Ejemplo n.º 1
0
        static void MakeOrder(OrderController orderController, Storage storage)
        {
            bool finished = false;

            while (!finished)
            {
                Console.Clear();
                PrintBasket(orderController.CurrentBasket);
                Console.WriteLine($"1) Add more items.");
                Console.WriteLine($"2) Send order.");
                Console.WriteLine($"3) Exit from basket.");
                ChooseLimits(1, 3, "Your choose: ", out int choose);
                Console.WriteLine();
                try
                {
                    switch (choose)
                    {
                    case (1):
                        bool chosen = false;
                        while (!chosen)
                        {
                            try
                            {
                                var quantity = Enum.GetNames(typeof(Items)).Length;
                                Console.Clear();
                                Console.WriteLine("What type of product you want?");
                                if (orderController.CurrentOrder.CurrentUser.Age > 18)
                                {
                                    foreach (var item in (Items[])Enum.GetValues(typeof(Items)))
                                    {
                                        Console.WriteLine((int)item + ") " + item);
                                    }
                                }
                                else
                                {
                                    foreach (var item in (Items[])Enum.GetValues(typeof(Items)))
                                    {
                                        if (item != Items.Wine)
                                        {
                                            Console.WriteLine(((int)item - 1) + ") " + item);
                                        }
                                    }
                                }
                                ChooseLimits(1, quantity, "Your chosen item: ", out int good);
                                if (orderController.CurrentOrder.CurrentUser.Age < 18)
                                {
                                    good++;
                                }
                                PrintBrands(GoodsController.GetBrands((Items)good));
                                ChooseLimits(1, GoodsController.GetAmount((Items)good), "Choose what you want: ", out int brand);
                                ChooseLimits(1, 100, "Type amount (less than 100): ", out int amount);
                                orderController.Add(GoodsController.CreateItem((Items)good, GetBrand((Items)good, brand)), amount);
                                chosen = true;
                            }
                            catch (TypeInitializationException ex)
                            {
                                Console.WriteLine(ex.InnerException);
                            }
                            catch (Exception ex)
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine(ex.Message);
                                Console.ResetColor();
                                Console.Write("Type any key to continue...");
                                Console.ReadKey();
                            }
                        }
                        break;

                    case (2):
                        orderController.FinishOrder();
                        if (storage.MakeOrder(orderController.CurrentOrder))
                        {
                            Console.WriteLine("Your order is completed!");
                        }
                        else
                        {
                            Console.WriteLine("You was added to the queue. Come back next day.");
                            Console.WriteLine($"You are on {storage.GetQueuePosition(orderController.CurrentOrder.CurrentUser)} position in queue.");
                        }
                        orderController.CheckCurrentOrder();

                        finished = true;
                        break;

                    default:
                        finished = true;
                        break;
                    }
                }
                catch (Exception ex)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(ex.Message);
                    Console.ResetColor();
                }
            }
        }