Esempio n. 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,HttpPostedFileBase Image)
 {
     if (ModelState.IsValid)
     {
         if (Image != null)
         {
             product.ImageMimeType = Image.ContentType;
             product.ImageData = new byte[Image.ContentLength];
             Image.InputStream.Read(product.ImageData, 0, Image.ContentLength);
         }
         repository.SaveProduct(product);
         TempData["message"] = string.Format("{0} has been saved !", product.Name);
         return RedirectToAction("Index");
     }
     else
     {
         return View(product);
     }
 }
 public void SaveProduct(Product product)
 {
     if (product.ProductId == 0)
     {
         context.Products.Add(product);
     }
     else
     {
         Product entity = context.Products.FirstOrDefault(m => m.ProductId == product.ProductId);
         if (entity != null)
         {
             entity.Name = product.Name;
             entity.Category = product.Category;
             entity.Price = product.Price;
             entity.Description = product.Description;
             entity.ImageData = product.ImageData;
             entity.ImageMimeType = product.ImageMimeType;
         }
     }
     context.SaveChanges();
 }
Esempio n. 4
0
 public void RemoveLine(Product product)
 {
     lineCollection.RemoveAll(l => l.Product.ProductId == product.ProductId);
 }