public void DbSaveItem(Item newItem) { DbInventoryContext db = new DbInventoryContext(); Item item = GetItemFromDbContext(db, newItem.ItemId); item.ItemName = newItem.ItemName; item.Quantity = newItem.Quantity; db.SaveChanges(); }
public int DbAddItem(string name, int quantity) { DbInventoryContext context = new DbInventoryContext(); Item item = new Item { ItemName = name, Quantity = quantity }; context.Items.Add(item); context.SaveChanges(); return item.ItemId; }
public void DbRemoveItem(int id) { DbInventoryContext db = new DbInventoryContext(); var query = from c in db.Items select c; Item item = query.FirstOrDefault(c => c.ItemId == id); db.Items.Remove(item); db.SaveChanges(); }
public int DbAddQuantity(int itemId, int quantity) { DbInventoryContext db = new DbInventoryContext(); var query = from c in db.Items select c; Item item = query.FirstOrDefault(c => c.ItemId == itemId); item.Quantity += quantity; db.SaveChanges(); return item.ItemId; }