public void DeleteProduct(int productId) { using (MySqlProductsDb Db = new MySqlProductsDb(ConnectionString)) { var prod = new Product() { ProductID = productId }; Db.Products.Attach(prod); Db.Products.Remove(prod); Db.SaveChanges(); } }
public int StoreProduct(Product product) { using (MySqlProductsDb Db = new MySqlProductsDb(ConnectionString)) { Db.Products.Add(product); Db.SaveChanges(); } return product.ProductID; }
public void SetInventory(int productId, int quantity) { var prod = GetProductById(productId); using (MySqlProductsDb Db = new MySqlProductsDb(ConnectionString)) { if (prod != null) { Db.Products.Attach(prod); prod.Inventory = quantity; Db.Entry(prod).Property("Inventory").IsModified = true; Db.SaveChanges(); } } }