public void Delete(int Id) { using (ApplicationDbContext db = new ApplicationDbContext()) { Product product = db.Products.Find(Id); if (product != null) { db.Products.Remove(product); db.SaveChanges(); ImageManage.Delete(product.ImagePath); } } }
public void Delete(int Id) { using (ApplicationDbContext db = new ApplicationDbContext()) { Category category = db.Categories.Find(Id); List <Product> list = db.Products.Where(m => m.CategoryId == Id).ToList(); foreach (var a in list) { ImageManage.Delete(a.ImagePath); } if (category != null) { db.Categories.Remove(category); db.SaveChanges(); ImageManage.Delete(category.ImagePath); } } }