public async Task <RegistrationConfirmationViewModel> Register([FromBody] CustomerRegistrationViewModel customerRegistrationInformation) { if (!ModelState.IsValid) { var errorList = (from item in ModelState.Values from error in item.Errors select error.ErrorMessage).ToList(); var response = new HttpResponseMessage(HttpStatusCode.BadRequest); response.ReasonPhrase = JsonConvert.SerializeObject(errorList); throw new HttpResponseException(response); } try { var user = await BusinessOperations.RegisterUser(customerRegistrationInformation.Customer); var newCustomer = await BusinessOperations.CreateCustomer(customerRegistrationInformation.Customer); user = await BusinessOperations.UpdateUser(user, newCustomer.CompanyProfile.TenantId); var order = await BusinessOperations.PlaceOrder(newCustomer.CompanyProfile.TenantId, customerRegistrationInformation.Orders); return(await BusinessOperations.GetRegistrationConfirmation(newCustomer, customerRegistrationInformation)); } catch (PartnerException partnerException) { HttpResponseMessage errorResponse = new HttpResponseMessage(); errorResponse.ReasonPhrase = partnerException.ServiceErrorPayload.ErrorMessage; switch (partnerException.ErrorCategory) { case PartnerErrorCategory.BadInput: errorResponse.StatusCode = HttpStatusCode.BadRequest; break; case PartnerErrorCategory.Unauthorized: errorResponse.StatusCode = HttpStatusCode.Unauthorized; break; default: errorResponse.StatusCode = HttpStatusCode.InternalServerError; break; } throw new HttpResponseException(errorResponse); } catch (InvalidOperationException userCreateProblem) { HttpResponseMessage errorResponse = new HttpResponseMessage(HttpStatusCode.InternalServerError); errorResponse.ReasonPhrase = userCreateProblem.Message; throw new HttpResponseException(errorResponse); } }