Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            // Perhaps I should tidy this up a little, or maybe just move this to a class of its own?
            // Maybe some other time...
            int    input;
            string line;
            bool   print = true;

            var shop = new ShopStorage();
            var cart = new ShoppingCart();

            do
            {
                if (shop.Count <= 0)
                {
                    Console.WriteLine("The shop is empty!\n");
                }

                if (print)
                {
                    Console.WriteLine("\nItems in the Shop:");
                    foreach (var item in shop.GetAllItems())
                    {
                        Console.WriteLine(item.ToString());
                    }
                    Console.WriteLine();
                }
                else
                {
                    print = true;
                }

                Console.WriteLine("Main Menu > "
                                  + "\n1. Add an Item to the Shopping Cart"
                                  + "\n2. Manage the Shopping Cart"
                                  + "\n3. Sort the Shop"
                                  + "\n4. Search the Shop"
                                  + "\n0. Exit"
                                  );
                // 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($"You entered {input}! Exiting the application.");
                    break;

                case 1:
                    print = AddItemToShoppingCart(shop, cart);
                    break;

                case 2:
                    print = ManageTheShoppingCart(cart);
                    break;

                case 3:
                    SortTheShop(shop);
                    break;

                case 4:
                    SearchTheShop(shop);
                    break;

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

            Console.WriteLine("Press any key to continue...");
            Console.ReadKey();
        }