コード例 #1
0
ファイル: Program.cs プロジェクト: elmertsai/project-p0
        static void StoreView()
        {
            bool done  = false;
            var  input = 0;

            PrintAllStoresWithEF();
            System.Console.WriteLine("Please select a store");
            Store s = SelectStore();
            User  u = new User();

            System.Console.WriteLine("Name of selected store:  " + s.Name);
            while (!done)
            {
                Console.WriteLine("Please select one of the actions");
                Console.WriteLine("1) Check store order history");
                Console.WriteLine("2) Check order history of a user");
                Console.WriteLine("3) Exist Program");
                int.TryParse(Console.ReadLine(), out input);

                if (input == 1)
                {
                    if (s.Orders.Count == 0)
                    {
                        Console.WriteLine("There are no orders in this store");
                    }
                    else if (s.Orders == null)
                    {
                        Console.WriteLine("Order is null, check method");
                    }
                    else
                    {
                        Console.WriteLine("Checking order history...");
                        List <Order> orderhistory = new List <Order>();
                        orderhistory = _sql.OrderHistoryByStore(s).ToList();
                        Console.WriteLine("There are: " + orderhistory.Count + " order(s) for this store");

                        // Console.WriteLine(String.Format("{0,-20} {1,-20} {2,-20} {3,-20}\n\n",
                        //                             "Order ID","User Name","Order Time","Order Price"));
                        // Console.WriteLine("DEBUG: "+s.Orders);

                        Console.WriteLine(String.Format("{0,-25} {1,-25} {2,-25} {3,-25} {4,-25}\n", "Order ID", "Store Name", "User Name", "price", "date"));
                        foreach (var order in orderhistory)
                        {
                            Console.WriteLine(String.Format("{0,-25} {1,-25} {2,-25} {3,-25} {4,-25}\n", order.EntityID, order.Store.Name, order.User.Name, order.price, order.Ordertime));
                        }
                    }
                }
                else if (input == 2)
                {
                    Console.WriteLine("Selecting user...\n\n");
                    PrintAllUsers();
                    u = SelectUser();
                    if (u.Orders.Intersect(s.Orders).Any() == false)
                    {
                        Console.WriteLine("User not found within this store\n");
                    }
                    else
                    {
                        List <Order> orders = _sql.OrderHistoryByUser(u).Where(o => o.Store.Name == s.Name).ToList();
                        Console.WriteLine("User: "******" has " + orders.Count + " orders");
                        Console.WriteLine("The las order price was " + orders.Last().price);
                        Console.WriteLine(String.Format("{0,-25} {1,-25} {2,-25} {3,-25} {4,-25}\n", "Order ID", "Store Name", "User Name", "price", "date"));
                        foreach (var order in orders)
                        {
                            Console.WriteLine(String.Format("{0,-25} {1,-25} {2,-25} {3,-25} {4,-25}\n", order.EntityID, order.Store.Name, order.User.Name, order.price, order.Ordertime));
                        }
                    }
                }
                else if (input == 3)
                {
                    done = true;
                    Console.WriteLine("Exiting program...");
                }
                else
                {
                    Console.WriteLine("Please enter a valid option");
                }
            }
        }