public void ToRemoveShop(PlazaImpl plaza) { Console.WriteLine("What is the name of the shop?"); string nameOfShop = Console.ReadLine(); plaza.RemoveShop(plaza.FindShopByName(nameOfShop)); }
public void Run() { PlazaImpl plaza = null; string firstMenu = "There are no plaza created yet! Press\n" + "1) to create a new plaza.\n" + "2) to exit.\n"; Console.Write(firstMenu); var inputFirstMenu = Console.ReadKey(true); switch (inputFirstMenu.Key) { case ConsoleKey.D1: Console.Write("Enter the name of the Plaza here: "); string plazaName = Console.ReadLine(); plaza = new PlazaImpl(plazaName); Console.Clear(); string secondMenu = $"Welcome to the {plaza.ToString()}! Press\n" + "1) to list all shops.\n" + "2) to add a new shop.\n" + "3) to remove an existing shop.\n" + "4) find a shop by name.\n" + "5) to check if the plaza is open or not.\n" + "6) to open the plaza.\n" + "7) to close the plaza.\n" + "...\n" + "N) leave plaza.\n"; while (true) { Console.Clear(); Console.Write(secondMenu); var inputSecondMenu = Console.ReadKey(true); switch (inputSecondMenu.Key) { case ConsoleKey.D1: foreach (Shop shop in plaza.GetShops()) { Console.WriteLine(shop.ToString()); } Console.ReadLine(); break; case ConsoleKey.D2: Console.Write("Enter the name of the store here: "); string storeName = Console.ReadLine(); Console.Write("Enter the name of the owner of the store here: "); string storeOwner = Console.ReadLine(); ShopImpl shopImpl = new ShopImpl(storeName, storeOwner); plaza.AddShop(shopImpl); break; case ConsoleKey.D3: Console.Write("Enter the name of the store you want to remove here: "); string storeToBeRemoved = Console.ReadLine(); plaza.RemoveShop(plaza.FindShopByName(storeToBeRemoved)); break; case ConsoleKey.D4: Console.Write("Enter the name of the store you want to go into: "); string storeToBeUsed = Console.ReadLine(); ShopImpl currentShop = (ShopImpl)plaza.FindShopByName(storeToBeUsed); string thirdMenu = "Hi! This is the {currentShop.ToString()} , welcome! Press\n" + "1) to list available products.\n" + "2) to find products by name.\n" + "3) to display the shop's owner.\n" + "4) to open the shop.\n" + "5) to close the shop.\n" + "6) to add new product to the shop.\n" + "7) to add existing products to the shop.\n" + "8) to buy a product by barcode.\n" + "9) check price by barcode.\n" + "...\n" + "N) go back to plaza.\n"; while (true) { Console.Clear(); Console.Write(thirdMenu); var inputThirdMenu = Console.ReadKey(true); switch (inputThirdMenu.Key) { case ConsoleKey.D1: foreach (Product product in currentShop.GetProducts()) { Console.WriteLine(product.ToString()); } Console.ReadLine(); break; case ConsoleKey.D2: Console.Write("Enter the name of the product you want to find"); string productToBeFound = Console.ReadLine(); currentShop.FindByName(productToBeFound); break; case ConsoleKey.D3: Console.WriteLine(currentShop.GetOwner()); Console.ReadLine(); break; case ConsoleKey.D4: currentShop.Open(); break; case ConsoleKey.D5: currentShop.Close(); break; case ConsoleKey.D6: Console.Write("What kind of product would you like to add? (clothing/food)"); string whatProductToAdd = Console.ReadLine(); if (whatProductToAdd == "clothing") { Console.Write("Enter barcode here:"); long barcodeToAddClothing = long.Parse(Console.ReadLine()); Console.Write("Enter name here:"); string nameToAddClothing = Console.ReadLine(); Console.Write("Enter manufacturer here:"); string manufacturerToAddClothing = Console.ReadLine(); Console.Write("Enter material here:"); string materialToAddClothing = Console.ReadLine(); Console.Write("Enter type here:"); string typeToAddClothing = Console.ReadLine(); Product clothingProductToAdd = new ClothingProduct(barcodeToAddClothing, nameToAddClothing, manufacturerToAddClothing, materialToAddClothing, typeToAddClothing); currentShop.AddNewProduct(clothingProductToAdd, 10, 230); break; } else if (whatProductToAdd == "food") { Console.Write("Enter barcode here:"); long barcodeToAddFood = long.Parse(Console.ReadLine()); Console.Write("Enter name here:"); string nameToAddFood = Console.ReadLine(); Console.Write("Enter manufacturer here:"); string manufacturerToAddFood = Console.ReadLine(); Console.Write("Enter calories here:"); int caloriesToAddFood = int.Parse(Console.ReadLine()); DateTime date = new DateTime(2020, 1, 1); Product foodProductToAdd = new FoodProduct(barcodeToAddFood, nameToAddFood, manufacturerToAddFood, caloriesToAddFood, date); currentShop.AddNewProduct(foodProductToAdd, 110, 2300); break; } break; case ConsoleKey.D7: Console.Write("Enter barcode here:"); int barcodeToAdd = int.Parse(Console.ReadLine()); Console.Write("Enter amount here:"); int amountToAdd = int.Parse(Console.ReadLine()); currentShop.AddProduct(barcodeToAdd, amountToAdd); break; case ConsoleKey.D8: Console.Write("Enter barcode here:"); int barcodeToBuy = int.Parse(Console.ReadLine()); Product boughtProduct = currentShop.BuyProduct(barcodeToBuy); cart.Add(boughtProduct); prices.Add(currentShop.GetPrice(barcodeToBuy)); break; case ConsoleKey.D9: Console.Write("Enter barcode here:"); int barcodeToGetThePriceOf = int.Parse(Console.ReadLine()); currentShop.GetPrice(barcodeToGetThePriceOf); break; case ConsoleKey.N: break; } } case ConsoleKey.D5: Console.WriteLine(plaza.IsOpen()); Console.ReadLine(); break; case ConsoleKey.D6: plaza.Open(); break; case ConsoleKey.D7: plaza.Close(); break; case ConsoleKey.N: Environment.Exit(0); break; default: throw new ArgumentException("Invalid input"); } } case ConsoleKey.D2: Environment.Exit(0); break; default: throw new ArgumentException("Invalid input"); } }
public void FindShopByName(PlazaImpl plaza) { Console.WriteLine("What is the name of the shop?"); string nameOfShop = Console.ReadLine(); var shop = plaza.FindShopByName(nameOfShop); if (shop.IsOpen()) { Console.WriteLine("\nname: " + shop.GetName() + ", owner: " + shop.GetOwner()); while (true) { Console.WriteLine($"Hi! This is the {nameOfShop} , welcome! Press\n" + "1) to list available products.\n" + "2) to find products and it's barcode by name.\n" + "3) to display the shop's owner.\n" + "4) to open the shop.\n" + "5) to close the shop.\n" + "6) to add new product to the shop.\n" + "7) to buy a product by barcode.\n" + "8) to add existing products to the shop.\n" + "9) check price by barcode.\n" + "10) go back to plaza."); string choice = Console.ReadLine(); if (choice.Equals("1")) { if (shop.GetProducts().Count > 0) { foreach (var item in shop.GetProducts()) { Console.WriteLine($"\t{item.GetName()} ({item.GetBarcode()})"); } } else { Console.WriteLine("Stock is EMPTY"); } } else if (choice.Equals("2")) { if (shop.GetProducts().Count > 0) { Console.WriteLine("What is the name of the product?"); string productName = Console.ReadLine(); var product = shop.FindByName(productName); if (product is ClothingProduct) { ClothingProduct cloth = (ClothingProduct)product; Console.WriteLine(cloth.GetManufacturer() + ", " + cloth.GetTypeOfCloth()); } else { FoodProduct food = (FoodProduct)product; Console.WriteLine(food.GetManufacturer() + ", " + "still consumable: " + food.isStillConsumable().ToString()); } Console.WriteLine("Barcode: " + product.GetBarcode()); } else { Console.WriteLine("Stock is EMPTY"); } } else if (choice.Equals("3")) { Console.WriteLine(shop.GetOwner()); } else if (choice.Equals("4")) { if (shop.IsOpen()) { Console.WriteLine("Shop already OPEN"); } else { shop.Open(); } } else if (choice.Equals("5")) { if (!shop.IsOpen()) { Console.WriteLine("Shop already CLOSED"); } else { shop.Close(); } } else if (choice.Equals("6")) { Console.WriteLine("What product do you want to add? Press\n" + "1) for Clothing Product\n" + "2) for Food Product"); string choiceOfProducts = Console.ReadLine(); if (choiceOfProducts.Equals("1")) { ChoseCloth(shop); } else if (choiceOfProducts.Equals("2")) { ChoseFood(shop); } } else if (choice.Equals("7")) { Console.WriteLine("Enter the barcode to buy the item!"); long barcode = long.Parse(Console.ReadLine()); this.cart.Add(shop.BuyProduct(barcode)); this.prices.Add(shop.GetPrice(barcode)); shop.GetProducts().Remove(shop.BuyProduct(barcode)); } else if (choice.Equals("8")) { Console.WriteLine("Enter the barcode!"); long barcode = long.Parse(Console.ReadLine()); Console.WriteLine("Enter the quantity!"); int quantity = int.Parse(Console.ReadLine()); shop.AddProduct(barcode, quantity); } else if (choice.Equals("9")) { Console.WriteLine("Enter the barcode to buy the item!"); long barcode = long.Parse(Console.ReadLine()); Console.WriteLine("It's: " + shop.GetPrice(barcode)); } else if (choice.Equals("10")) { break; } else { throw new Exception("There was no argument like that!"); } Console.WriteLine("\n"); } } else { throw new Exception("ShopIsClosedException"); } }