public ActionResult CartPartial()
        {
            KorpaVM model = new KorpaVM();

            int qty = 0;

            decimal price = 0m;

            if (Session["korpa"] != null)
            {
                var list = (List <KorpaVM>)Session["korpa"];

                foreach (var item in list)
                {
                    qty   += item.Quantity;
                    price += item.Quantity * item.Price;
                }

                model.Quantity = qty;
                model.Price    = price;
            }
            else
            {
                model.Quantity = 0;
                model.Price    = 0m;
            }

            return(PartialView(model));
        }
        public void RemoveProduct(int productId)
        {
            List <KorpaVM> cart = Session["korpa"] as List <KorpaVM>;

            using (Db db = new Db())
            {
                KorpaVM model = cart.FirstOrDefault(x => x.ProductId == productId);

                //Uklanjanje model iz listw
                cart.Remove(model);
            }
        }
        public JsonResult IncrementProduct(int productId)
        {
            List <KorpaVM> cart = Session["korpa"] as List <KorpaVM>;

            using (Db db = new Db())
            {
                KorpaVM model = cart.FirstOrDefault(x => x.ProductId == productId);

                // Inkrementiramo qty
                model.Quantity++;

                var result = new { qty = model.Quantity, price = model.Price };

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult AddToCartPartial(int id)
        {
            List <KorpaVM> cart = Session["korpa"] as List <KorpaVM> ?? new List <KorpaVM>();

            KorpaVM model = new KorpaVM();

            using (Db db = new Db())
            {
                ProductDTO product = db.Products.Find(id);

                // Provera da li proizvod vec postoji u korpi
                var productInCart = cart.FirstOrDefault(x => x.ProductId == id);

                // ako ne postoji dodaje se novi
                if (productInCart == null)
                {
                    cart.Add(new KorpaVM()
                    {
                        ProductId   = product.Id,
                        ProductName = product.Name,
                        Quantity    = 1,
                        Price       = product.Price,
                        Image       = product.ImageName
                    });
                }
                else
                {
                    productInCart.Quantity++;
                }
            }
            int     qty   = 0;
            decimal price = 0m;

            foreach (var item in cart)
            {
                qty   += item.Quantity;
                price += item.Quantity * item.Price;
            }

            model.Quantity = qty;
            model.Price    = price;

            //Cuvanje
            Session["korpa"] = cart;

            return(PartialView(model));
        }
        public ActionResult DecrementProduct(int productId)
        {
            List <KorpaVM> cart = Session["korpa"] as List <KorpaVM>;

            using (Db db = new Db())
            {
                KorpaVM model = cart.FirstOrDefault(x => x.ProductId == productId);

                // Decrementacija qty
                if (model.Quantity > 1)
                {
                    model.Quantity--;
                }
                else
                {
                    model.Quantity = 0;
                    cart.Remove(model);
                }

                var result = new { qty = model.Quantity, price = model.Price };

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }