public async Task <ActionResult <object> > ChangeUserDetails(ChangeUserDetailsDto changeUserDetailsDto) { // Sends new token with updated username var token = await _identityService.ChangeUserDetails(changeUserDetailsDto); return(Ok(new { token })); }
public async Task <string> ChangeUserDetails(ChangeUserDetailsDto userDetails) { var user = await GetCurrentUser(_currentUser.UserId); if (userDetails.Username != user.UserName) { var usernameResult = await _userManager.SetUserNameAsync(user, userDetails.Username); if (!usernameResult.Succeeded) { throw new BadRequestException("Unexpected error changing username"); } } var customer = await _unitOfWork.Customers.GetFirstAsync(c => c.UserId == user.Id); user.Customer = customer; user.Customer.FirstName = userDetails.FirstName; user.Customer.FamilyName = userDetails.FamilyName; user.Customer.Street = userDetails.Street; user.Customer.HouseNr = userDetails.HouseNr; user.Customer.HouseBus = userDetails.HouseBus; user.Customer.PostalCode = userDetails.PostalCode; user.Customer.City = userDetails.City; user.Customer.StreetBilling = userDetails.StreetBilling; user.Customer.HouseNrBilling = userDetails.HouseNrBilling; user.Customer.HouseBusBilling = userDetails.HouseBusBilling; user.Customer.PostalCodeBilling = userDetails.PostalCodeBilling; user.Customer.CityBilling = userDetails.CityBilling; var result = await _userManager.UpdateAsync(user); if (!result.Succeeded) { throw new BadRequestException("Unexpected error changing user details"); } return(await LoginAndGetToken(userDetails.Username)); }