public async Task UpdatePermissions(int userId, IEnumerable <int> permissions) { var user = await userRepository.GetAsync(userId); if (user == null) { throw new Exception("user doesn't exist"); } var permissionsInfo = await permissionRepository.GetAllAsync(); var tasks = new List <Task>(); foreach (var permission in permissionsInfo) { tasks.Add(userPermissionRepository.RemoveAsync(permission.Id, userId)); } await Task.WhenAll(tasks); tasks.Clear(); foreach (var permission in permissions) { UserPermission up = new UserPermission(permission, userId); tasks.Add(userPermissionRepository.AddAsync(up)); } await Task.WhenAll(tasks); }
public async Task <ActionResponse> RemovePermissions(List <Permission> permissions) { return(await _repository.RemoveAsync(permissions)); }