public ActionResult Detail(long id) { var product = new ProductLib().ViewDetail(id); ViewBag.Category = new ProductCategoryLib().ViewDetail(product.CategoryID.Value); ViewBag.RelatedProducts = new ProductLib().ListRelatedProducts(id); return(View(product)); }
// GET: Home public ActionResult Index() { ViewBag.Slides = new SlideLib().ListAll(); var productLib = new ProductLib(); ViewBag.NewProducts = productLib.ListNewProduct(4); ViewBag.ListFeatureProducts = productLib.ListFeatureProduct(4); return(View()); }
public ActionResult AddItem(long productId, int quantity) { var product = new ProductLib().ViewDetail(productId); 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 { // Add new cart item var item = new CartItem(); item.Product = product; item.Quantity = quantity; list.Add(item); } // Assign to session Session[CartSession] = list; } else { // Add new cart item var item = new CartItem(); item.Product = product; item.Quantity = quantity; var list = new List <CartItem>(); list.Add(item); // Assign to session Session[CartSession] = list; } return(RedirectToAction("Index")); }