private void ShowViewInventoryOption() { while (true) { Console.Clear(); _cart.PrintHeader(); // list the inventory categories Console.WriteLine(); Console.WriteLine("ASCII Art Categories"); Console.WriteLine(); foreach (var category in _repo.Categories) { Console.Write($"{category.Id}. {category.Description}"); Console.Write(" "); } Console.WriteLine(); // allow category selection Console.Write("Select a category: "); int categoryId = 0; if (!int.TryParse(Console.ReadLine(), out categoryId)) { Console.Clear(); return; } Console.Clear(); _cart.PrintHeader(); // display all art in that category foreach (var art in _repo.Categories.First(c => c.Id == categoryId).ASCIIArtPieces) { Console.WriteLine(); if (art.NumberInStock == 0) { Console.WriteLine($"Id: {art.Id}\t\tOut Of Stock!"); } else { Console.WriteLine($"Id: {art.Id}\t\t{art.Price.ToString("c")}\t\t{art.NumberAvailable} In Stock."); } Console.WriteLine(art); Console.WriteLine(); } Console.WriteLine(); Console.WriteLine("1. Make purchase."); Console.WriteLine("2. Main Menu."); Console.Write("Option: "); if (Console.ReadLine() == "1") { // allow purchase and fire a sale event Console.Write("Select your purchase: "); int artId = int.Parse(Console.ReadLine()); Console.WriteLine(); ASCIIArt purchase = _repo.Categories.SelectMany(c => c.ASCIIArtPieces).First(a => a.Id == artId); AddedToCart?.Invoke(this, new AddToCartEvent(purchase)); Console.WriteLine(purchase); Console.WriteLine("Has been added to your cart. Press Enter to continue shopping."); Console.ReadLine(); Console.Clear(); } else { Console.Clear(); return; } } }
public AddToCartEvent(ASCIIArt item) { Item = item; }