public bool DeleteUserPermission(Guid id) { bool isSuccess = true; try { UserPermission userPermission = GetUserPermission(id); userPermissionRepository.Delete(userPermission); SaveRecord(); ServiceUtil <UserPermission> .WriteActionLog(id, ENUMOperation.DELETE); } catch (Exception ex) { isSuccess = false; logger.Error("Error in deleting UserPermission", ex); } return(isSuccess); }
/// <summary> /// Delete all user permissions applied to a single entity /// </summary> /// <param name="userId">User identifier</param> /// <returns>Return user permissions list</returns> public Task <IList <ValidationResult> > DeletePermissionsOnEntity(IList <string> permissions, string entityId) { //Validazione argomenti if (string.IsNullOrEmpty(entityId)) { throw new ArgumentNullException(nameof(entityId)); } IList <ValidationResult> validations = new List <ValidationResult>(); var permissionIds = _permissionRepository.FetchWithProjection(x => x.Id, x => permissions.Contains(x.Name)); //retrieve elements var userPermissions = _userPermissionRepository.Fetch(x => x.EntityId == entityId && permissionIds.Contains(x.PermissionId)); foreach (var entityPermission in userPermissions) { _userPermissionRepository.Delete(entityPermission); } // get role permission on entity var rolePermissions = _userRoleRepository.Fetch(x => x.EntityId == entityId); var roleIds = rolePermissions.Select(x => x.RoleId); var rolePermission = _permissionRoleRepository .FetchWithProjection(x => x.RoleId, // filter by permissions x => roleIds.Contains(x.RoleId) && permissionIds.Contains(x.PermissionId)); // delete every role with entityId and the role which contains the required permission foreach (var userRole in rolePermissions.Where(x => rolePermission.Contains(x.RoleId))) { _userRoleRepository.Delete(userRole); } //Recupero i dati, commit ed uscita return(Task.FromResult(validations)); }
public bool DeleteAllByUserId(string userId) { return(userPermissionRepository.Delete(x => x.UserID == userId)); }