Exemplo n.º 1
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.TitleDescription = product.TitleDescription;
             dbEntry.Price = product.Price;
             dbEntry.ImageData = product.ImageData;
             dbEntry.ImageMimeType = product.ImageMimeType;
             dbEntry.HowToUseDescription = product.HowToUseDescription;
             dbEntry.Category = product.Category;
         }
     }
     _context.SaveChanges();
 }
Exemplo n.º 2
0
        public ActionResult ProductEdit(Product product, HttpPostedFileBase image, int productId)
        {
            Product productPhoto = _productRepository.GetProducts().FirstOrDefault(p => p.ProductId == productId);

            if (ModelState.IsValid)
            {
                if (image != null)
                {
                    product.ImageMimeType = image.ContentType;
                    product.ImageData = new byte[image.ContentLength];
                    image.InputStream.Read(product.ImageData, 0, image.ContentLength);
                }
                else
                {
                    if (productPhoto != null)
                    {
                        product.ImageMimeType = productPhoto.ImageMimeType;
                        product.ImageData = productPhoto.ImageData;
                    }
                }
                _productRepository.SaveProduct(product);
                TempData["message"] = string.Format("{0} Išsaugota", product.Name);
                return RedirectToAction("Index");
            }
            else
            {
                return View(product);
            }
        }