public PermissionResult Remove(List <int> permissions, int userId, UserSessionObject currentUser) { bool flag = true; var wrongIds = new List <int>(); var result = new PermissionResult(); List <int> alreadyAssigned = RelationUserPermissionRepository .GetRelationUserPermissionFor(userId) .Select(x => x.PermissionId) .ToList(); foreach (int permissionId in permissions) { if (!alreadyAssigned.Contains(permissionId)) { flag = false; wrongIds.Add(permissionId); } else { var data = RelationUserPermissionRepository.GetRelationUserPermissionFor(userId, permissionId); RelationUserPermissionRepository.DeleteById(data.Id, currentUser.UserId); } } if (!flag) { result = new PermissionResult(false, PermissionResult.OperationType.Remove, wrongIds); } else { result = new PermissionResult(true, PermissionResult.OperationType.Remove); } return(result); }