Exemple #1
0
        static void MakeNewUser()
        {
            var user = new User();

            Console.WriteLine("Enter username for new user");
            user.Name = Console.ReadLine();
            _sql.SaveUser(user);
        }
Exemple #2
0
        private static User CreateUser()
        {
            Console.WriteLine("Please enter your name: ");
            var  name = Console.ReadLine();
            User user = _sql.ReadOneUser(name.Trim());

            if (user == null)
            {
                user      = new User();
                user.Name = name.Trim();
                _sql.SaveUser(user);
            }
            Console.WriteLine(user);
            return(user);
        }
Exemple #3
0
        static void UserView()
        {
            // List<User> users = sqlclient.FetchUsers();

            // for (int i = 0; i < users.Count; i++)
            // {
            //     Console.WriteLine("Order Count: " + users[i].Orders.Count);
            // }


            var user = new User();

            PrintAllStores();


            user.SelectedStore = sqlclient.FetchStore(Console.ReadLine());
            //intstantiate new obj of type Order


            //adding order to user
            user.Orders.Add(new Order());
            // calling last order added and adding to order
            AddToOrder(user.Orders.Last());
            Console.WriteLine(user.Orders.Count);

            // sqlclient.SaveUser(user);

            // for while loop for
            Console.WriteLine("Your current order: ");
            for (int i = 0; i < user.Orders.Count; i++)
            {
                Console.WriteLine(user.Orders[i]);
            }
            ;

            Console.WriteLine("Press 'A' to add Pizzas, 'R' to remove Pizzas or 'Enter' to finish order");
            string response = Console.ReadLine();

            while (response != "")
            {
                if (response == "A")
                {
                    AddToOrder(user.Orders.Last());
                    Console.WriteLine(user.Orders.Count);
                }
                if (response == "R")
                {
                    int NumOrders = user.Orders.Last().Pizzas.Count() - 1;
                    Console.WriteLine("Please enter index to remove (a number between 0 and " + NumOrders.ToString() + ")");
                    // Console.WriteLine("Please enter index to remove starting at 0");
                    response = Console.ReadLine();
                    int index = Convert.ToInt16(response);
                    RemovePizza(user, index);
                }
                Console.WriteLine("Press 'A' to add Pizzas, 'R' to remove Pizzas or 'Enter' to finish order");
                response = Console.ReadLine();
            }

            Console.WriteLine("Your current order: ");


            //  sqlclient.SaveOrder(user.Orders.Last());

            // establishing ability to read and write to DB
            sqlclient.SaveUser(user);

            for (int i = 0; i < user.Orders.Count; i++)
            {
                Console.WriteLine(user.Orders[i]);
            }
            ;

            // print out all orders
            // Console.WriteLine(users.Last().Orders.Last());



            // user.SelectedStore = _client.SelectStore();
            // user.SelectedStore.CreateOrder();
            // user.Orders.Add(user.SelectedStore.Orders.Last());
            // // while user.SelectPizza()
            // user.Orders.Last().MakeMeatPizza();
            // user.Orders.Last().MakeVeggiePizza();

            System.Console.WriteLine(user);
        }
Exemple #4
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");
            }
        }