コード例 #1
0
        //cart получаем из CartModelBinder
        public RedirectToActionResult AddToCart(Cart cart, int gameId, string returnUrl)
        {
            Game game = _repository.Games.FirstOrDefault(g => g.GameId == gameId);

            if (game != null)
            {
                cart.AddItem(game, 1);
                CartModelBinder.SetUpCart(cart, HttpContext.Session);
            }
            return(RedirectToAction("Index", new { returnUrl }));
        }
コード例 #2
0
        public RedirectToActionResult RemoveFromCart(Cart cart, int gameId, string returnUrl)
        {
            Game game = _repository.Games.FirstOrDefault(g => g.GameId == gameId);

            if (game != null)
            {
                cart.RemoveLine(game);
                if (HttpContext != null)
                {
                    CartModelBinder.SetUpCart(cart, HttpContext.Session);
                }
            }
            return(RedirectToAction("Index", new { returnUrl }));
        }
コード例 #3
0
 public ViewResult Checkout(Cart cart, ShippingDetails shippingDetails)
 {
     if (cart.Lines.Count() == 0)
     {
         ModelState.AddModelError("", "Извените ваша корзина пуста");
     }
     if (ModelState.IsValid)
     {
         _processor.ProcessOrder(cart, shippingDetails);
         cart.Clear();
         if (HttpContext != null)
         {
             CartModelBinder.SetUpCart(cart, HttpContext.Session);
         }
         return(View("Completed"));
     }
     else
     {
         return(View(shippingDetails));
     }
 }
コード例 #4
0
        public IViewComponentResult Invoke()
        {
            Cart cart = CartModelBinder.GetCart(HttpContext.Session);

            return(View(cart));
        }