public ActionResult Delete(int id) { using (var context = new StructureContainer()) { 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 StructureContainer()) { var product = context.Product.Include("Category").First(p => p.Id == id); var categoryId = product.Category.Id; var category = context.Category.Include("Parent").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 category.Parent != null ? RedirectToAction("Index", "Catalogue", new { Area = "", category = category.Parent.Name, subCategory = category.Name }) : RedirectToAction("Index", "Catalogue", new { Area = "", category = category.Name }); } }
public ActionResult Delete(int id) { using (var context = new StructureContainer()) { var content = context.Content.First(c => c.Id == id); context.DeleteObject(content); context.SaveChanges(); return RedirectToAction("Index", "Home", new {area = "", id = ""}); } }
public ActionResult Delete(int id) { using (var context = new StructureContainer()) { var category = context.Category.Include("Children").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(); while (category.Children.Any()) { int catId = category.Children.First().Id; var child = context.Category.Include("Products").Include("ProductAttributes").First(c => c.Id == catId); child.ProductAttributes.Load(); while (child.Products.Any()) { var product = child.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(); } } child.Products.Clear(); child.ProductAttributes.Clear(); context.DeleteObject(child); context.SaveChanges(); } category.ProductAttributes.Load(); category.ProductAttributes.Clear(); context.DeleteObject(category); context.SaveChanges(); } return RedirectToAction("Index", "Home", new { Area = "", id = "" }); }