public async Task <BaseResponse> UpdateUser(string userName, ApplicationUser applicationUser) { var user = await _userManager.FindByNameAsync(userName); if (user == null) { return(new ErrorResponse(new CustomApplicationException($"Could not find user with user name {userName}"))); } user.FirstName = applicationUser.FirstName; user.LastName = applicationUser.LastName; user.PhoneNumber = applicationUser.PhoneNumber; var result = await _userManager.UpdateAsync(user); if (result.Succeeded) { var mappedUser = LocalMapper.Map <ApplicationUser>(user); return(new SuccessResponse <ApplicationUser>(mappedUser)); } var errors = result.Errors.Select(e => new CustomApplicationException(e.Description)).ToArray(); return(new ErrorResponse(new CustomAggregatedException("Errors occurred during user update.", errors))); }
public async Task <BaseResponse> RegisterNewUser(ApplicationUser applicationUser, Uri tokenCallback) { var mappedApplicationUser = LocalMapper.Map <Entities.ApplicationUser>(applicationUser); var createdUser = await _userManager.CreateAsync(mappedApplicationUser, applicationUser.Password); if (createdUser == null) { return(new ErrorResponse(new ApplicationException("Created user is null!"))); } if (createdUser.Succeeded) { var token = await _userManager.GenerateEmailConfirmationTokenAsync(mappedApplicationUser); await SendEmailConfirmation(applicationUser.Email, $"{applicationUser.FirstName} {applicationUser.LastName}", tokenCallback, applicationUser.UserName, token); return(new SuccessResponse <ApplicationUser>(applicationUser)); } var exceptions = createdUser.Errors.Select(e => new CustomApplicationException(e.Description)); return(new ErrorResponse(new CustomAggregatedException("Exceptions occurred during creating new user.", exceptions.ToArray()))); }