예제 #1
0
        public IActionResult OnGetBuy(int id)
        {
            var product = productData.GetProductById(id);

            if (HttpContext.Session.GetObjectFromJson <List <ShoppingCart> >("CartItems") != null)
            {
                CartItems = HttpContext.Session.GetObjectFromJson <List <ShoppingCart> >("CartItems").ToList();
                var productiInCart = CartItems.SingleOrDefault(x => x.Product.Id == id);

                if (CartItems.Contains(productiInCart))
                {
                    return(RedirectToPage("./ShoppingCart"));
                }
            }
            CartItems.Add(cartBL.AddCartItem(product));

            HttpContext.Session.SetObjectAsJson("CartItems", CartItems);
            CartItems = HttpContext.Session.GetObjectFromJson <List <ShoppingCart> >("CartItems").ToList();
            return(RedirectToPage("./ShoppingCart"));
            //return Page();
        }