public ActionResult Delete(int id) { using (var context = new SiteContainer()) { Article article = context.Article.First(a => a.Id == id); context.DeleteObject(article); context.SaveChanges(); } return RedirectToAction("Index", "Home", new { Area = "", id = "" }); }
public ActionResult Delete(int id) { using (var context = new SiteContainer()) { var productAttribute = context.ProductAttribute .Include("Categories") .Include("Products") .First(pa => pa.Id == id); productAttribute.Products.Clear(); productAttribute.Categories.Clear(); context.DeleteObject(productAttribute); context.SaveChanges(); } return RedirectToAction("Index"); }
public ActionResult Delete(int id) { using (var context = new SiteContainer()) { var product = context.Product.Include("Category").First(p => p.Id == id); var categoryId = product.Category.Id; var category = context.Category.First(c => c.Id == categoryId); if (!string.IsNullOrEmpty(product.ImageSource)) { IOHelper.DeleteFile("~/Content/Images", product.ImageSource); IOHelper.DeleteFile("~/ImageCache/galleryThumbnail", product.ImageSource); } product.ProductAttributes.Clear(); context.DeleteObject(product); context.SaveChanges(); return RedirectToAction("Index", "Catalogue", new { Area = "", id = category.Name }); } }
public ActionResult Delete(int id) { using (var context = new SiteContainer()) { var category = context.Category.Include("Products").First(c => c.Id == id); while (category.Products.Any()) { var product = category.Products.First(); if (!string.IsNullOrEmpty(product.ImageSource)) { IOHelper.DeleteFile("~/Content/Images", product.ImageSource); IOHelper.DeleteFile("~/ImageCache/galleryThumbnail", product.ImageSource); product.ProductAttributes.Clear(); context.DeleteObject(product); } } context.SaveChanges(); category.ProductAttributes.Load(); category.ProductAttributes.Clear(); context.DeleteObject(category); context.SaveChanges(); } return RedirectToAction("Index", "Home", new { Area = "", id = "" }); }