예제 #1
0
        static void UserView()
        {
            PrintMessage("Welcome to PizzaWorld!");

            PrintMessage("What are you?");
            DisplayOptions(new string[] {
                "a) Customer",
                "b) Store"
            });
            string identityInput = Console.ReadLine();

            if (identityInput == "a") // Customer
            {
                PrintMessage("Please sign in or create an account:");
                DisplayOptions(new string[] {
                    "a) Sign In",
                    "b) Create Account"
                });

                string accountInput = Console.ReadLine();

                User   user          = null;
                string usernameInput = "";
                string passwordInput = "";

                if (accountInput == "a")
                {
                    do
                    {
                        PrintMessage("Enter Username");
                        usernameInput = Console.ReadLine();

                        PrintMessage("Enter Password");
                        passwordInput = Console.ReadLine();

                        user = _sql.GetUserIfCredentialsAreValid(usernameInput, passwordInput);

                        if (user == null)
                        {
                            PrintMessage("Your credentials were incorrect. Please try again");
                        }
                    } while (user == null);
                }
                else if (accountInput == "b")
                {
                    bool AlreadyExists = false;
                    do
                    {
                        PrintMessage("Select Username");
                        usernameInput = Console.ReadLine();

                        AlreadyExists = _sql.CheckIfUsernameExists(usernameInput);

                        if (AlreadyExists)
                        {
                            PrintMessage("Your chosen username has been taken. Please try another one");
                        }
                    } while (AlreadyExists);

                    PrintMessage("Select Password");
                    passwordInput = Console.ReadLine();

                    user = new User(usernameInput, passwordInput);
                    _sql.SaveUser(user);
                }

                PrintAllStoresWithEF();

                user.SelectedStore = _sql.SelectStore();

                _sql.Update(user.SelectedStore); // this line is just in case the user cancels their order

                CreateAndProcessOrder(user);
            }
            else if (identityInput == "b") // Store
            {
                PrintAllStoresWithEF();

                var SelectedStore = _sql.SelectStore();

                string storeActionInput = "";

                do
                {
                    PrintMessage("What would you like to do next?");
                    DisplayOptions(new string[] {
                        "a) Show Order History",
                        "b) Show Sales History",
                        "c) Exit"
                    });
                    storeActionInput = Console.ReadLine();

                    switch (storeActionInput)
                    {
                    case "a":
                        _sql.DisplayStoreOrderHistory(SelectedStore);
                        break;

                    case "b":
                        _sql.DisplayStoreSales(SelectedStore);
                        break;

                    case "c":
                        PrintMessage("Thank you. Come again!");
                        break;

                    default:
                        break;
                    }
                } while (storeActionInput != "c");
            }
        }