public ActionResult Add(int id , CartItem ci) { List<CartItem> cartList = new List<CartItem>(); if (Session["Index"] == null) { cartList.Add(new CartItem { id = cartList.Count + 1,items=findItem(id),quantity=ci.quantity }); //cartList.Add( // new CartItem { id = cartList.Count + 1, items = findItem(id), quantity = 1 }); //ticket.orderItems = cartList; //for (int i =0; i<cartList.Count;i++) //{ // ticket.subTotal += (double)cartList[i].quantity * cartList[i].items.productPrice; //} //Session["Index"] = ticket; } else { cartList = (List<CartItem>)(((Invoice)Session["Index"]).orderItems); if (isExisted(id) == -1) { cartList.Add(new CartItem { id = cartList.Count + 1, items = findItem(id), quantity = ci.quantity }); } else { cartList[isExisted(id)].quantity +=ci.quantity; } } ticket.orderItems = cartList; Session["Add"] = findItem(id); Session["Index"] = ticket; Session["Cart"] = ((Invoice)Session["Index"]).totalQuantity; return RedirectToAction("Index"); }
// GET: Cart/Add/id public ActionResult Add(int id) { CartItem ci = new CartItem(); ci.items = findItem(id); ci.quantity = 1; return PartialView(ci); }