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); }
public ActionResult DeliveryInfo() { 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) { CheckoutDeliveryInfoDigitalOnlyViewModel viewModelDigitalOnly = new CheckoutDeliveryInfoDigitalOnlyViewModel(config, cart, RouteData.Action()); return View("DeliveryInfoDigitalOnly", viewModelDigitalOnly); } else { CheckoutDeliveryInfoShippingViewModel viewModelShipping = new CheckoutDeliveryInfoShippingViewModel(config, cart, RouteData.Action()); return View("DeliveryInfoShipping", viewModelShipping); } }