Supermarket.Inventory.Add C# (CSharp) Method

Add() public method

Adds the given product to this inventory if it has a quantity greater than 0.
public Add ( Product product ) : void
product Product The product to store in this inventory.
return void
        public void Add(Product product)
        {
            // Only store product if it has a quantity greater than 0
            if (product.Quantity > 0)
            {
                // If inventory already has a stack of this product
                if (items.ContainsKey(product.Name))
                {
                    // Combine stacks
                    items[product.Name].Quantity += product.Quantity;
                }

                else
                {
                    // New entry
                    items.Add(product.Name, product);
                }
                // Recalculate the new total cost of all items.
                CalculateTotal();
            }
        }