public void AddItem(Product product, int quantity) { //Check if the product exist add it to the lineCollection. //If there is no product, then return null CartLine line = lineCollection.Where(p => p.Product.ProductId == product.ProductId).FirstOrDefault(); if (line == null) { lineCollection.Add(new CartLine { Product = product, Quantity = quantity }); } else { line.Quantity += quantity; } }
public ActionResult Create(Product product) { if (ModelState.IsValid) { repository.SaveProduct(product); TempData["message"] = string.Format("{0} has been updated", product.Name); return RedirectToAction("Index"); } else { //There is something wrong with the data values return View(product); } }
public void RemoveLine(Product product) { //Remove products from the lineCollection lineCollection.RemoveAll(p => p.Product.ProductId == product.ProductId); }