public ActionResult DeleteImage(int id) { using (var context = new SiteContainer()) { var image = context.ContentItemImage.First(c => c.Id == id); var contentItemId = image.ContentItemId; ImageHelper.DeleteImage(image.ImageSource); context.DeleteObject(image); context.SaveChanges(); var contentItem = context.ContentItem.Include("ContentItemImages").First(c => c.Id == contentItemId); if (!contentItem.ContentItemImages.Any()) { context.DeleteObject(contentItem); context.SaveChanges(); } } return RedirectToAction("Index", "Home", new { area = "", id = "look" }); }
public ActionResult DeleteTextBlock(int id) { using (var context = new SiteContainer()) { var contentItem = context.ContentItem.First(c => c.Id == id); context.DeleteObject(contentItem); context.SaveChanges(); return RedirectToAction("Index", "Home", new { area = "", id = "look" }); } }
public ActionResult DeleteImagesBlock(int id) { using (var context = new SiteContainer()) { var contentItem = context.ContentItem.Include("ContentItemImages").First(c => c.Id == id); while (contentItem.ContentItemImages.Any()) { var ci = contentItem.ContentItemImages.First(); ImageHelper.DeleteImage(ci.ImageSource); context.DeleteObject(ci); } context.DeleteObject(contentItem); context.SaveChanges(); return RedirectToAction("Index", "Home", new { area = "", id = "look" }); } }