/// <summary> /// The as customer address. /// </summary> /// <param name="adr"> /// The adr. /// </param> /// <param name="existing"> /// The existing. /// </param> /// <returns> /// The <see cref="ICustomerAddress"/>. /// </returns> public static ICustomerAddress AsCustomerAddress(this CustomerAddressModel adr, ICustomerAddress existing) { existing.Label = adr.Label; existing.FullName = adr.FullName; existing.Company = adr.Company; existing.AddressType = adr.AddressType == "shipping" ? AddressType.Shipping : AddressType.Billing; existing.Address1 = adr.Address1; existing.Address2 = adr.Address2; existing.Locality = adr.Locality; existing.Region = adr.Region; existing.PostalCode = adr.PostalCode; existing.CountryCode = adr.CountryCode; existing.Phone = adr.Phone; return(existing); }
/// <summary> /// The as customer address. /// </summary> /// <param name="adr"> /// The adr. /// </param> /// <returns> /// The <see cref="ICustomerAddress"/>. /// </returns> public static ICustomerAddress AsCustomerAddress(this CustomerAddressModel adr) { var customerAddress = new CustomerAddress(adr.CustomerKey) { Label = adr.Label, FullName = adr.FullName, Company = adr.Company, AddressType = adr.AddressType == "shipping" ? AddressType.Shipping : AddressType.Billing, Address1 = adr.Address1, Address2 = adr.Address2, Locality = adr.Locality, Region = adr.Region, PostalCode = adr.PostalCode, CountryCode = adr.CountryCode, Phone = adr.Phone, IsDefault = false }; if (!adr.Key.Equals(Guid.Empty)) customerAddress.Key = adr.Key; return customerAddress; }
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 RenderCustomerAddressForm(CustomerAddressModel model) { return this.PartialView(PathHelper.GetThemePartialViewPath(model.Theme, "CustomerAddressForm"), model); }