BlazorStart/Start/Server/Data/Services/BookmarkOwnershipTools.cs

36 lines
1.1 KiB
C#
Raw Permalink Normal View History

2021-11-14 01:19:28 +00:00
using System;
using System.Linq;
namespace Start.Server.Data.Services {
public static class BookmarkOwnershipTools {
public static bool IsBookmarkOwner(ApplicationDbContext db, string userId, int bookmarkId) {
string? bookmarkOwnerId = db.Bookmarks
.Where(b => b.BookmarkId == bookmarkId)
.Select(b => b.BookmarkGroup!.BookmarkContainer!.ApplicationUserId)
.SingleOrDefault();
return userId == bookmarkOwnerId;
}
public static bool IsBookmarkGroupOwner(ApplicationDbContext db, string userId,
int bookmarkGroupId) {
string? groupOwnerId = db.BookmarkGroups
.Where(bg => bg.BookmarkGroupId == bookmarkGroupId)
.Select(bg => bg.BookmarkContainer!.ApplicationUserId)
.SingleOrDefault();
return userId == groupOwnerId;
}
public static bool IsBookmarkContainerOwner(ApplicationDbContext db, string userId,
int bookmarkContainerId) {
string? containerOwnerId = db.BookmarkContainers
.Where(bc => bc.BookmarkContainerId == bookmarkContainerId)
.Select(bc => bc.ApplicationUserId)
.SingleOrDefault();
return userId == containerOwnerId;
}
}
}