Beispiel #1
0
        public void AddItem(Product product, int quantity)
        {
            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 Edit(Product product)
 {
     if (ModelState.IsValid)
     {
         repository.SaveProduct(product);
         TempData["message"] = string.Format("{0} has been saved", product.ProductName);
         return RedirectToAction("Index");
     }
     else
     {
         // there is something wrong with the data values
         return View(product);
     }
 }
 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.BrandName = product.BrandName;
             dbEntry.ProductName = product.ProductName;
             dbEntry.ProductType = product.ProductType;
             dbEntry.Description = product.Description;
             dbEntry.Price = product.Price;
             dbEntry.Category = product.Category;
         }
     }
     context.SaveChanges();
 }
Beispiel #4
0
 public void RemoveLine(Product product)
 {
     lineCollection.RemoveAll(l => l.Product.ProductID == product.ProductID);
 }