Example #1
0
        public bool AddIngredient(int id)
        {
            var topping = Toppings.GetToppingById(id);

            if (topping == null)
            {
                return(false);
            }
            Ingredients.Add(topping);
            CalculatePrice();
            return(true);
        }
Example #2
0
        public static void GetPizzaMenu()
        {
            int pizzaId = 0;

            while (pizzaId < 1)
            {
                Console.Clear();
                Console.WriteLine("Please select a pizza");
                PizzaMenu.PrintInMenu();
                Console.Write(">");

                var userInput = Console.ReadLine();

                if (!int.TryParse(userInput, out pizzaId) || !PizzaMenu.PizzaInMenu(pizzaId))
                {
                    Console.WriteLine("User input was not correct.");
                    Console.ReadKey();
                    continue;
                }

                var pizza = PizzaMenu.GetPizza(pizzaId);

                do
                {
                    Console.Clear();
                    Console.WriteLine("Choose a pizza dough (thin or thick)");
                    userInput = Console.ReadLine().ToLower();
                } while (userInput != "thin" && userInput != "thick");

                if (userInput == "thin")
                {
                    pizza.IsThin = true;
                }
                else
                {
                    pizza.IsThin = false;
                }

                userInput = "";
                do
                {
                    Console.Clear();
                    Console.WriteLine($"Pizza: {pizza}");
                    Console.WriteLine("Select additional toppings. Insert empty line if you want to add pizza to shopping cart.");
                    Toppings.PrintToppings();
                    Console.Write(">");
                    userInput = Console.ReadLine();
                    if (userInput == "")
                    {
                        break;
                    }

                    if (!int.TryParse(userInput, out var toppingId) || Toppings.GetToppingById(toppingId) == null)
                    {
                        Console.WriteLine("User input is not correct");
                        Console.ReadKey();
                        continue;
                    }

                    pizza.AddIngredient(toppingId);
                    Console.WriteLine("Topping added");
                    Console.ReadKey();
                } while (userInput != "");

                _cart.AddPizza(pizza);
            }

            Console.WriteLine("Pizza added to cart");
            Console.ReadLine();
        }