예제 #1
0
        private static void MakeOrder(User user)
        {
            var       order         = new Order();
            bool      continueInput = user.AddOrder(order);
            PizzaMenu state         = PizzaMenu.SelectPizza;
            Pizza     pizza         = null;

            if (!continueInput)
            {
                Console.WriteLine("Sorry, you cannot make another order within a 2 hour period.");
            }
            while (continueInput)
            {
                if (order.Pizzas.Count() >= 50)
                {
                    state = PizzaMenu.Finish;
                    Console.WriteLine("You have 50 pizzas, completing order.");
                }
                switch (state)
                {
                case (PizzaMenu.SelectPizza):
                    pizza = SelectPizza();
                    state = PizzaMenu.SelectSize;
                    break;

                case (PizzaMenu.SelectSize):
                    List <Size> sizes      = _sql.ReadSizes().ToList();
                    var         sizeString = _sql.SelectAPizzaPart <Size>(sizes,
                                                                          "Select a size: ");
                    pizza.Size = sizes.ElementAtOrDefault <Size>(sizeString);
                    state      = PizzaMenu.SelectCrust;
                    break;

                case (PizzaMenu.SelectCrust):
                    List <Crust> crusts      = _sql.ReadCrusts().ToList();
                    var          crustString = _sql.SelectAPizzaPart <Crust>(_sql.ReadCrusts().ToList(),
                                                                             "Select a crust: ");
                    pizza.Crust = crusts.ElementAtOrDefault <Crust>(crustString);
                    bool addTopping = ConfirmationInput("Would you like to add toppings?");
                    if (addTopping)
                    {
                        state      = PizzaMenu.AddTopping;
                        pizza.Name = "custom";
                    }
                    else
                    {
                        state = PizzaMenu.CheckOrder;
                    }
                    break;

                case (PizzaMenu.AddTopping):
                    AddToppings(pizza);
                    state = PizzaMenu.CheckOrder;
                    break;

                case (PizzaMenu.CheckOrder):
                    bool canAddPizza = order.AddPizza(pizza);
                    if (!canAddPizza)
                    {
                        Console.WriteLine("Sorry, your order would put you over the limit of $250.");
                        Console.WriteLine("Either complete your order or add another pizza.");
                    }
                    Console.WriteLine($"Your current total is: ${order.GetTotalAmount()} with {order.Pizzas.Count()} pizza(s).");
                    bool confirmation = ConfirmationInput("Would you like to add another pizza?");
                    if (confirmation)
                    {
                        state = PizzaMenu.SelectPizza;
                    }
                    else
                    {
                        state = PizzaMenu.RemovePizzas;
                        Console.WriteLine("We have completed your order. Thank you for your time.");
                    }
                    break;

                case PizzaMenu.RemovePizzas:
                    bool removeConfirm = ConfirmationInput("Would you like to remove any pizzas?");
                    if (removeConfirm)
                    {
                        RemovePizzas(order);
                    }
                    state = PizzaMenu.Finish;
                    break;

                default:
                    Console.WriteLine($"Your total is: ${order.GetTotalAmount()} with {order.Pizzas.Count()} pizza(s).");
                    continueInput = false;
                    user.SelectedStore.Orders.Add(order);
                    _sql.SaveChanges();
                    break;
                }
            }
        }