Пример #1
0
        private static void DisplayOrders(IList <Orders> orders, PizzaRepository repo)
        {
            int orderDisplay = 1;

            while (orderDisplay == 1)
            {
                Console.WriteLine("| ID | User | Location | Date/Time | Total  | Items |");
                Console.WriteLine("-------------------------------------------------------");

                foreach (var item in orders)
                {
                    Console.WriteLine($"| {item.OId} | {item.OrderFor} | {item.OrderedFrom} | {item.OrderedAt} | {item.TotalPrice} | {item.NumOfOrderedItems} |");
                }

                Console.WriteLine("-------------------------------------------------------");
                Console.WriteLine();

                Console.WriteLine("1) Display details of an order");
                Console.WriteLine();
                Console.WriteLine("2) Return to previous menu");
                Console.WriteLine();

                var input = Console.ReadLine();

                switch (input)
                {
                case "1":
                    Console.WriteLine();
                    Console.WriteLine("- - - - - - - - - - ");
                    Console.WriteLine("Enter the ID of the order to display details");
                    Console.WriteLine();

                    input = Console.ReadLine();

                    int selectedId = -1;

                    bool inputIsInt = Int32.TryParse(input, out selectedId);
                    bool validId    = false;

                    foreach (var item in orders)
                    {
                        if (item.OId == selectedId)
                        {
                            validId = true;
                        }
                    }

                    // Check that input is a number
                    if (!inputIsInt)
                    {
                        Console.WriteLine("Please enter the ID of an order from the list");
                    }
                    else if (!validId)
                    {
                        Console.WriteLine("Order could not be found");
                    }
                    // Number is valid, get order
                    else
                    {
                        var orderDetails = repo.GetOrderById(selectedId);

                        Console.WriteLine();
                        Console.WriteLine("- - - - - - - - - - ");
                        Console.WriteLine($"Showing details for Order {orderDetails.OId}:");
                        Console.WriteLine("| Order | Pizza | Price | Quantity |");
                        Console.WriteLine("-------------------------------------------------------");

                        foreach (var item in repo.ShowOrderDetails(orderDetails))
                        {
                            Console.WriteLine($"| {item.OnOrder} | {item.PizzaNavigation.Name} | ${item.PizzaNavigation.Price} |  {item.Quantity} |");
                        }

                        Console.WriteLine("-------------------------------------------------------");
                        Console.WriteLine();

                        Console.WriteLine("[Press any key to return]");
                        Console.WriteLine();

                        Console.ReadLine();
                    }
                    break;

                case "2":
                    orderDisplay = 0;
                    break;

                default:
                    Console.WriteLine();
                    Console.WriteLine("Command not recognized");
                    Console.WriteLine();
                    break;
                }
            }
        }