public async Task <AccountResponse> UpdateAsync(TKey id, UpdateRequest model) { var account = await jwtUserService.GetAsync(id); var accountMail = await jwtUserService.GetByEmailAsync(model.Email); // validate if (account.Email != model.Email && accountMail != null) { throw new JwtAppException($"Email '{model.Email}' is already taken"); } // hash password if it was entered if (!string.IsNullOrEmpty(model.Password)) { account.PasswordHash = passwordService.HashPassword(model.Password); } // copy model to account and save var updatedUser = convertService.UpdateRequestToUser(model); account.Updated = DateTime.UtcNow; await jwtUserService.UpdateAsync(account.Id, updatedUser); AccountResponse accountResponse = convertService.UserToAccountResponse(account); return(accountResponse); }