public async Task <RequestResult <ProjectModel> > UdpateProjectAsync(UpdateProjectDto projectDto, List <SimpleUserModel> oldMembersCollection, List <SimpleUserModel> newMembersCollection) { var projectUpdateTask = _webClient.ExecuteRequestAsync(webApi => webApi.UpdateProject(projectDto)); var addedMembersIds = newMembersCollection.Except(oldMembersCollection, _modelsByIdComparer).Select(u => u.Id).ToList(); var removedMembersIds = oldMembersCollection.Except(newMembersCollection, _modelsByIdComparer).Select(u => u.Id).ToList(); var tasks = new List <Task>(); tasks.Add(projectUpdateTask); foreach (var addedMemberId in addedMembersIds) { var addDto = new CreateUpdateProjectMemberDto { UserId = addedMemberId, ProjectId = projectDto.Id, Role = (int)ProjectMemberRole.Implementer }; string requestId = RequestIdProvider.GetRequestId(); var addMemberTask = _webClient.ExecuteRequestAsync(webApi => webApi.AddMemberToProject(requestId, addDto)); tasks.Add(addMemberTask); } foreach (var removingMemberId in removedMembersIds) { var removeDto = new DeleteProjectMemberDto { UserId = removingMemberId, ProjectId = projectDto.Id }; string requestId = RequestIdProvider.GetRequestId(); var removeMemberTask = _webClient.ExecuteRequestAsync(webApi => webApi.RemoveMemberFromProject(removeDto)); tasks.Add(removeMemberTask); } await Task.WhenAll(tasks); foreach (var task in tasks) { task.ThrowIfFaulted(); } return(projectUpdateTask.Result); }
public Task <RequestResult <ListModel> > CreateListAsync(CreateListDto dto) { string requestId = RequestIdProvider.GetRequestId(); return(_webApiClient.ExecuteRequestAsync(webApi => webApi.CreateList(requestId, dto))); }