/// <summary> /// display the inventory /// </summary> /// <param name="inventory">list of Items</param> public static void DisplayInventory(IList <Item> inventory) { Console.Clear(); Console.WriteLine(); Console.WriteLine("Current Inventory"); Console.WriteLine(); Console.WriteLine("\tName\t\tInventory\t\tBackorder"); foreach (var item in inventory) { if (item is Perishable) { Perishable perishableItem = new Perishable(); perishableItem = item as Perishable; Console.WriteLine($"\t{perishableItem.ItemName}\t\t{perishableItem.CurrentInventory}"); } else if (item is NonPerishable) { NonPerishable nonPerishableItem = new NonPerishable(); nonPerishableItem = item as NonPerishable; Console.WriteLine($"\t{nonPerishableItem.ItemName}\t\t{nonPerishableItem.CurrentInventory}\t\t\t{nonPerishableItem.InventoryToOrder}"); } else { Console.WriteLine("Item has no category."); } } Console.WriteLine("Press any key to continue."); Console.ReadKey(); }
/// <summary> /// cycle through the list of products and sell items /// </summary> /// <param name="inventory">list of Items</param> private static void DisplayPerformTransactions(IList <Item> inventory) { // // declare delegate object // ProductTransaction productTransaction = null; // // sell products // foreach (var item in inventory) { int unitsSold = 0; Console.Clear(); Console.WriteLine(); Console.WriteLine("Sell Products"); Console.WriteLine(); // // get number of units to sell and process based on item class // if (item is NonPerishable) { NonPerishable nonPerishableItem = new NonPerishable(); nonPerishableItem = item as NonPerishable; Console.Write($"Enter the number of {nonPerishableItem.ItemName} sold: "); if (int.TryParse(Console.ReadLine(), out unitsSold)) { productTransaction = ProcessNonPerishableSale; } } else if (item is Perishable) { Perishable perishableItem = new Perishable(); perishableItem = item as Perishable; Console.Write($"Enter the number of {perishableItem.ItemName} sold: "); if (int.TryParse(Console.ReadLine(), out unitsSold)) { productTransaction = ProcessPerishableSale; } } // // process the transaction // ProcessTransaction(productTransaction, item, unitsSold); } Console.WriteLine(); Console.WriteLine("Inventory Complete"); Console.WriteLine("Press any key to continue."); Console.ReadKey(); }
/// <summary> /// process nonperishable item sales /// </summary> /// <param name="item">item to sell</param> /// <param name="units">number to sell</param> public static void ProcessNonPerishableSale(Item item, int units) { NonPerishable nonPerishableItem = new NonPerishable(); nonPerishableItem = item as NonPerishable; if (item.CurrentInventory >= units) { nonPerishableItem.CurrentInventory -= units; } else { nonPerishableItem.InventoryToOrder = Math.Abs(nonPerishableItem.CurrentInventory - units); nonPerishableItem.CurrentInventory = 0; } }