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;
     }
 }
Esempio n. 2
0
 //Добавление в корзину
 public void AddLine(Product product, int quantity)
 {
     //Проверка на наличие его в корзине
     ProductLine line = LineCollection.Where(i => i.Product.Id == product.Id)
                                      .FirstOrDefault();
     //Если нет - добавляем
     if (line == null)
     {
         LineCollection.Add(new ProductLine
             {
                 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
     {
         // 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.Name = product.Name;
             dbEntry.Description = product.Description;
             dbEntry.Price = product.Price;
             dbEntry.Category = product.Category;
             if (product.ImageData!=null)
             {
                 dbEntry.ImageData = product.ImageData;
                 dbEntry.ImageMimeType = product.ImageMimeType;
             }
         }
     }
     context.SaveChanges();
 }
Esempio n. 5
0
 public void RemoveLine(Product product)
 {
     lineCollection.RemoveAll(l => l.Product.ProductId == product.ProductId);
 }
Esempio n. 6
0
 //Удаление с корзины
 public void RemoveLine(Product product)
 {
     LineCollection.RemoveAll(i => i.Product.Id == product.Id);
 }