コード例 #1
0
 public void AddItem(Product product, int quantity)
 {
     var line = _lineCollection.FirstOrDefault(p => p.Product.ProductId == product.ProductId);
     if (line == null)
     {
         _lineCollection.Add(new CartLine { Product = product, Quantity = quantity });
     }
     else
     {
         line.Quantity += quantity;
     }
 }
コード例 #2
0
ファイル: Cart.cs プロジェクト: jedjad/GitHubVS2013
 public void AddItem(Product product, int quantity)
 {
     CartLine line = lineCollection.Where(p => p.Product == product).FirstOrDefault(); //return a product or null
     if (line == null)
     {
         lineCollection.Add(
             new CartLine { Product = product, Quantity = quantity });   // add an order if there is no order
     }
     else   //if there is already a pre-exisitng order, program assumes we are just adding additional quantity
     {
         line.Quantity += quantity;  //just add the amount of order to the existing order, line is a product query
     }
 }
コード例 #3
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);
     }
 }
コード例 #4
0
 public ActionResult Create(Product product)
 {
     if (ModelState.IsValid)
     {
         repository.SaveProduct(product);
         TempData["message"] = string.Format("{0} has been saved", product.Name);
         return RedirectToAction("Index");
     }
     //there is something wrong with the data values
     else
     {
         return View(product);
     }
 }
コード例 #5
0
 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();
 }
コード例 #6
0
 public void SaveProduct(Product product)
 {
     //THIS IS A NEW PRODUCT
     if (product.ProductId == 0)
     {
         context.Products.Add(product);
     }
     else
     {
         //FIND THE PRODUCT 
         Product dbEntry =
             context.Products.Find(product.ProductId);
         // IF WE CANNOT FIND THE PRODUCT THEN CREATE THE PRODUCT
         if (dbEntry != null)
         {
             dbEntry.Name = product.Name;
             dbEntry.Description = product.Description;
             dbEntry.Price = product.Price;
             dbEntry.Category = product.Category;
         }
     }
     context.SaveChanges();
 }
コード例 #7
0
 public void RemoveLine(Product product)
 {
     lineCollection.RemoveAll(p => p.Product.ProductId == product.ProductId);
 }