/// <summary> /// Find the selected item in InventoryItems and subtract 1 from the count /// If the count becomes 0 remove the item from InventoryItems /// </summary> private void RemoveOneFromList() { if (SelectedItem == null) { MessageBox.Show("Please Select an Item to remove."); return; } InventoryItem item = InventoryItems.First(x => x.Name == SelectedItem.Name); item.ItemCount--; if (item.ItemCount == 0) { InventoryItems.Remove(item); } }
/// <summary> /// We will look at the InventoryItems if the current text in the textbox is in the ListView /// we just need to add to the count, if not we need to add to the InventoryItems /// </summary> private void AddItemToList() { if (InventoryItems.Any(p => p.Name == InputName) && InventoryItems.Count > 0) { InventoryItems.First(x => x.Name == InputName).ItemCount++; } else { if (string.IsNullOrEmpty(InputName)) { MessageBox.Show("Please enter an item in the text box"); return; } InventoryItems.Add(new InventoryItem() { Name = InputName, ItemCount = 1 }); } Item = new InventoryItem(); }