Ejemplo n.º 1
0
        public ActionResult SaveCustomerAddress(CustomerAddressModel model)
        {
            var isValid = ModelState.IsValidField("FullName") && ModelState.IsValidField("Label") &&
                          ModelState.IsValidField("Address1") && ModelState.IsValidField("Locality") &&
                          ModelState.IsValidField("PostalCode") && ModelState.IsValidField("CountryCode");

            if (!isValid)
            {
                return(this.CurrentUmbracoPage());
            }
            ICustomerAddress customerAddress;

            if (!model.Key.Equals(Guid.Empty))
            {
                var existing = MerchelloServices.CustomerService.GetAddressByKey(model.Key);
                customerAddress = model.AsCustomerAddress(existing);
            }
            else
            {
                customerAddress = model.AsCustomerAddress();
            }

            MerchelloServices.CustomerService.Save(customerAddress);
            CustomerContext.Reinitialize(CurrentCustomer);
            return(this.SuccessfulRedirect(model.AccountPageId));
        }
        public ActionResult SaveCustomerAddress(CustomerAddressModel model)
        {
            var isValid = ModelState.IsValidField("FullName") && ModelState.IsValidField("Label") &&
                          ModelState.IsValidField("Address1") && ModelState.IsValidField("Locality") &&
                          ModelState.IsValidField("PostalCode") && ModelState.IsValidField("CountryCode") &&
                          !model.CustomerKey.Equals(Guid.Empty);

            var customer = MerchelloServices.CustomerService.GetByKey(model.CustomerKey);

            if (customer == null)
            {
                throw new NullReferenceException("customer was null");
            }

            if (!isValid)
            {
                return(this.CurrentUmbracoPage());
            }
            ICustomerAddress customerAddress;

            if (!model.Key.Equals(Guid.Empty))
            {
                var existing = MerchelloServices.CustomerService.GetAddressByKey(model.Key);
                customerAddress = model.AsCustomerAddress(existing);
            }
            else
            {
                customerAddress = model.AsCustomerAddress();
            }

            // Using the extension internally adds or updates against the existing addresses
            // and then saves the customer record rather than the address independently.
            // This asserts the customer index (Examine) will be updated correctly.
            //// http://issues.merchello.com/youtrack/issue/M-786
            customer.SaveCustomerAddress(customerAddress);

            // This method is obsolete and never should have been exposed as it "may not" reindex
            // the customer correctly in Examine.
            // MerchelloServices.CustomerService.Save(customerAddress);
            CustomerContext.Reinitialize(CurrentCustomer);
            return(this.SuccessfulRedirect(model.AccountPageId));
        }
        public ActionResult SaveCustomerAddress(CustomerAddressModel model)
        {
            if (!ModelState.IsValid)
            {
                return(this.CurrentUmbracoPage());
            }
            ICustomerAddress customerAddress;

            if (!model.Key.Equals(Guid.Empty))
            {
                var existing = MerchelloServices.CustomerService.GetAddressByKey(model.Key);
                customerAddress = model.AsCustomerAddress(existing);
            }
            else
            {
                customerAddress = model.AsCustomerAddress();
            }

            MerchelloServices.CustomerService.Save(customerAddress);
            CustomerContext.Reinitialize(CurrentCustomer);
            return(this.SuccessfulRedirect(model.AccountPageId));
        }