// Removes inventory with given amount, if given amount is bigger than current amount - throw exception public void RemoveInventory(Inventory inventory, int amount) { InventoryAmount curr = InventoryAmountList.Find(x => x.Inventory.Equals(inventory)); if (curr.Amount > amount) { curr.Amount -= amount; } else { throw new Exception($"Not enough amount in stock"); } }
// Removes inventory from stock public void RemoveInventory(Inventory inventory) { InventoryAmount curr = InventoryAmountList.Find(x => x.Inventory.Equals(inventory)); if (curr != null) { InventoryAmountList.Remove(curr); } else { throw new Exception("No inventory found"); } }
// Get amount of given inventory in stock. If the `inventory` is not found, return 0. public int GetInventoryAmount(Inventory inventory) { InventoryAmount curr = InventoryAmountList.Find(x => x.Inventory.Equals(inventory)); return(curr != null ? curr.Amount : 0); }