public ActionResult BillingAddress(AddressModel billingAddress, ChangeStepType changeStep) { ViewBag.Countries = Context.Database.Items["/sitecore/system/Settings/Analytics/Lookups/Countries/"]; ViewBag.Addresses = this.cartService.GetAddresses().Select(a => a.ToAddressModel()); if (changeStep != ChangeStepType.Next || !this.ModelState.IsValid) { return(View(billingAddress)); } // If address is not new if (!string.IsNullOrEmpty(billingAddress.PartyId)) { if (billingAddress.IsChanged((AddressModel)TempData["billing_address"])) { this.cartService.UpdateAddresses(new List <Party>() { billingAddress.ToParty() }); } this.cartService.SetBillingAddressToCart(new CartParty() { ExternalId = billingAddress.PartyId, PartyID = billingAddress.PartyId }); // proceed to next step return(this.RedirectToAction("ShippingAddress")); } // Add a new address to customer var party = billingAddress.ToParty(); var addresses = this.cartService.AddAddress(party); var address = addresses.FirstOrDefault(a => a.FirstName == party.FirstName && a.LastName == party.LastName && a.Email == party.Email); if (address == null) { this.ModelState.AddModelError(string.Empty, "Address could not be added to cart"); return(View(billingAddress)); } var result = this.cartService.SetBillingAddressToCart(new CartParty { ExternalId = address.ExternalId, PartyID = address.PartyId }); if (!result) { this.ModelState.AddModelError(string.Empty, "Could not update billing address"); return(View(billingAddress)); } // proceed to next step return(this.RedirectToAction("ShippingAddress")); }