public Task <GetUserResponseDto> UpdateUser(UpdateUserRequestDto userRequest, string userName, string authToken = null) { if (userRequest == null || string.IsNullOrEmpty(userName)) { throw new ArgumentException("The userName can not be null"); } return(PutCyberArk <GetUserResponseDto>($"{CyberArkEndpointConst.Users}/{userName}", userRequest, false, authToken)); }
public async Task <ResponseDto> Update([FromBody] UpdateUserRequestDto request) { if (!ModelState.IsValid) { return(new ResponseDto(ResponseCode.Validate, "Đầu vào không hợp lệ")); } var result = await _userService.Update(request); return(result); }
public async Task <ResponseDto> Update(UpdateUserRequestDto request) { var user = await _userManager.FindByIdAsync(request.Id.ToString()); if (user == null) { return(new ResponseDto(ResponseCode.NotFound, "User không tồn tại")); } if (await _userManager.Users.AnyAsync(x => x.Email == request.Email && x.Id != request.Id)) { return(new ResponseDto(ResponseCode.Validate, "Emai đã tồn tại")); } user.FullName = request.FullName; user.PhoneNumber = request.PhoneNumber; user.TypeAccount = (TypeAccount)request.TypeAccount; user.Status = (Status)request.Status; user.Dob = request.Dob; user.Email = request.Email; var result = await _userManager.UpdateAsync(user); if (result.Succeeded) { foreach (var item in request.RemovedRoles) { if (await _userManager.IsInRoleAsync(user, item) == true) { var kq = await _userManager.RemoveFromRoleAsync(user, item); if (!kq.Succeeded) { return(new ResponseDto(ResponseCode.LogicError, "Cập nhật thất bại do thêm role thất bại")); } } } foreach (var roleName in request.AddedRoles) { if (await _userManager.IsInRoleAsync(user, roleName) == false) { var kq = await _userManager.AddToRoleAsync(user, roleName); if (!kq.Succeeded) { return(new ResponseDto(ResponseCode.LogicError, "Cập nhật thất bại do thêm role thất bại")); } } } } else { return(new ResponseDto(ResponseCode.LogicError, "Cập nhật người dùng thất bại")); } return(new ResponseDto(ResponseCode.Success, "Cập nhật người dùng thành công")); }
public async Task <IActionResult> Update([FromBody] UpdateUserRequestDto model) { try { await _userService.Update(model); return(Ok()); } catch (Exception ex) { return(BadRequest(new { error = _localizer[ex.Message].Value })); } }
public async Task Update(UpdateUserRequestDto userDto) { var user = await _unitOfWork.Users.GetUserByUsernameAsync(userDto.Username); if (user == null) { throw new ArgumentException("UserNotFound"); } if (!string.IsNullOrWhiteSpace(userDto.Password)) { CreatePasswordHash(userDto.Password, out byte[] passwordHash, out byte[] passwordSalt); user.PasswordHash = passwordHash; user.PasswordSalt = passwordSalt; } _unitOfWork.Users.Update(user); await _unitOfWork.CommitAsync(); }
public async Task <IHttpActionResult> PutUser(UpdateUserRequestDto request) { ApplicationUser currentUser = CurrentUser; currentUser.FirstName = request.FirstName; currentUser.LastName = request.LastName; currentUser.ProfilePictureUri = request.ProfileImageUri; //TODO: save request.ProfileImage to blob storage IdentityResult result = await AppUserManager.UpdateAsync(currentUser); if (!result.Succeeded) { //TODO: Translate errors returned to client return(GetErrorResult(result)); } Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = CurrentUserId })); return(Created(locationHeader, TheModelFactory.Create(currentUser))); }
public async Task <IActionResult> UpdateUserAsync([FromRoute] Guid id, [FromBody] UpdateUserRequestDto dto) { var currentUser = await GetCurrentUserAsync(); Logger.LogInformation($"{nameof(UpdateUserAsync)}, currentUser:{currentUser.ToJson()}, dto:{dto.ToJson()}"); var user = await _userManager.FindByIdAsync(id); ValidateUserExists(user, id); var role = await _roleManager.FindByIdAsync(dto.RoleId); ValidateRoleExists(role, dto, currentUser); user.Update( dto.Firstname, dto.Lastname ); user.SetRole(role); //TODO To validate user = await _userManager.UpdateAsync(user); return(new ObjectResult(Mapper.Map <User, UserDto>(user))); }
public async Task <IActionResult> UpdateUser(UpdateUserRequestDto userRequest, string userName, string authToken = null) { Devon4NetLogger.Debug("Executing Login from controller CyberArk"); return(Ok(await CyberArkHandler.UpdateUser(userRequest, userName, authToken))); }