public async Task <ActionResult> Register([FromBody] RegisterViewModel userFromBody) { var user = new ApplicationUser { UserName = userFromBody.Username, Email = userFromBody.Email, SecurityStamp = Guid.NewGuid().ToString() }; var result = await _userManager.CreateAsync(user, userFromBody.Password); if (result.Succeeded) { _logger.LogInformation(LoggingEvents.CreateUser, "Create user {ID}", user.UserName); UserProfile profile = new UserProfile { ApplicationUser = user, Avatar = "https://getonboard.blob.core.windows.net/profile-pictures/default-user.png" }; _dbContext.UserProfiles.Add(profile); } else { string errorMessage = String.Empty; foreach (IdentityError error in result.Errors) { errorMessage += error.Description; } throw new RequestException(HttpStatusCode.BadRequest, errorMessage, LoggingEvents.CreateUser); } _dbContext.SaveChanges(); return(Ok(await Login(new LoginViewModel { Username = userFromBody.Username, Password = userFromBody.Password }))); }