예제 #1
0
        public ActionResult AddToCart(string ItemNum)
        {
            //psudocode


            if (Session["Prof"] == null)
            {
                Session["prof"] = Cart;
            }

            //Check if item is already in cart
            bool found        = false;
            int  indexOfFound = -1;

            for (int i = 0; i < Cart.getItems().Count; i++)
            {
                CartDetails p = Cart.getItems()[i];
                if (p.ItemNumber.Equals(ItemNum, StringComparison.Ordinal))
                {
                    found        = true;
                    indexOfFound = i;
                    break;
                }
            }

            //if not, add to card
            //Else increase quantity by ones
            if (found)
            {
                Cart.incrementQuantity(indexOfFound);
                //Cart.getTotal();
            }
            else
            {
                CartDetails product = new CartDetails();

                Products item = productInfo.getProInfo(ItemNum);
                product.ItemNumber  = item.ItemNumber;
                product.productName = item.ProductName;
                product.Description = item.ProductDiscription;
                product.Quantity    = 1;
                product.subTotal    = item.ProPrice;
                product.total       = Cart.getTotal();



                Cart.addProduct(product);
                ViewBag.MyCarts = Cart.catDetails.Count();
                Session["prof"] = Cart.catDetails;
            }


            var list = Session["cart"] as CartItems;

            return(View("Product"));
        }