Ejemplo n.º 1
0
        public IActionResult AddToCart(int id)
        {
            ShopingCart shopingCart = HttpContext.Session.GetObjectFromJson <ShopingCart>("Cart");

            if (shopingCart == null)
            {
                shopingCart = new ShopingCart();
            }

            Items Item = oItemservice.GetbyId(id);

            ShopingCartItem shopingItem = shopingCart.shopingCartItems.Where(a => a.ItemId == id).FirstOrDefault();

            if (shopingItem != null)// check if  this item in cart or not
            {
                shopingItem.Qty++;
                shopingItem.Total = shopingItem.Price * shopingItem.Qty;
            }
            else
            {
                shopingCart.shopingCartItems.Add(new ShopingCartItem
                {
                    ItemId    = Item.Id,
                    ItemName  = Item.Name,
                    Price     = Item.SalesPrice,
                    ImageName = Item.ImageName,
                    Qty       = 1,
                    Total     = Item.SalesPrice
                });
            }
            shopingCart.Total = shopingCart.shopingCartItems.Sum(a => a.Total);

            HttpContext.Session.SetObjectAsJson("Cart", shopingCart);
            return(Redirect("/Home/Shop"));
        }
Ejemplo n.º 2
0
 public IActionResult Edit(int?id)
 {
     ViewBag.Categories = oCategoryservice.GetAll();
     if (id != null)
     {
         return(View(oItemservice.GetbyId(Convert.ToInt32(id))));
     }
     else
     {
         return(View());
     }
 }