public ActionResult DeleteConfirmed(int id) { Product product = db.Products.Find(id); ImageFuctionality.DeleteImageFromServer(product.imgName, Server.MapPath("~"), ImageFuctionality.imagesDirectoryPath); db.Products.Remove(product); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "ProductId,Name,Description,Price,Category,imgName,Count")] Product product, HttpPostedFileBase file, string imgName_old) { ViewBag.Categories = Utility.CategoriesSelectList(); if (product.Category == "all") { ModelState.AddModelError("Category", "Chose product category"); } if (ModelState.IsValid) { if (file != null) { product.imgName = ImageFuctionality.UploadImage(file, Server.MapPath("~"), ImageFuctionality.imagesDirectoryPath); ImageFuctionality.DeleteImageFromServer(imgName_old, Server.MapPath("~"), ImageFuctionality.imagesDirectoryPath); } db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(product)); }