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