Beispiel #1
0
        // GET: Product/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(Redirect("/"));
            }

            var product = ProductBus.Find(id);

            if (product == null)
            {
                return(Redirect("/"));
            }

            ViewBag.Images = ImageBus.List(id);

            return(View(ProductBus.Details(id)));
        }
Beispiel #2
0
        //add a product to cart
        public ActionResult AddItem(int productId, int quantity)
        {
            var cart = Session[CartSession];

            if (cart != null)
            {
                var list = (List <CartItem>)cart;
                if (list.Exists(x => x.Product.Id == productId))
                {
                    foreach (var item in list)
                    {
                        if (item.Product.Id == productId)
                        {
                            item.Quantity += quantity;
                        }
                    }
                }
                else
                {
                    //create new cartItem object
                    var item = new CartItem();
                    item.Product  = ProductBus.Details(productId);
                    item.Quantity = quantity;
                    list.Add(item);
                }
                //set to session
                Session[CartSession] = list;
            }
            else
            {
                //create new cartItem object
                var item = new CartItem();
                item.Product  = ProductBus.Details(productId);
                item.Quantity = quantity;
                var list = new List <CartItem>();
                list.Add(item);
                //set to session
                Session[CartSession] = list;
            }
            return(RedirectToAction("Index"));
        }