public CheckoutDeliveryInfoShippingViewModel(StoreFrontConfiguration config, Cart cart, string currentAction) : base(config, cart, currentAction) { this.EmailAddress = cart.Email; if (cart.DeliveryInfoShipping != null) { DeliveryInfoShipping info = cart.DeliveryInfoShipping; this.EmailAddress = info.EmailAddress; this.FullName = info.FullName; this.AdddressL1 = info.AdddressL1; this.AdddressL2 = info.AdddressL2; this.City = info.City; this.State = info.State; this.PostalCode = info.PostalCode; this.CountryCode = info.CountryCode; } else if (cart.UserProfile != null) { this.FullName = cart.UserProfile.FullName; this.AdddressL1 = cart.UserProfile.AddressLine1; this.AdddressL2 = cart.UserProfile.AddressLine2; this.City = cart.UserProfile.City; this.State = cart.UserProfile.State; this.PostalCode = cart.UserProfile.PostalCode; this.CountryCode = cart.UserProfile.CountryCode; } }
public ActionResult DeliveryInfoShipping(CheckoutDeliveryInfoShippingViewModel viewModel) { StoreFrontConfiguration config = CurrentStoreFrontConfigOrThrow; Cart cart = config.StoreFront.GetCart(Session.SessionID, CurrentUserProfileOrNull); if (!cart.CartIsValidForCheckout(this)) { return(RedirectToAction("Index", "Cart")); } if (!cart.StatusStartedCheckout) { return(RedirectToAction("Index")); } if (!cart.StatusSelectedLogInOrGuest) { return(RedirectToAction("LogInOrGuest")); } cart = cart.ValidateCartAndSave(this); if (cart.AllItemsAreDigitalDownload) { return(RedirectToAction("DeliveryInfo")); } //check if custom form is valid if (config.CheckoutDeliveryInfoShippingWebForm != null) { FormProcessorExtensions.ValidateFields(this, config.CheckoutDeliveryInfoShippingWebForm); } if (ModelState.IsValid) { WebFormResponse webFormResponse = cart.DeliveryInfoShippingProcessWebForm(this); DeliveryInfoShipping info = null; if (cart.DeliveryInfoShipping == null) { info = GStoreDb.DeliveryInfoShippings.Create(); info.SetDefaults(CurrentUserProfileOrNull); info.Client = CurrentClientOrThrow; info.ClientId = info.Client.ClientId; info.StoreFront = CurrentStoreFrontOrThrow; info.StoreFrontId = info.StoreFront.StoreFrontId; info.StartDateTimeUtc = DateTime.UtcNow.AddMinutes(-1); info.EndDateTimeUtc = DateTime.UtcNow.AddYears(100); info.Cart = cart; info.CartId = cart.CartId; info.AdddressL1 = viewModel.AdddressL1; info.AdddressL2 = viewModel.AdddressL2; info.EmailAddress = viewModel.EmailAddress; info.FullName = viewModel.FullName; info.City = viewModel.City; info.State = viewModel.State; info.PostalCode = viewModel.PostalCode; info.CountryCode = viewModel.CountryCode.Value; if (webFormResponse != null) { info.WebFormResponseId = webFormResponse.WebFormResponseId; } info = GStoreDb.DeliveryInfoShippings.Add(info); } else { info = cart.DeliveryInfoShipping; info.AdddressL1 = viewModel.AdddressL1; info.AdddressL2 = viewModel.AdddressL2; info.EmailAddress = viewModel.EmailAddress; info.FullName = viewModel.FullName; info.City = viewModel.City; info.State = viewModel.State; info.PostalCode = viewModel.PostalCode; info.CountryCode = viewModel.CountryCode.Value; if (webFormResponse != null) { info.WebFormResponseId = webFormResponse.WebFormResponseId; } info = GStoreDb.DeliveryInfoShippings.Update(info); } cart.DeliveryInfoShipping = info; cart.Email = viewModel.EmailAddress; cart.FullName = viewModel.FullName; cart.StatusCompletedDeliveryInfo = true; GStoreDb.Carts.Update(cart); GStoreDb.SaveChanges(); GStoreDb.LogUserActionEvent(HttpContext, RouteData, this, UserActionCategoryEnum.Checkout, UserActionActionEnum.Checkout_CompletedDeliveryInfo, "", true, cartId: cart.CartId); return(RedirectToAction("DeliveryMethod")); } viewModel.UpdateForRepost(config, cart, RouteData.Action()); return(View("DeliveryInfoShipping", viewModel)); }