コード例 #1
0
        /// <summary>
        /// Executes the operations associated with the cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            Scheduler.RunTask(async() =>
            {
                if (ShouldProcess(string.Format(CultureInfo.CurrentCulture, Resources.NewPartnerCustomerWhatIf, Name)))
                {
                    IPartner partner = await PartnerSession.Instance.ClientFactory.CreatePartnerOperationsAsync(CorrelationId, CancellationToken).ConfigureAwait(false);

                    PartnerCenter.Models.Customers.Customer customer;
                    string country = (string.IsNullOrEmpty(BillingAddressCountry)) ? PartnerSession.Instance.Context.CountryCode : BillingAddressCountry;
                    string culture = (string.IsNullOrEmpty(Culture)) ? PartnerSession.Instance.Context.Locale : Culture;
                    string region;

                    if (string.IsNullOrEmpty(BillingAddressRegion))
                    {
                        region = null;
                    }
                    else
                    {
                        region = BillingAddressRegion.Equals(UnitedStatesCountryCode, StringComparison.InvariantCultureIgnoreCase) ? string.Empty : BillingAddressRegion;
                    }

                    customer = new PartnerCenter.Models.Customers.Customer
                    {
                        AssociatedPartnerId = AssociatedPartnerId,
                        BillingProfile      = new PartnerCenter.Models.Customers.CustomerBillingProfile
                        {
                            CompanyName    = Name,
                            Culture        = culture,
                            DefaultAddress = new Address
                            {
                                AddressLine1 = BillingAddressLine1,
                                AddressLine2 = BillingAddressLine2,
                                City         = BillingAddressCity,
                                Country      = country,
                                FirstName    = ContactFirstName,
                                LastName     = ContactLastName,
                                PhoneNumber  = ContactPhoneNumber,
                                PostalCode   = BillingAddressPostalCode,
                                Region       = region,
                                State        = BillingAddressState
                            },
                            Email     = ContactEmail,
                            FirstName = ContactFirstName,
                            Language  = Language,
                            LastName  = ContactLastName
                        },
                        CompanyProfile = new PartnerCenter.Models.Customers.CustomerCompanyProfile
                        {
                            CompanyName = Name,
                            Domain      = Domain
                        }
                    };

                    if (!DisableValidation.ToBool())
                    {
                        if (await partner.Domains.ByDomain(Domain).ExistsAsync(CancellationToken).ConfigureAwait(false))
                        {
                            throw new PSInvalidOperationException(
                                string.Format(
                                    CultureInfo.CurrentCulture,
                                    Resources.DomainExistsError,
                                    Domain));
                        }

                        IValidator <Address> validator = new AddressValidator(partner);

                        if (!await validator.IsValidAsync(customer.BillingProfile.DefaultAddress, CancellationToken).ConfigureAwait(false))
                        {
                            throw new PartnerPowerShellException("The address for the customer is not valid.", PartnerPowerShellErrorCategory.Validation);
                        }
                    }

                    WriteObject(await partner.Customers.CreateAsync(customer).ConfigureAwait(false));
                }
            }, true);
        }
コード例 #2
0
        /// <summary>
        /// Executes the operations associated with the cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            Customer             customer;
            IValidator <Address> validator;
            string country;
            string culture;
            string region;

            if (ShouldProcess(string.Format(CultureInfo.CurrentCulture, Resources.NewPartnerCustomerWhatIf, Name)))
            {
                if (Partner.Domains.ByDomain(Domain).Exists())
                {
                    throw new PSInvalidOperationException(
                              string.Format(
                                  CultureInfo.CurrentCulture,
                                  Resources.DomainExistsError,
                                  Domain));
                }

                country = (string.IsNullOrEmpty(BillingAddressCountry)) ? PartnerSession.Instance.Context.CountryCode : BillingAddressCountry;
                culture = (string.IsNullOrEmpty(Culture)) ? PartnerSession.Instance.Context.Locale : Culture;

                if (string.IsNullOrEmpty(BillingAddressRegion))
                {
                    region = null;
                }
                else
                {
                    region = BillingAddressRegion.Equals("US", StringComparison.InvariantCultureIgnoreCase) ? string.Empty : BillingAddressRegion;
                }

                customer = new Customer
                {
                    AssociatedPartnerId = AssociatedPartnerId,
                    BillingProfile      = new CustomerBillingProfile
                    {
                        CompanyName    = Name,
                        Culture        = culture,
                        DefaultAddress = new Address
                        {
                            AddressLine1 = BillingAddressLine1,
                            AddressLine2 = BillingAddressLine2,
                            City         = BillingAddressCity,
                            Country      = country,
                            FirstName    = ContactFirstName,
                            LastName     = ContactLastName,
                            PhoneNumber  = ContactPhoneNumber,
                            PostalCode   = BillingAddressPostalCode,
                            Region       = region,
                            State        = BillingAddressState
                        },
                        Email     = ContactEmail,
                        FirstName = ContactFirstName,
                        Language  = Language,
                        LastName  = ContactLastName
                    },
                    CompanyProfile = new CustomerCompanyProfile
                    {
                        CompanyName = Name,
                        Domain      = Domain
                    }
                };

                validator = new AddressValidator(Partner);

                if (validator.IsValid(customer.BillingProfile.DefaultAddress))
                {
                    customer = Partner.Customers.Create(customer);

                    WriteObject(customer);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Executes the operations associated with the cmdlet.
        /// </summary>
        public override void ExecuteCmdlet()
        {
            PartnerCenter.Models.Customers.Customer customer;
            IValidator <Address> validator;
            string country;
            string culture;
            string region;

            if (ShouldProcess(string.Format(CultureInfo.CurrentCulture, Resources.NewPartnerCustomerWhatIf, Name)))
            {
                country = (string.IsNullOrEmpty(BillingAddressCountry)) ? PartnerSession.Instance.Context.CountryCode : BillingAddressCountry;
                culture = (string.IsNullOrEmpty(Culture)) ? PartnerSession.Instance.Context.Locale : Culture;

                if (string.IsNullOrEmpty(BillingAddressRegion))
                {
                    region = null;
                }
                else
                {
                    region = BillingAddressRegion.Equals(UnitedStatesCountryCode, StringComparison.InvariantCultureIgnoreCase) ? string.Empty : BillingAddressRegion;
                }

                customer = new PartnerCenter.Models.Customers.Customer
                {
                    AssociatedPartnerId = AssociatedPartnerId,
                    BillingProfile      = new PartnerCenter.Models.Customers.CustomerBillingProfile
                    {
                        CompanyName    = Name,
                        Culture        = culture,
                        DefaultAddress = new Address
                        {
                            AddressLine1 = BillingAddressLine1,
                            AddressLine2 = BillingAddressLine2,
                            City         = BillingAddressCity,
                            Country      = country,
                            FirstName    = ContactFirstName,
                            LastName     = ContactLastName,
                            PhoneNumber  = ContactPhoneNumber,
                            PostalCode   = BillingAddressPostalCode,
                            Region       = region,
                            State        = BillingAddressState
                        },
                        Email     = ContactEmail,
                        FirstName = ContactFirstName,
                        Language  = Language,
                        LastName  = ContactLastName
                    },
                    CompanyProfile = new PartnerCenter.Models.Customers.CustomerCompanyProfile
                    {
                        CompanyName = Name,
                        Domain      = Domain
                    }
                };

                if (!DisableValidation.ToBool())
                {
                    if (Partner.Domains.ByDomain(Domain).ExistsAsync().ConfigureAwait(false).GetAwaiter().GetResult())
                    {
                        throw new PSInvalidOperationException(
                                  string.Format(
                                      CultureInfo.CurrentCulture,
                                      Resources.DomainExistsError,
                                      Domain));
                    }

                    validator = new AddressValidator(Partner);

                    if (!validator.IsValid(customer.BillingProfile.DefaultAddress, d => WriteDebug(d)))
                    {
                        throw new PartnerException("The address for the customer is not valid.");
                    }
                }

                WriteObject(Partner.Customers.CreateAsync(customer).GetAwaiter().GetResult());
            }
        }