public ActionResult DeleteConfirmed(int id) { NewsTB newsTB = db.NewsTBs.Find(id); db.NewsTBs.Remove(newsTB); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: SMAdm/NewsImage/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } NewsTB newsTB = db.NewsTBs.Find(id); if (newsTB == null) { return(HttpNotFound()); } return(View(newsTB)); }
public ActionResult Create([Bind(Include = "NewsId,NewsPhoto")] NewsTB newsTB, 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); newsTB.NewsPhoto = "/Uploads/AboutPhoto/" + newPhoto; } db.NewsTBs.Add(newsTB); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(newsTB)); }
public ActionResult Edit([Bind(Include = "NewsId,NewsPhoto")] NewsTB newsTB, int id, HttpPostedFileBase Photo) { if (ModelState.IsValid) { var articles = db.NewsTBs.SingleOrDefault(m => m.NewsId == id); if (Photo != null) { if (System.IO.File.Exists(Server.MapPath(articles.NewsPhoto))) { System.IO.File.Delete(Server.MapPath(articles.NewsPhoto)); } WebImage img = new WebImage(Photo.InputStream); FileInfo photoInfo = new FileInfo(Photo.FileName); string newPhoto = Guid.NewGuid().ToString() + photoInfo.Extension; img.Save("~/Uploads/AboutPhoto/" + newPhoto); articles.NewsPhoto = "/Uploads/AboutPhoto/" + newPhoto; } db.SaveChanges(); return(RedirectToAction("Index")); } return(View(newsTB)); }