protected virtual async Task CreateProjectAuditGroupAsync(CreateOrUpdateProjectAuditGroupInput input) { var projectAuditGroup = new ProjectAuditGroup() { Name = input.Name, Description = input.Description //Sort_id = input.Sort_id }; var groupId = await _projectAuditGroupRepository.InsertAndGetIdAsync(projectAuditGroup); input.Users.ForEach(r => { var entity = new ProjectAuditGroupUser(); entity.Id = Guid.NewGuid(); entity.GroupId = groupId; entity.UserId = r.UserId; entity.UserRole = r.UserRole; _projectAuditGroupUserRepository.InsertAsync(entity); }); var adduserid = input.Users.First(x => x.UserRole == 1).UserId; await UpdateRole(adduserid, 1, groupId); await CurrentUnitOfWork.SaveChangesAsync(); //It's done to get Id of the edition. }
protected virtual async Task UpdateProjectAuditGroupAsync(CreateOrUpdateProjectAuditGroupInput input) { Debug.Assert(input.Id != null, "input Id should be set."); var projectAuditGroup = await _projectAuditGroupRepository.GetAsync(input.Id.Value); projectAuditGroup.Name = input.Name; projectAuditGroup.Description = input.Description; var list = await _projectAuditGroupUserRepository.GetAll().Where(r => r.GroupId == input.Id.Value).ToListAsync(); var userid = list.First(x => x.UserRole == 1).UserId; var adduserid = input.Users.First(x => x.UserRole == 1).UserId; list.ForEach(r => _projectAuditGroupUserRepository.DeleteAsync(r)); input.Users.ForEach(r => { var entity = new ProjectAuditGroupUser(); entity.Id = Guid.NewGuid(); entity.GroupId = input.Id.Value; entity.UserId = r.UserId; entity.UserRole = r.UserRole; _projectAuditGroupUserRepository.InsertAsync(entity); }); await _projectAuditGroupRepository.UpdateAsync(projectAuditGroup); if (userid != adduserid) { await UpdateRole(userid, 0, input.Id.Value); await UpdateRole(adduserid, 1, input.Id.Value); } }
protected virtual async Task <Guid> CreateProjectAuditGroup(CreateOrUpdateProjectAuditGroupInput input) { var projectAuditGroup = new ProjectAuditGroup() { Name = input.Name, Description = input.Description, }; var retid = await _projectAuditGroupRepository.InsertAndGetIdAsync(projectAuditGroup); input.Users.ForEach(r => { var entity = new ProjectAuditGroupUser(); entity.Id = Guid.NewGuid(); entity.GroupId = retid; entity.UserId = r.UserId; entity.UserRole = r.UserRole; _projectAuditGroupUserRepository.InsertAsync(entity); }); await CurrentUnitOfWork.SaveChangesAsync(); return(retid); }