Exemple #1
0
        public void AddItemToMenuShop()
        {
            string name = string.Empty;
            double price;
            string unit;
            bool   checkInput = false;
            int    yourChoice = -1;

            do
            {
                Console.Write("Please enter name of item: ");
                name = ValidDataServices.FormatName(Console.ReadLine());
            } while (name == "");

            if (!IsItemExists(name))
            {
                do
                {
                    Console.Write("Please enter item's price: ");
                    checkInput = ConvertServices.ToDoubleByTryParse(Console.ReadLine(), out price);
                } while (!checkInput || price <= 0);
                do
                {
                    Console.Write("Please enter unit type of item: ");
                    unit       = Console.ReadLine().Trim();
                    checkInput = ConvertServices.ToIntByTryParse(unit, out int temp);
                } while (unit == "" || checkInput);
                switch (yourChoice)
                {
                case 1:
                    Drink newDrink = new Drink(nameInput: name, priceInput: price, unitInput: unit);
                    _menu.ListDrinksOfShop.Add(newDrink);
                    Console.WriteLine("Your drink item has add to Drinks Menu");
                    break;

                case 2:
                    Food newFood = new Food(nameInput: name, priceInput: price, unitInput: unit);
                    _menu.ListFoodsOfShop.Add(newFood);
                    Console.WriteLine("Your food item has add to Foods Menu");
                    break;
                }
                FileJsonServices.WriteFileJson(_shopUseServices, FilePath.StrDataFileFullPath);
            }
            else
            {
                Console.WriteLine($"Shop have item with name {name}, please change another name");
            }
        }