示例#1
0
        public ActionResult addtocart(string ProdId)
        {
            if (Session["Prof"] == null)
            {
                Session["Prof"] = cart;
            }
            bool found        = false;
            int  indexOfFound = -1;

            for (int i = 0; i < cart.getItems().Count; i++)
            {
                ShoppingCart p = cart.getItems()[i];
                if (p.prodID.Equals(ProdId, StringComparison.Ordinal))
                {
                    found        = true;
                    indexOfFound = i;



                    break;
                }
            }


            if (found)
            {
                ShoppingCart product = new ShoppingCart();
                cart.incrementQuantity(indexOfFound);
            }
            else
            {
                ShoppingCart product = new ShoppingCart();

                Product item = prodetails.getinfo(ProdId);
                product.prodID      = item.ProdID;
                product.productName = item.ProdName;
                product.qty         = 1;
                product.subTotal    = item.ProdPrice;
                product.total       = product.subTotal;
                cart.carts(product);

                ViewBag.cart = cart.catDetails.Count();

                Session["Prof"] = cart.catDetails;
                // double total=    cart.getTotal(product);
            }
            // orderTotal += (item.Count * item.Product.Price);



            return(View("Product"));
        }