public async Task <OperationResponse> UpdateAsync(UserUpdateInputDto input) { input.NotNull(nameof(input)); var user = await _userManager.FindByIdAsync(input.Id.ToString()); user = input.MapTo(user); return((await _userManager.UpdateAsync(user)).ToOperationResponse()); //return result; //return await _unitOfWork.UseTranAsync(async () => //{ // if (!result.Succeeded) // return result.ToOperationResponse(); // await _userRoleRepository.DeleteBatchAsync(x => x.UserId == input.Id); // if (input.RoleIds?.Any() == true) // { // await _userRoleRepository.InsertAsync(input.RoleIds.Select(x => new UserRoleEntity // { // RoleId = x, // UserId = user.Id, // }).ToArray()); // } // return new OperationResponse(ResultMessage.UpdateSuccess, OperationEnumType.Success); //}); }
public async Task <IActionResult> UpdateUserMobile([FromBody] UserUpdateInputDto input) { if (!string.IsNullOrEmpty(input.Id) && !string.IsNullOrEmpty(input.Mobile)) { var(user, appService) = _userAppServiceClient.FindByUserIdAsync(input.Id).Result; if (user != null) { if (user.Mobile == input.Mobile) { return(Json(false, null, "新手机号码不能和原手机号码相同")); } if (await _userAppServiceClient.IsMobileExistedAsync(input.Mobile)) { return(Json(false, null, "手机号码已经存在")); } if (await appService.UpdateUserAsync(user.Id, new UserItemDto { Mobile = input.Mobile }) != null) { user.Mobile = input.Mobile; return(Json(true, user, "操作成功")); } } } return(Json(false, null, "未找到相关的用户信息")); }
public async Task <OperationResponse> UpdateAsync(UserUpdateInputDto dto) { dto.NotNull(nameof(dto)); var user = await _userManager.FindByIdAsync(dto.Id.ToString()); user = dto.MapTo(user); return(await _unitOfWork.UseTranAsync(async() => { var result = await _userManager.UpdateAsync(user); if (!result.Succeeded) { return result.ToOperationResponse(); } if (dto.RoleIds.Any() == true) { return await this.SetUserRoles(user, dto.RoleIds); } else { return await this.DeleteUserRoleAsync(user); } })); }
public async Task <IActionResult> UpdateUserPassword([FromBody] UserUpdateInputDto input) { if (!string.IsNullOrEmpty(input.Id) && !string.IsNullOrEmpty(input.RePassword) && !string.IsNullOrEmpty(input.Password) && input.Password == input.RePassword) { var(user, appService) = _userAppServiceClient.FindByUserIdAsync(input.Id).Result; if (user != null) { if (await appService.UpdateUserAsync(user.Id, new UserItemDto { Password = input.Password }) != null) { return(new JsonResult(new AjaxResult() { Success = true, Message = "操作成功" })); } return(new JsonResult(new AjaxResult() { Success = false, Message = "操作失败" })); } } return(new JsonResult(new AjaxResult() { Success = false, Message = "操作失败:未找到用户|密码不一致|密码不能为空" })); }
/// <summary> /// 修改用户 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <StatusResult> UpdateAsync(UserUpdateInputDto input) { var user = await _userRepository.Select.Where(o => o.Id == input.Id).FirstAsync(); if (user == null) { return(new StatusResult("用户不存在!")); } var thisUser = new UserEntity() { Id = input.Id }; _userRepository.Attach(thisUser); thisUser.Avatar = input.Avatar; thisUser.NickName = input.NickName; thisUser.Phone = input.Phone; thisUser.RealName = input.RealName; int res = await _userRepository.UpdateAsync(thisUser); await _userRoleRepository.DeleteAsync(o => o.UserId == user.Id); var userRoles = input.RoleIds.Select(o => new UserRoleEntity() { RoleId = o.key, UserId = user.Id, Id = Snowflake.GenId() }); await _userRoleRepository.InsertAsync(userRoles); return(new StatusResult(res == 0, "修改失败")); }
public async Task <OperationResponse> UpdateAsync(UserUpdateInputDto dto) { dto.NotNull(nameof(dto)); var user = await _userManager.FindByIdAsync(dto.Id.ToString()); user = dto.MapTo(user); var result = await _userManager.UpdateAsync(user); return(result.ToOperationResponse("保存用户成功")); }
public async Task Update(UserUpdateInputDto inputDto) { var user = await _userManager.GetById(inputDto.Id); if (user == null) { throw new APIException("用户信息不存在。"); } inputDto.MapTo(user); await _userManager.Update(user); }
public async Task UpdateUser(UserUpdateInputDto request) { var userVerified = _repository.GetUserWithDetail(request.Id); if (userVerified != null) { //userVerified.UserProfile.BirthDate = request.BirthDate; //userVerified.UserProfile.FirstName = request.FirstName; //userVerified.UserProfile.LastName = request.LastName; //userVerified.UserProfile.MobilePhone = request.MobilePhone; await _userManager.UpdateAsync(userVerified); } else { throw new Exception("User is not existing in our records."); } }
public async Task <IActionResult> UpdateUserState([FromBody] UserUpdateInputDto input) { if (!string.IsNullOrEmpty(input.Id)) { var(user, appService) = await _userAppServiceClient.FindByUserIdAsync(input.Id); if (user != null) { if (await appService.UpdateUserAsync(user.Id, new UserItemDto { IsActive = !user.IsActive }) != null) { return(Json(true, null, "修改成功")); } } } return(Json(false, null, "未找到当前用户")); }
public async Task <AjaxResult> UpdateAsync([FromBody] UserUpdateInputDto input) { return((await _userContract.UpdateAsync(input)).ToAjaxResult()); }
public async Task <AjaxResult> UpdateAsync([FromBody] UserUpdateInputDto dto) { return((await _userService.UpdateAsync(dto)).ToAjaxResult()); }
public async Task <HttpResponse <int> > Update(UserUpdateInputDto inputDto) { await _userAppService.Update(inputDto); return(Success(0)); }
public async Task <StatusResult> Update(UserUpdateInputDto input) { return(await _userService.UpdateAsync(input)); }