Example #1
0
        public void Test_RepositoryGetPizzaByNumMenu(int i)
        {
            var actual = sut.GetPizzaByNumMenu(i);

            Assert.IsType <Pizza>(actual);
        }
Example #2
0
        public static List <Pizza> PreOrder(User user, Store store)
        {
            List <Pizza>           list           = new List <Pizza>();
            List <StorePizza>      listStorePizza = _spr.GetPizzasInStore(store);
            Dictionary <long, int> dict           = new Dictionary <long, int>();

            foreach (var p in listStorePizza)
            {
                dict.Add(p.PizzaId, p.Inventory);
            }
            decimal maxTotal       = 250M;        // *** MAXTOTAL = 250
            int     maxTotalAmount = 10;          // *** MAXTOTALAMOUNT = 50
            decimal tempPrice;
            int     tempAmount = 0;
            bool    check      = true;


            while (check)
            {
                if (tempAmount == maxTotalAmount)
                {
                    Console.WriteLine($"You can't add more pizzas, you have reached the maximum n° of pizzas for an order, which is {maxTotalAmount}");
                    Console.WriteLine("");
                }
                else
                {
                    _pr.ShowMenu(dict);
                    Console.WriteLine("");
                    int selection_pizza = SelectPizza(dict);

                    Pizza pizza = _pr.GetPizzaByNumMenu(selection_pizza);
                    tempPrice  = list.Sum(l => l.Price);
                    tempAmount = list.Count();
                    if (tempPrice + pizza.Price > maxTotal)
                    {
                        Console.WriteLine($"You can't add this pizza, the total would go over ${maxTotal}");
                        Console.WriteLine("");
                    }
                    else if (tempAmount < maxTotalAmount && (tempPrice + pizza.Price) <= maxTotal)
                    {
                        list.Add(pizza);
                        tempAmount = list.Count();
                        dict[pizza.PizzaId]--;

                        PrintPartialOrder(list);
                    }
                }
                if (tempAmount <= maxTotalAmount)
                {
menuPizza:
                    Console.WriteLine("-----------------------------");
                    Console.WriteLine("");
                    Console.WriteLine("Press 1: ADD A PIZZA");
                    Console.WriteLine("Press 2: REMOVE LAST PIZZA ADDED");
                    Console.WriteLine("Press 3: MY ORDER IS READY");
                    Console.WriteLine("");
                    Console.Write("Enter your option's number: ");
                    string addPizza = Console.ReadLine();
                    Console.WriteLine("");
                    bool check2 = addPizza == "1" || addPizza == "2" || addPizza == "3";
                    while (!check2)
                    {
                        Console.Write("The option you selected is not valid, please try again: ");
                        addPizza = Console.ReadLine();
                        Console.WriteLine("");
                        check2 = addPizza == "1" || addPizza == "2" || addPizza == "3";
                    }
                    if (addPizza == "1")
                    {
                        check = true;
                    }
                    else if (addPizza == "2")
                    {
                        list       = RemovePizza(list, dict);
                        tempAmount = list.Count();
                        PrintPartialOrder(list);
                        goto menuPizza;
                    }
                    else if (addPizza == "3")
                    {
                        CheckOut(list, user);
                        check = false;
                    }
                }
            }
            return(list);
        }