Example #1
0
        public void AddItem(Product product, int quantity)
        {
            CartLine line = lineCollection.FirstOrDefault(p => p.Product.ProductID == product.ProductID);

            if (line == null)
            {
                lineCollection.Add(new CartLine
                {
                    Product = product,
                    Quantity = quantity
                });
            }
            else
            {
                line.Quantity += quantity;
            }
        }
        public void SaveProduct(Product product)
        {

            if (product.ProductID == 0)
            {
                context.Products.Add(product);
            }
            else
            {
                Product dbEntry = context.Products.Find(product.ProductID);
                if (dbEntry != null)
                {
                    dbEntry.Name = product.Name;
                    dbEntry.Description = product.Description;
                    dbEntry.Price = product.Price;
                    dbEntry.Category = product.Category;
                  
                }
            }
            context.SaveChanges();
        }
Example #3
0
 public void RemoveLine(Product product)
 {
     lineCollection.RemoveAll(l => l.Product.ProductID == product.ProductID);
 }
Example #4
0
 public ActionResult Edit(Product product)
 {
     if (ModelState.IsValid)
     {
         
         repository.SaveProduct(product);
         TempData["message"] = string.Format("{0} has been saved", product.Name);
         return RedirectToAction("Index");
     }
     else
     {
      
         return View(product);
     }
 }