public ActionResult DeleteConfirmed(int id) { Sliderr sliderr = db.Sliderrs.Find(id); System.IO.File.Delete(Server.MapPath("/Images/Slider/" + sliderr.ImageName)); db.Sliderrs.Remove(sliderr); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: Admin/Sliderrs/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Sliderr sliderr = db.Sliderrs.Find(id); if (sliderr == null) { return(HttpNotFound()); } return(View(sliderr)); }
public ActionResult Edit([Bind(Include = "SliderID,Title,Url,ImageName,StartDate,EndDate,IsActive")] Sliderr sliderr, HttpPostedFileBase imgUp) { if (ModelState.IsValid) { if (imgUp != null) { System.IO.File.Delete(Server.MapPath("/Images/Sliderr/" + sliderr.ImageName)); sliderr.ImageName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(imgUp.FileName); imgUp.SaveAs(Server.MapPath("/Images/Slider/" + sliderr.ImageName)); } db.Entry(sliderr).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(sliderr)); }
public ActionResult Create([Bind(Include = "SliderID,Title,Url,ImageName,StartDate,EndDate,IsActive")] Sliderr sliderr, HttpPostedFileBase imgUp) { if (ModelState.IsValid) { if (imgUp == null) { ModelState.AddModelError("ImageName", "لطفا تصویر را انتخاب کنید"); return(View(sliderr)); } sliderr.ImageName = Guid.NewGuid().ToString() + System.IO.Path.GetExtension(imgUp.FileName); imgUp.SaveAs(Server.MapPath("/Images/Slider/" + sliderr.ImageName)); db.Sliderrs.Add(sliderr); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(sliderr)); }