public ActionResult DeleteContent(int id) { using (var context = new ContentStorage()) { Content content = context.Content.Where(c => c.Id == id).FirstOrDefault(); while (content.GalleryItems.Any()) { context.DeleteObject(content.GalleryItems.First()); } context.DeleteObject(content); context.SaveChanges(); return RedirectToAction("Index", "Home", new { area = "", id = "" }); } }
public ActionResult DeletePhoto(int id) { using (var context = new ContentStorage()) { var photo = context.GalleryItem.Include("Content").Where(p => p.Id == id).First(); long dcId = photo.Content.Id; var content = context.Content.Where(dc => dc.Id == dcId).First(); if (!string.IsNullOrEmpty(photo.ImageSource)) { IOHelper.DeleteFile("~/Content/Photos", photo.ImageSource); } context.DeleteObject(photo); context.SaveChanges(); return RedirectToAction("Index", "Home", new { area = "", id = content.Name }); } }