示例#1
0
 public string PlazaMenu(IPlaza plaza)
 {
     Console.WriteLine($"Welcome to the {plaza.GetName()} plaza! Press\n" +
                       $"1) to list all shops\n" +
                       $"2) to add a new shop\n" +
                       $"3) to remove an existing shop\n" +
                       $"4) enter a shop by name\n" +
                       $"5) to open the plaza\n" +
                       $"6) to close the plaza\n" +
                       $"7) to check if the plaza is open or not\n" +
                       $"8) list items in the cart\n" +
                       $"9) leave plaza");
     return(Console.ReadLine());
 }
示例#2
0
        public void PlazaMenuLogic(IPlaza plaza, string option)
        {
            switch (option)
            {
            case "1":
                Console.Clear();
                try
                {
                    if (plaza.GetShops().Count > 0)
                    {
                        foreach (var shop in plaza.GetShops())
                        {
                            Console.WriteLine(shop.GetName());
                        }
                    }
                    else
                    {
                        Console.WriteLine("There are no shops yet");
                    }
                }
                catch (PlazaIsClosedException)
                {
                    Console.WriteLine("Open the plaza first!");;
                }
                break;

            case "2":
                Console.Clear();
                try
                {
                    Console.WriteLine("What is the name of the shop?");
                    var shopName = Console.ReadLine();
                    Console.WriteLine("Who is the owner of the shop?");
                    var shopOwner = Console.ReadLine();
                    plaza.AddShop(new ShopImpl(shopName, shopOwner));
                }
                catch (PlazaIsClosedException)
                {
                    Console.WriteLine("Open the plaza first!");;
                }
                catch (ShopAlreadyExistsException)
                {
                    Console.WriteLine("This shop already exists!");;
                }
                break;

            case "3":
                Console.Clear();
                try
                {
                    Console.WriteLine("Which shop you want to remove?");
                    var shopToRemove = Console.ReadLine();
                    plaza.RemoveShop(plaza.FindShopByName(shopToRemove));
                    Console.WriteLine($"{shopToRemove} is not in our plaza anymore.");
                }
                catch (NoSuchShopException)
                {
                    Console.WriteLine("Invalid shop name!");
                }
                catch (PlazaIsClosedException)
                {
                    Console.WriteLine("Open the plaza first" !);
                }
                break;

            case "4":
                Console.Clear();
                try
                {
                    inAShop = true;
                    Console.WriteLine("Which shop you looking for?");
                    var shopToEnter = Console.ReadLine();
                    while (inAShop)
                    {
                        ShopMenuLogic(plaza.FindShopByName(shopToEnter), ShopMenu(plaza.FindShopByName(shopToEnter)));
                    }
                }
                catch (PlazaIsClosedException)
                {
                    Console.WriteLine("Open the plaza first" !);
                }
                catch (NoSuchShopException)
                {
                    Console.WriteLine("Invalid shop name!");
                }
                break;

            case "5":
                Console.Clear();
                plaza.Open();
                break;

            case "6":
                Console.Clear();
                plaza.Close();
                break;

            case "7":
                Console.Clear();
                if (plaza.IsOpen())
                {
                    Console.WriteLine($"{plaza.GetName()} is open.");
                }
                else
                {
                    Console.WriteLine($"{plaza.GetName()} is closed.");
                }
                break;

            case "8":
                Console.Clear();
                if (plaza.IsOpen())
                {
                    if (Cart.Count > 0)
                    {
                        for (int i = 0; i < Cart.Count; i++)
                        {
                            Console.WriteLine($"Item: {Cart[i]} Price: {Prices[i]} HUF");
                        }
                    }
                    else
                    {
                        Console.WriteLine("There is nothing in the cart yet");
                    }
                }
                else
                {
                    Console.WriteLine("Open the plaza first!");
                }
                break;

            case "9":
                System.Environment.Exit(1);
                break;

            default:
                Console.WriteLine("Invalid input");
                Thread.Sleep(500);
                Console.Clear();
                break;
            }
        }