// GET: ImageSlider public ActionResult Index() { using (MVC_WebsiteContext db = new MVC_WebsiteContext()) { return View(db.Galleries.ToList()); } }
public ActionResult AddImage(HttpPostedFileBase imagePath) { if (imagePath != null) { System.Drawing.Image img = System.Drawing.Image.FromStream(imagePath.InputStream); string pic = System.IO.Path.GetFileName(imagePath.FileName); string path = System.IO.Path.Combine(Server.MapPath("~/Content/SliderPhotos/"), pic); imagePath.SaveAs(path); using (MVC_WebsiteContext db = new MVC_WebsiteContext()) { Gallery gallery = new Gallery { ImagePath = "~/Content/SliderPhotos/" + pic }; db.Galleries.Add(gallery); db.SaveChanges(); } } return RedirectToAction("Index"); }
public ActionResult DeleteImages(IEnumerable<int> ImageIDs) { using (MVC_WebsiteContext db = new MVC_WebsiteContext()) { foreach (var id in ImageIDs) { var image = db.Galleries.Single(s => s.ID == id); string imgPath = Server.MapPath(image.ImagePath); if (System.IO.File.Exists(imgPath)) { System.IO.File.Delete(imgPath); } db.Galleries.Remove(image); } db.SaveChanges(); } return RedirectToAction("DeleteImages"); }