Example #1
0
        /// <summary>
        /// Will add to respective store given storeId and user
        /// </summary>
        /// <param name="ChooseProduct("></param>
        /// <returns> string PossiblyFoundProduct, int statusCode </returns>
        public (string, int) ChooseProduct()
        {
            StoreAppDBContext       dbContext    = new StoreAppDBContext();
            StoreAppRepositoryLayer storeContext = new StoreAppRepositoryLayer(dbContext);

            while (true)
            {
                Console.Write("Please type in the product name (or 'checkout' or 'quit'): ");//\n\tNOTICE:\n\t\t1. Typing 'quit' will log you out and nothing will be check out\n\t\t2. Typing 'checkout' will display your cart."); //permanently charge your account and the items will ship soon.");
                string productName = Console.ReadLine();
                if (productName == "quit")
                {
                    return(productName, -1);
                }
                else if (productName == "checkout")
                {
                    return(productName, 0);
                }

                int status = storeContext.CheckProduct(productName);

                if (status == -1)
                {
                    Console.WriteLine("Could not find that product. Please try again.");
                }

                else
                {
                    Console.Write("How many: ");
                    int quantityDesired = Int32.Parse(Console.ReadLine());
                    return(productName, quantityDesired);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Handles input from the inital menu header to see where the user wants to navigate to.
        /// </summary>
        /// <param name="GetOption("></param>
        /// <returns>(int statusCode, string userName)</returns>
        public (int, string) GetOption()
        {
            StoreAppDBContext       dbContext    = new StoreAppDBContext();
            StoreAppRepositoryLayer storeContext = new StoreAppRepositoryLayer(dbContext);
            string option = Console.ReadLine();

            //int value = VerifyOptions(option);
            if (option == "1") //log in
            {
                Console.Write("What is your username: "******"2")            //create account
            {
                string fName, lName, userName; //, userId;
                //needs to be all lowercase and letters only for
                //all entries
                Console.Write("First Name: ");
                fName = Console.ReadLine();
                Console.Write("Last Name: ");
                lName = Console.ReadLine();
                do
                {
                    Console.Write("Username (letters only): ");
                    userName = Console.ReadLine();
                    Console.WriteLine("ONLY USE LETTERS");
                }while(!Regex.IsMatch(userName, @"^[a-zA-Z]+$"));

                int statusCode = storeContext.CreateCustomer(fName, lName, userName);//,userId);
                return(statusCode, userName);
            }
            else if (option == "3") //looking up order history
            {
                Console.Write("Please enter the username: "******"\t 1. Hollywood, CA \n\t 2. Berkeley, CA \n\t 3. San Francisco, CA\n\t 4. All Stores");
                Console.Write("What store ID: ");
                string storeId = Console.ReadLine();
                return(3, userName + '_' + storeId);
            }
            else if (option == "4") //quit
            {
                Console.WriteLine("Thanks for choosing NotAmoeba!");
                return(4, null);
            }
            else
            {
                Console.WriteLine("Please input something valid!");
                return(-1, null);
            }
        }
Example #3
0
        public static void Main(string[] args)
        {
            Control                 c            = new Control();
            StoreAppDBContext       dbContext    = new StoreAppDBContext();
            StoreAppRepositoryLayer storeContext = new StoreAppRepositoryLayer(dbContext);
            int storeId;

            while (true)
            {
                c.MenuSplash();
                (int option, string userName) = c.GetOption();
                if (option == -1)  //general error
                {
                    continue;
                }
                else if (option == 3) //getting order history
                {
                    string[] response = userName.Split('_');
                    userName = response[0];
                    storeId  = Int32.Parse(response[1]);
                    storeContext.GetOrderHistory(userName, storeId);
                }
                else if (option == 4)
                {
                    break;       //quitting
                }
                if (option == 0) //good
                {
                    //SAVE LOCAL LIST HERE OF ALL ORDERED PRODUCTS
                    while (true)
                    {
                        //originally here
                        int status = c.ChooseStore();
                        //
                        if (status == -1 || status == 0)
                        {
                            break;
                        }
                        else
                        {
                            Dictionary <string, int> currentOrder = new Dictionary <string, int>();
                            while (true)
                            {
                                storeContext.ShowInventory(status, currentOrder);
                                storeId = status; //store the storeID locally for now

                                (string productName, int quantity) = c.ChooseProduct();

                                if (productName == "quit")
                                {
                                    break;                        //change of store, drop everthing
                                }
                                else if (productName == "checkout")
                                {
                                    storeContext.CheckoutCart(userName, storeId, currentOrder);
                                    currentOrder.Clear(); //clears current order when finished checking out
                                    break;
                                }
                                else //still deciding
                                {
                                    //append to local orders
                                    if (currentOrder.ContainsKey(productName))
                                    {
                                        currentOrder[productName]++; //adding to existing product
                                    }
                                    else
                                    {
                                        currentOrder.Add(productName, quantity); //adding new product with its quantity
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }