public void SaveProduct(Product product)
 {
     if (product.ProductID == 0)
     {
         context.Products.Add(product);
     }
     context.SaveChanges();
 }
Esempio n. 2
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);
                }

                // save the product
                repository.SaveProduct(product);
                // add a message to the viewbag
                TempData["message"] = string.Format("{0} был сохранён", product.Name);
                // return the user to the list
                return RedirectToAction("Index");
            }

            // there is something wrong with the data values
            return View(product);
        }
 public void DeleteProduct(Product product)
 {
     context.Products.Remove(product);
     context.SaveChanges();
 }
Esempio n. 5
0
 public void RemoveLine(Product product)
 {
     lineCollection.RemoveAll(l => l.Product.ProductID == product.ProductID);
 }