示例#1
0
        public ActionResult Edit(Product product, HttpPostedFileBase image = null)
        {
            if (!ModelState.IsValid)
            {
                return View(product);
            }

            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");
        }
示例#2
0
文件: Cart.cs 项目: korvin888/eStore
 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;
     }
 }
示例#3
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;
             dbEntry.ImageData = product.ImageData;
             dbEntry.ImageMimeType = product.ImageMimeType;
         }
     }
     context.SaveChanges();
 }
示例#4
0
文件: Cart.cs 项目: korvin888/eStore
 public void RemoveLine(Product product)
 {
     lineCollection.RemoveAll(l => l.Product.ProductID == product.ProductID);
 }