public async Task <string> Add([FromBody] IdentityServiceApiAddUserDto dto) { if (!ModelState.IsValid) { Response.StatusCode = StatusCodes.Status400BadRequest; return(string.Empty); } var user = new ApplicationUser { UserName = dto.Email, Email = dto.Email, EmailConfirmed = true, LockoutEnabled = false, }; var result = await _userManager.CreateAsync(user); var token = await _userManager.GeneratePasswordResetTokenAsync(user); await _userManager.ResetPasswordAsync(user, token, "Password123!"); if (!result.Succeeded) { Response.StatusCode = StatusCodes.Status400BadRequest; return(string.Empty); } Response.StatusCode = StatusCodes.Status201Created; return(user.Id); }
public async Task <SimpleUpsertDto> AddUserAsync([FromBody] AddUserDto dto) { var appUser = AddUserDto.GetAddUserFrom(dto); appUser = await _userRepository.AddAsync(appUser, this.AppUserId.Value); var identityDto = new IdentityServiceApiAddUserDto { Email = dto.Email }; var content = new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(identityDto)); content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse("application/json"); HttpResponseMessage response = await _httpClient.PostAsync("api/UserApi", content); response.EnsureSuccessStatusCode(); string identityId = await response.Content.ReadAsStringAsync(); appUser.IdentityId = identityId; appUser = await _userRepository.UpdateAsync(appUser, this.AppUserId.Value); return(SimpleUpsertDto.From(appUser)); }