public async Task <IActionResult> CreateWebProfile([FromBody] WebProfile webProfile) { IActionResult result; try { _logger.LogInformation($"CreateWebProfile({nameof(webProfile)}: {webProfile.ToJson()})"); if (webProfile == null) { return(BadRequest("No profile provided")); } var validBp = long.TryParse(webProfile.BPId, out var bpId); // Validate password,username, phone, email ValidateCreateProfile(webProfile, validBp); // Make sure the account provider exists var customermodel = _customerLogic.LookupCustomer(webProfile.Customer); // Check if username exists var usernameCheck = _customerLogic.UserNameExists(webProfile.CustomerCredentials.UserName); await Task.WhenAll(customermodel, usernameCheck); var lookupCustomerModel = customermodel.Result; var userExist = usernameCheck.Result; if (userExist) { //409 - conflict for user name exist return(new BadRequestObjectResult(new ServiceError { Code = (int)HttpStatusCode.Conflict, Message = $"The username {webProfile.CustomerCredentials.UserName} exists" })); } if (lookupCustomerModel == null) { return(new BadRequestObjectResult(new ServiceError { Code = (int)HttpStatusCode.BadRequest, Message = "The Customer was not found" })); } //make sure the Bp provided and the account match if (bpId != lookupCustomerModel.BPId) { return(new BadRequestObjectResult(new ServiceError { Code = (int)HttpStatusCode.BadRequest, Message = "The Contract account provided didn't match the Business Partner" })); } //Create profile and save security questions await _customerLogic.CreateWebProfileAsync(webProfile); //Updates Email and Phone after signup var jwt = await _customerLogic.GetJWTTokenAsync(webProfile.CustomerCredentials.UserName, webProfile.CustomerCredentials.Password); if (!string.IsNullOrEmpty(jwt)) { await _customerLogic.PutEmailAddressAsync(jwt, webProfile.Email, bpId); await _customerLogic.PutPhoneNumberAsync(jwt, webProfile.Phone, bpId); } result = new OkResult(); } catch (Exception e) { _logger.LogError(e, e.Message); result = e.ToActionResult(); } return(result); }