Пример #1
0
        /// <summary>
        /// Method to get user names and which menu they want
        /// </summary>
        public Customer Login(StoreRepository repo, List <StoreLocation> locations)
        {
            Customer c;
            string   firstName = "";
            string   lastName  = "";

            Console.WriteLine("\nWelcome to STREAM Game Store!");
            Console.WriteLine("------------------------------");
            Console.WriteLine("\nOPTIONS:\n(c) : Customer\n(m) : Manager\n(q) : Quit Program");
            Console.Write("Select User Type: ");
            string input = Console.ReadLine();

            if (input.Equals("c", StringComparison.InvariantCultureIgnoreCase))
            {
                //Create customer
                Console.Write("\nPlease enter your first name: ");
                firstName = Console.ReadLine();

                Console.Write("Please enter your last name: ");
                lastName = Console.ReadLine();

                //get user from db
                c = repo.GetCustomerByName(char.ToUpper(firstName[0]) + firstName.Substring(1), char.ToUpper(lastName[0]) + lastName.Substring(1));

                if (c == null)
                {
                    //new customer
                    int lastid = repo.GetLastUserId();
                    c = new Customer(lastid + 1, firstName, lastName, 1);
                }

                return(c);
            }
            else if (input.Equals("m", StringComparison.InvariantCultureIgnoreCase))
            {
                ManagerDisplay md = new ManagerDisplay();
                md.ShowManagerMenu(repo, locations);
            }
            else if (input.Equals("q", StringComparison.InvariantCultureIgnoreCase))
            {
                Environment.Exit(0);
            }
            else
            {
                Console.WriteLine("\nInvalid Input! Enter Selection Again!");
            }

            return(new Customer(1, firstName, lastName, 1));
        }
Пример #2
0
        /// <summary>
        /// Method to show manager menu options and run each option
        /// </summary>
        /// <param name="repo">The repo object to use repo methods</param>
        /// <param name="locations">a list of all the store locations from db</param>
        public void ShowManagerMenu(StoreRepository repo, List <StoreLocation> locations)
        {
            bool runMenu = true;

            while (runMenu)
            {
                //show menu options
                Console.WriteLine("\nManager Menu:");
                Console.WriteLine("1) Search Customer");
                Console.WriteLine("2) Display All Orders by Location");
                Console.WriteLine("3) Display All Orders by Customer");
                Console.WriteLine("4) Display An Orders Details");
                Console.Write("Enter a menu number or (q) to quit: ");
                string input = Console.ReadLine();

                switch (input)
                {
                case "1":
                    //Customer search
                    Console.Write("\nEnter customers first name: ");
                    string first = Console.ReadLine();
                    Console.Write("Enter customers last name: ");
                    string last = Console.ReadLine();

                    Customer cust = repo.GetCustomerByName(first, last);

                    //print customers
                    if (cust == null)
                    {
                        Console.WriteLine("Customer not found in database");
                    }
                    else
                    {
                        Console.WriteLine("\nID\tFIRST NAME\tLAST NAME\tUSER TYPE");
                        Console.WriteLine($"{cust.CustomerId}\t{cust.FirstName}\t\t{cust.LastName}\t\t{cust.UserType}");
                    }
                    break;

                case "2":     //All orders from location
                    //print locations
                    Console.WriteLine("\nLocations to search from: ");
                    foreach (var l in locations)
                    {
                        Console.WriteLine(l.StoreLocationName);
                    }

                    //get location and print out its orders
                    Console.Write("Search Location: ");
                    string locationInput = Console.ReadLine();
                    foreach (var x in locations)
                    {
                        if (locationInput.Equals(x.StoreLocationName, StringComparison.InvariantCultureIgnoreCase))
                        {
                            List <Order> orderListLocation = (List <Order>)repo.GetOrdersByLocation(x);
                            Console.WriteLine("\nID\tSTORE ID\tCUSTOMER ID\tDATETIME\t\tTOTAL");
                            foreach (var o in orderListLocation)
                            {
                                Console.WriteLine($"{o.OrderId}\t{o.OrderStoreLocationId}\t\t{o.OrderCustomerId}\t\t{o.OrderTime}\t${o.OrderTotal}");
                            }
                        }
                    }
                    break;

                case "3":     //All orders from user
                    //Customer search
                    Console.Write("\nEnter customers first name: ");
                    string firstName = Console.ReadLine();
                    Console.Write("Enter customers last name: ");
                    string   lastName = Console.ReadLine();
                    Customer c        = repo.GetCustomerByName(firstName, lastName);

                    //get customers orders and print
                    List <Order> orderListCustomer = (List <Order>)repo.GetOrdersByCustomer(c);
                    Console.WriteLine("\nID\tSTORE ID\tCUSTOMER ID\tDATETIME\t\tTOTAL");
                    foreach (var o in orderListCustomer)
                    {
                        Console.WriteLine($"{o.OrderId}\t{o.OrderStoreLocationId}\t\t{o.OrderCustomerId}\t\t{o.OrderTime}\t${o.OrderTotal}");
                    }
                    break;

                case "4":     //display order items from order number
                    //Get order products
                    Console.Write("\nEnter the order id: ");
                    string         orderId     = Console.ReadLine();
                    List <Product> productList = (List <Product>)repo.GetOrderDetails(Int32.Parse(orderId));
                    //print products
                    if (productList.Count == 0)
                    {
                        Console.WriteLine("Order could not be found.");
                    }
                    else
                    {
                        string header = string.Format("\n{0,-5} {1,-20} {2,-6} {3,-3}  {4,-6}", "ID", "NAME", "PRICE", "QTY", "TOTAL");
                        Console.WriteLine(header);
                        foreach (var p in productList)
                        {
                            string output = string.Format("{0,-5} {1,-20} ${2,-6} {3,-3} ${4,-6}", p.ProductId, p.ProductName, p.ProductPrice, p.ProductQty, p.ProductPrice * p.ProductQty);
                            Console.WriteLine(output);
                        }
                    }
                    break;

                case "q":
                    runMenu = false;
                    break;

                default:
                    Console.WriteLine("\nPlease enter a number 1-4 for which menu option you want or (q) to quit.");
                    break;
                }
            }
        }