public ActionResult Edit([Bind(Include = "ProductId,ProductName,UnitPrice,ProductDate,Available,Category,Description")] Product product, HttpPostedFileBase editImage) { if (ModelState.IsValid) { Product modifyProduct = db.Products.Find(product.ProductId); if (modifyProduct != null) { if (editImage != null && editImage.ContentLength > 0) { modifyProduct.Image = new byte[editImage.ContentLength]; // image stored in binary formate editImage.InputStream.Read(modifyProduct.Image, 0, editImage.ContentLength); string fileName = System.IO.Path.GetFileName(editImage.FileName); string urlImage = Server.MapPath("~/Image/" + fileName); editImage.SaveAs(urlImage); modifyProduct.UrlImage = "Image/" + fileName; } } db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }
public ActionResult Edit([Bind(Include = "ProductID,ProductName,ProductGroup,Price,Status,Description")] Product product, HttpPostedFileBase image) { if (ModelState.IsValid) { // Product modifyProduct = db.Products.Find(product.ProductID); if (product != null) { if (image != null && image.ContentLength > 0) { product.Image = new byte[image.ContentLength]; image.InputStream.Read(product.Image, 0, image.ContentLength); string fileName = System.IO.Path.GetFileName(image.FileName); string urlImage = Server.MapPath("~/Image/" + fileName); image.SaveAs(urlImage); product.UrlImage = "Image/" + fileName; } } //db.Entry(modifyProduct).State = EntityState.Modified; db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("GetPaging")); } return(View(product)); }