public ActionResult Edit(FoodGallery foodGallery, HttpPostedFileBase Image) { if (ModelState.IsValid) { #region Upload Image if (Image != null) { if (System.IO.File.Exists(Server.MapPath("/Files/FoodImages/" + foodGallery.Image))) { System.IO.File.Delete(Server.MapPath("/Files/FoodImages/Temp/" + foodGallery.Image)); } // Saving Temp Image var newFileName = Guid.NewGuid() + Path.GetExtension(Image.FileName); Image.SaveAs(Server.MapPath("/Files/FoodImages/Temp/" + newFileName)); // Resize Image ImageResizer image = new ImageResizer(800, 600, true); image.Resize(Server.MapPath("/Files/FoodImages/Temp/" + newFileName), Server.MapPath("/Files/FoodImages/" + newFileName)); // Deleting Temp Image System.IO.File.Delete(Server.MapPath("/Files/FoodImages/Temp/" + newFileName)); foodGallery.Image = newFileName; } #endregion _repo.Update(foodGallery); return(RedirectToAction("Index")); } return(View(foodGallery)); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } FoodGallery foodGallery = _repo.Get(id.Value); if (foodGallery == null) { return(HttpNotFound()); } return(PartialView(foodGallery)); }