public void DeleteCategory(Product product) { using (BazaarContext context = new BazaarContext()) { context.Entry(product).State = System.Data.Entity.EntityState.Deleted; context.SaveChanges(); } }
public void UpdateCategory(Category category) { using (BazaarContext context = new BazaarContext()) { context.Entry(category).State = System.Data.Entity.EntityState.Modified; context.SaveChanges(); } }
private void lstCategoryProducts_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Delete && lstCategoryProducts.SelectedIndex > -1) { Product p = (Product)lstCategoryProducts.SelectedItem; db.Entry(p).State = EntityState.Deleted; db.SaveChanges(); ListCategories(); ListProducts(); } }