public async Task <string> Register([FromBody] CustomerViewModel customerViewModel) { if (!ModelState.IsValid) { List <string> errorList = (from item in ModelState.Values from error in item.Errors select error.ErrorMessage).ToList(); string errorMessage = JsonConvert.SerializeObject(errorList); throw new PartnerDomainException(ErrorCode.InvalidInput).AddDetail("ErrorMessage", errorMessage); } // TODO :: Loc. may need special handling for national clouds deployments (China). string domainName = string.Format(CultureInfo.InvariantCulture, "{0}.onmicrosoft.com", customerViewModel.DomainPrefix); // check domain available. bool isDomainTaken = await ApplicationDomain.Instance.PartnerCenterClient.Domains.ByDomain(domainName).ExistsAsync().ConfigureAwait(false); if (isDomainTaken) { throw new PartnerDomainException(ErrorCode.DomainNotAvailable).AddDetail("DomainPrefix", domainName); } // get the locale, we default to the first locale used in a country for now. PartnerCenter.Models.CountryValidationRules.CountryValidationRules customerCountryValidationRules = await ApplicationDomain.Instance.PartnerCenterClient.CountryValidationRules.ByCountry(customerViewModel.Country).GetAsync().ConfigureAwait(false); string billingCulture = customerCountryValidationRules.SupportedCulturesList.FirstOrDefault(); // default billing culture is the first supported culture for the customer's selected country. string billingLanguage = customerCountryValidationRules.SupportedLanguagesList.FirstOrDefault(); // default billing culture is the first supported language for the customer's selected country. CustomerViewModel customerRegistrationInfoToPersist = new CustomerViewModel() { AddressLine1 = customerViewModel.AddressLine1, AddressLine2 = customerViewModel.AddressLine2, City = customerViewModel.City, State = customerViewModel.State, ZipCode = customerViewModel.ZipCode, Country = customerViewModel.Country, Phone = customerViewModel.Phone, Language = customerViewModel.Language, FirstName = customerViewModel.FirstName, LastName = customerViewModel.LastName, Email = customerViewModel.Email, CompanyName = customerViewModel.CompanyName, MicrosoftId = Guid.NewGuid().ToString(), UserName = customerViewModel.Email, BillingLanguage = billingLanguage, BillingCulture = billingCulture, DomainName = domainName, DomainPrefix = customerViewModel.DomainPrefix }; CustomerRegistrationRepository customerRegistrationRepository = new CustomerRegistrationRepository(ApplicationDomain.Instance); CustomerViewModel customerRegistrationInfo = await customerRegistrationRepository.AddAsync(customerRegistrationInfoToPersist).ConfigureAwait(false); return(customerRegistrationInfo.MicrosoftId); }
public async Task <PartialViewResult> Create() { IAggregatePartner operations = await new SdkContext().GetPartnerOperationsAysnc(); PartnerCenter.Models.CountryValidationRules.CountryValidationRules rules = await operations.CountryValidationRules.ByCountry(AppConfig.CountryCode).GetAsync(); // TODO - Do not get the supported states list each time. This data should be cached so the forms will load more rapidly. NewCustomerModel newCustomerModel = new NewCustomerModel() { SupportedStates = rules.SupportedStatesList }; return(PartialView(newCustomerModel)); }