コード例 #1
0
        // View the Shop
        public static void SortTheShop(ShopStorage shop)
        {
            string line;
            int    input;

            do
            {
                Console.WriteLine("Main Menu > View the Shop > "
                                  + "\n1. Sort the Shop by name"
                                  + "\n2. Sort the Shop by price"
                                  + "\n3. Sort the Shop by price and name"
                                  + "\n4. Sort the Shop by price, grouped by category"
                                  + "\n0. Return"
                                  );
                // Make sure that the user entered a valid input
                while (!int.TryParse(line = Console.ReadLine().ToString(), out input))
                {
                    Console.WriteLine($"Invalid input, you entered {line}! Please read and follow the instructions.");
                }

                switch (input)
                {
                case 0:
                    Console.WriteLine();
                    return;

                case 1:
                    Console.WriteLine("\nView the Shop sorted by name:");
                    shop.SortByName();
                    foreach (var item in shop.GetAllItems())
                    {
                        Console.WriteLine(item.ToString());
                    }
                    Console.WriteLine();
                    return;

                case 2:
                    Console.WriteLine("\nView the Shop sorted by price:");
                    shop.SortByPrice();
                    foreach (var item in shop.GetAllItems())
                    {
                        Console.WriteLine(item.ToString());
                    }
                    Console.WriteLine();
                    return;

                case 3:
                    Console.WriteLine("\nView the Shop sorted by price and name:");
                    shop.SortByPriceAndName();
                    foreach (var item in shop.GetAllItems())
                    {
                        Console.WriteLine(item.ToString());
                    }
                    Console.WriteLine();
                    return;

                case 4:
                    Console.WriteLine("\nView the Shop sorted by price, grouped by category:");
                    shop.SortByPriceAndGroupByCategory();
                    foreach (var item in shop.GetAllItems())
                    {
                        Console.WriteLine(item.ToString());
                    }
                    Console.WriteLine();
                    return;

                default:
                    Console.WriteLine($"Invalid input, you entered {input}! Please read and follow the instructions.");
                    break;
                }
            }while (true);
        }