public async Task UpdateAsync(long id, UpdateGroupDto updateGroupDto) { await _freeSql.Update <LinGroup>(id).Set(a => new LinGroup() { Info = updateGroupDto.Info, Name = updateGroupDto.Name }).ExecuteAffrowsAsync(); }
public async Task UpdateAsync(long id, UpdateGroupDto updateGroupDto) { await _groupRepository.UpdateDiy.Where(r => r.Id == id).Set(a => new LinGroup() { Info = updateGroupDto.Info, Name = updateGroupDto.Name }).ExecuteAffrowsAsync(); }
public ResultDto Put(int id, [FromBody] UpdateGroupDto updateGroupDto) { _freeSql.Update <LinGroup>(id).Set(a => new LinGroup() { Info = updateGroupDto.Info, Name = updateGroupDto.Name }).ExecuteAffrows(); return(ResultDto.Success("更新分组成功")); }
public async Task <IActionResult> Update(Guid id, [FromBody] UpdateGroupDto updateGroupDto) { updateGroupDto.Id = id; var result = await _unitOfWork.GroupService.Update(updateGroupDto); if (!result.Success) { return(result.ApiResult); } return(NoContent()); }
public void IMapper() { CreateGroupDto inputDto = new CreateGroupDto() { Info = "11", Name = "11" }; UpdateGroupDto update = new UpdateGroupDto() { Info = "11", Name = "11" }; LinGroup d = _mapper.Map <LinGroup>(inputDto); LinGroup d2 = _mapper.Map <LinGroup>(update); }
public void IMapper() { CreateGroupDto inputDto = new CreateGroupDto() { Auths = new List <string>() { "查询日志记录的用户" }, Info = "11", Name = "11" }; UpdateGroupDto update = new UpdateGroupDto() { Info = "11", Name = "11" }; LinGroup d = _mapper.Map <LinGroup>(inputDto); LinGroup d2 = _mapper.Map <LinGroup>(update); }
public async Task <ActionResult <GroupDto> > Update([FromBody] UpdateGroupDto updateGroupDto) { try { var result = await _groupService.Update(updateGroupDto); if (result.Sucess) { return(Ok(result.Data)); } if (result.NotFound) { return(NotFound()); } return(Conflict(result)); } catch (Exception ex) { _logging.WriteExption(ex); return(BadRequest()); } }
public async Task <IActionResult> UpdateGroup(int id, [FromBody] UpdateGroupDto groupDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var group = await _groupRepository.GetGroup(id); if (group == null) { return(NotFound()); } _mapper.Map(groupDto, group); await _unitOfWork.CompleteAsync(); group = await _groupRepository.GetGroup(group.Id); var result = _mapper.Map <Group, UpdateGroupDto>(group); return(Ok(result)); }
public async Task <UnifyResponseDto> UpdateAsync(long id, [FromBody] UpdateGroupDto updateGroupDto) { await _groupService.UpdateAsync(id, updateGroupDto); return(UnifyResponseDto.Success("更新分组成功")); }
public async Task <Result> Update(UpdateGroupDto updateGroupDto) { var group = await FirstOrDefaultAsync(c => c.Id == updateGroupDto.Id, g => g.UserInGroups, g => g.User); if (group.User.Id != updateGroupDto.OwnerId) { var user = await Context.Users.FirstOrDefaultAsync(u => u.Id == updateGroupDto.OwnerId); if (user == null) { return(Result.Failed(new NotFoundObjectResult( new ApiMessage { Message = ResponseMessage.UserNotFound }))); } group.User = user; } _mapper.Map(updateGroupDto, group); if (group.UserInGroups != null && group.UserInGroups.Any() && !group.UserInGroups.Select(g => g.UserId).SequenceEqual(updateGroupDto.UsersInGroups)) { // get all users that are removed var removedUsers = group.UserInGroups .Where(user => !updateGroupDto.UsersInGroups.Contains(user.UserId)).ToList(); if (removedUsers.Any()) { Context.UserInGroups.RemoveRange(removedUsers); } // get all users id that are added var addedUsersId = updateGroupDto.UsersInGroups.Where(userId => !group.UserInGroups.Select(u => u.UserId).Contains(userId)).ToList(); var addedUsers = await Context.Users.Where(u => addedUsersId.Contains(u.Id)).ToListAsync(); // if invalid user id sent if (addedUsers.Count != addedUsersId.Count) { return(Result.Failed(new BadRequestObjectResult(new ApiMessage { Message = ResponseMessage.UserNotFound }))); } var addedUserInGroups = addedUsers.Select(user => new UserInGroup { Id = Guid.NewGuid(), Groups = group, JoinGroupDate = DateTime.Now, User = user }) .ToList(); if (addedUserInGroups.Any()) { await Context.UserInGroups.AddRangeAsync(addedUserInGroups); } group.UserInGroups = addedUserInGroups.Union(group.UserInGroups.Where(ur => !addedUsersId.Contains(ur.UserId) && !removedUsers.Select(rr => rr.UserId).Contains(ur.UserId))) .ToList(); } group.Members = group.UserInGroups != null && group.UserInGroups.Any() ? group.UserInGroups.Count + 1 : 1; await Context.SaveChangesAsync(); return(Result.SuccessFull()); }
public async Task <IActionResult> Update([FromRoute] int id, [FromBody] UpdateGroupDto updateGroupDto) { return(GetResponseOnlyResultMessage(await Mediator.Send(new UpdateGroupCommand { Id = id, GroupName = updateGroupDto.GroupName }))); }