Exemplo n.º 1
0
        public void Run()
        {
            bool quit = false;

            #region App Menu
            do
            {
                Console.Clear();
                Helpers.PrintWelcome();
                //Get user option
                userOption = Helpers.GetMenuOption(Menus.Start);
                switch (userOption)
                {
                    #region CASE1: Login with existing user
                case 1:                         //login with existing user
                    Console.Clear();
                    bool   valid = false;
                    bool   end   = false;
                    string phone;
                    do
                    {
                        Console.Write("Enter phone number or enter c to cancel: ");
                        phone = Console.ReadLine();
                        if (phone == "c")
                        {
                            end   = true;
                            valid = true;
                        }
                        else
                        {
                            valid = Helpers.IsValidPhoneNumber(phone);
                            if (!valid)
                            {
                                Helpers.NotValidOption(phone);
                            }
                            var cust = db.Customers.Where(p => p.PhoneNum == phone).FirstOrDefault();
                            if (cust == null)
                            {
                                valid = false;
                                Helpers.NotValidOption(phone);
                            }
                        }
                    } while (!valid);
                    if (end)
                    {
                        break;
                    }
                    CustomerLogic.CustomerOptions(phone);
                    break;
                    #endregion

                    #region CASE2: Create new user
                case 2:                         // create new user
                    Console.Clear();
                    Console.WriteLine("Creating a new user");
                    CustomerLogic.CreateNewCustomer();
                    break;
                    #endregion

                    #region CASE 3: Location sales history
                case 3:                         //location
                    valid = false;
                    end   = false;
                    Console.Clear();
                    string name1;
                    #region Validate user input
                    do
                    {
                        Console.Write("Enter location name or c to cancel: ");
                        name1 = Console.ReadLine();
                        valid = !(string.IsNullOrWhiteSpace(name1));
                        if (name1 == "c")
                        {
                            valid = true;
                            end   = true;
                        }
                        else if (!valid)
                        {
                            Helpers.NotValidOption(name1);
                        }
                        else
                        {
                            valid = LocationLogic.ValidLocation(name1);
                        }
                        if (!valid)
                        {
                            Helpers.NotValidOption(name1);
                        }
                    } while (!valid);
                    if (end)
                    {
                        break;
                    }
                    #endregion
                    //display sales history for location
                    LocationLogic.LocationSales(name1);
                    break;
                    #endregion

                    #region CASE4: Search by name
                case 4:
                    Console.Clear();
                    valid = false;
                    end   = false;
                    string name;

                    #region Validate user input
                    do
                    {
                        Console.Write("Enter customer name or c to cancel: ");
                        name  = Console.ReadLine();
                        valid = !(string.IsNullOrWhiteSpace(name));
                        if (name == "c")
                        {
                            valid = true;
                            end   = true;
                        }
                        else if (!valid)
                        {
                            Helpers.NotValidOption(name);
                        }
                    } while (!valid);
                    if (end)
                    {
                        break;
                    }
                    #endregion

                    Helpers.SearchCustomer(name);
                    break;
                    #endregion

                default:                         //exit program
                    quit = true;
                    break;
                }
                ///usertype? customer or location

                //Display options (customer)
                ///create new order
                ///view order histories
                //OR Display options (location)
                ///search customers by name
                ///display order history of store location
            } while (!quit);
            #endregion
        }
Exemplo n.º 2
0
        /// <summary>
        /// Prompts user for option from specified menu
        /// Validates user input based on menu
        /// </summary>
        /// <param name="menu"></param>
        /// <returns int>User option</returns>
        public static int GetMenuOption(Menus menu)
        {
            #region Method variables
            int    choice = 0;
            bool   valid  = false;
            string input;
            #endregion

            #region Menus
            do
            {
                switch (menu)
                {
                    #region Main start menu
                case Menus.Start:                         //Main start menu operations
                    PrintStartMenu();
                    input = Console.ReadLine();
                    //valid = string.IsNullOrWhiteSpace(input);
                    valid = int.TryParse(input, out choice);
                    if (!valid)
                    {
                        Console.Clear();
                        NotValidOption(input);
                    }
                    else if (choice < 1 || choice > 5)
                    {
                        Console.Clear();
                        NotValidOption(input);
                        valid = false;                                 //ensure that valid is false
                    }
                    break;
                    #endregion

                    #region Create customer menu
                case Menus.CreateCustomer:                         //Create customer menu
                    CustomerLogic.PrintCreateCustomerMenu();
                    input = Console.ReadLine();
                    valid = int.TryParse(input, out choice);
                    if (!valid)
                    {
                        Console.Clear();
                        NotValidOption(input);
                    }
                    else if (choice < 1 || choice > 5)
                    {
                        Console.Clear();
                        NotValidOption(input);
                        valid = false;                                 //ensure that valid is false
                    }
                    break;
                    #endregion

                    #region Customer menu
                case Menus.Customer:                         //Customer menu
                    CustomerLogic.PrintCustomerMenu();
                    input = Console.ReadLine();
                    valid = int.TryParse(input, out choice);
                    if (!valid)
                    {
                        Console.Clear();
                        NotValidOption(input);
                    }
                    else if (choice < 1 || choice > 4)
                    {
                        Console.Clear();
                        NotValidOption(input);
                        valid = false;                                 //ensure that valid is false
                    }
                    break;
                    #endregion
                }
            } while (!valid);
            #endregion

            return(choice);
        }