Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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));
            }
        }
Exemplo n.º 4
0
        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));
        }
Exemplo n.º 5
0
        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));
            }
        }