public ActionResult DeleteConfirmed(int id) { ResetImageTB resetImageTB = db.ResetImageTBs.Find(id); db.ResetImageTBs.Remove(resetImageTB); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: SMAdm/ResetImage/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ResetImageTB resetImageTB = db.ResetImageTBs.Find(id); if (resetImageTB == null) { return(HttpNotFound()); } return(View(resetImageTB)); }
public ActionResult Create([Bind(Include = "ResetImageId,ResetPhoto")] ResetImageTB resetImageTB, HttpPostedFileBase Photo) { if (ModelState.IsValid) { if (Photo != null) { WebImage img = new WebImage(Photo.InputStream); FileInfo photoInfo = new FileInfo(Photo.FileName); string newPhoto = Guid.NewGuid().ToString() + photoInfo.Extension; img.Save("~/Uploads/AboutPhoto/" + newPhoto); resetImageTB.ResetPhoto = "/Uploads/AboutPhoto/" + newPhoto; } db.ResetImageTBs.Add(resetImageTB); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(resetImageTB)); }
public ActionResult Edit([Bind(Include = "ResetImageId,ResetPhoto")] ResetImageTB resetImageTB, int id, HttpPostedFileBase Photo) { if (ModelState.IsValid) { var resImg = db.ResetImageTBs.SingleOrDefault(m => m.ResetImageId == id); if (Photo != null) { if (System.IO.File.Exists(Server.MapPath(resImg.ResetPhoto))) { System.IO.File.Delete(Server.MapPath(resImg.ResetPhoto)); } WebImage img = new WebImage(Photo.InputStream); FileInfo photoInfo = new FileInfo(Photo.FileName); string newPhoto = Guid.NewGuid().ToString() + photoInfo.Extension; img.Save("~/Uploads/AboutPhoto/" + newPhoto); resImg.ResetPhoto = "/Uploads/AboutPhoto/" + newPhoto; } db.SaveChanges(); return(RedirectToAction("Index")); } return(View(resetImageTB)); }