public static void Display(ProductsBuilder pb, Products allProducts) { WriteLineColored("\t\t\t === Vending Machine ===", ConsoleColor.Blue); Console.WriteLine(allProducts); Console.WriteLine("1. Fill machine"); Console.WriteLine("2. Show products"); Console.WriteLine("3. Purchase product"); Console.WriteLine("4. Exit and return money\n"); Console.Write("Introduce money : "); string money = Console.ReadLine(); Console.Write("Option: "); string option = Console.ReadLine(); switch (option) { case "1": allProducts = pb.FillMachine(); break; case "2": Console.WriteLine(allProducts); break; case "3": WriteLineColored("Product index: ", ConsoleColor.Black); string index = Console.ReadLine(); WriteLineColored("Product quantity: ", ConsoleColor.Black); string quantity = Console.ReadLine(); // select an id and quantity after that will actualized stock ProductPurchase(allProducts, Int32.Parse(money), Int32.Parse(index), Int32.Parse(quantity)); Console.WriteLine(allProducts); break; case "4": WriteLineColored("Refund money " + money + "$\n", ConsoleColor.Green); Environment.Exit(0); break; default: WriteLineColored("Invalid option !!!", ConsoleColor.Red); break; } }
public static void Main(string[] args) { ProductsBuilder pb = new ProductsBuilder(); Products allProducts = pb.FillMachine(); bool continueOperation = true; while (continueOperation) { Menu.Display(pb, allProducts); Menu.WriteLineColored("You want still buy ? [Y/N]", ConsoleColor.Cyan); string inputUser = Console.ReadLine(); if (!inputUser.Equals("Y")) { continueOperation = false; } } }