public PermissionType GetFolderPermission(Guid folderId, Guid userId) { FolderPermissionModel fpm = _unitOfWork.FolderPermissionRepository .Find(p => p.User.Id == userId && p.Folder.Id == folderId) .FirstOrDefault(); return(fpm == null ? PermissionType.None : fpm.Value); }
public void SetFolderPermission(Guid folderId, Guid ownerId, Guid userId, PermissionType permission) { FolderModel folderModel = _unitOfWork.FolderRepository.Get(folderId); if (folderModel == null) { throw new Exception(); } if (folderModel.OwnerId != ownerId) { throw new Exception(); } UserModel userModel = _unitOfWork.UserRepository.Get(userId); if (userModel == null) { throw new Exception(); } if (folderModel.OwnerId == userId) { throw new Exception(); } FolderPermissionModel fpm = _unitOfWork.FolderPermissionRepository .Find(p => p.UserId == userId && p.FolderId == folderId) .FirstOrDefault(); //Create if (permission != PermissionType.None && fpm == null) { fpm = new FolderPermissionModel() { User = userModel, Folder = folderModel, Value = permission }; _unitOfWork.FolderPermissionRepository.Create(fpm); } //Update else if (permission != PermissionType.None && fpm != null) { fpm.Value = permission; _unitOfWork.FolderPermissionRepository.Update(fpm); } //Delete else if (permission == PermissionType.None && fpm != null) { _unitOfWork.FolderPermissionRepository.Delete(fpm.Id); } _unitOfWork.Save(); }