Beispiel #1
0
        public ActionResult DeliveryInfoDigitalOnly(CheckoutDeliveryInfoDigitalOnlyViewModel 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.CheckoutDeliveryInfoDigitalOnlyWebForm != null)
            {
                FormProcessorExtensions.ValidateFields(this, config.CheckoutDeliveryInfoDigitalOnlyWebForm);
            }

            if (ModelState.IsValid)
            {
                WebFormResponse webFormResponse = cart.DeliveryInfoDigitalOnlyProcessWebForm(this);

                DeliveryInfoDigital info = null;
                if (cart.DeliveryInfoDigital == null)
                {
                    info = GStoreDb.DeliveryInfoDigitals.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.EmailAddress = viewModel.EmailAddress;
                    info.FullName = viewModel.FullName;
                    if (webFormResponse != null)
                    {
                        info.WebFormResponseId = webFormResponse.WebFormResponseId;
                    }

                    info = GStoreDb.DeliveryInfoDigitals.Add(info);
                }
                else
                {
                    info = cart.DeliveryInfoDigital;

                    info.EmailAddress = viewModel.EmailAddress;
                    info.FullName = viewModel.FullName;

                    if (webFormResponse != null)
                    {
                        info.WebFormResponseId = webFormResponse.WebFormResponseId;
                    }
                    info = GStoreDb.DeliveryInfoDigitals.Update(info);
                }

                cart.DeliveryInfoDigital = 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("DeliveryInfoDigitalOnly", viewModel);
        }
Beispiel #2
0
        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);
            }
        }