public async Task <ActionResult <MessageResponse> > UpateUser([FromRoute] string username, [FromBody] ApplicationUserUpdateRequest request) { _logger.LogInformation($"Updating user {username} with body {request}"); return(await _userService.UpdateUser(username, request)); }
public async Task <ActionResult <MessageResponse> > UpdateUser(string username, ApplicationUserUpdateRequest user) { try { ApplicationUser registeredUser = _userRepository.GetUser(username); if (registeredUser == null) { return(new NotFoundObjectResult(new MessageResponse { Message = $"User {username} does not exist" })); } registeredUser = new ApplicationUser { Salary = user.Salary ?? registeredUser.Salary, ProfilePicture = _applicationService.StoreUploadedImage(user.ProfilePicture) ?? registeredUser.ProfilePicture, Address = user.Address ?? registeredUser.Address, Country = user.Country ?? registeredUser.Country, DateOfBirth = user.DateOfBirth ?? registeredUser.DateOfBirth, DisplayName = user.DisplayName ?? registeredUser.DisplayName }; await _userManager.UpdateAsync(registeredUser); return(new OkObjectResult(new MessageResponse { Message = $"User {username} has been updated successfully" })); } catch (Exception e) { _logger.LogError(e, e.Message); return(new BadRequestObjectResult(_applicationService.GetExceptionMessage(e))); } }