Ejemplo n.º 1
0
        public void FetchStateTaxInfoTest(string input, decimal expected)
        {
            var     response = _oops.FetchStateTaxInfo(input);
            decimal result   = response.StateTaxInfo.TaxRate;

            Assert.AreEqual(expected, result);
        }
Ejemplo n.º 2
0
        public void PromptStateFromUser()
        {
            bool   validState = false;
            string stateInput;
            var    listOfStates = _oops.FetchListOfStates();

            do
            {
                do
                {
                    Console.Clear();
                    Console.WriteLine("List of States that we service:");
                    Console.WriteLine("-------------------------------");

                    foreach (var s in listOfStates)
                    {
                        Console.WriteLine(" {0} - ({1}) - {2}%", s.StateAbbreviation, s.StateName, s.TaxRate);
                    }

                    Console.WriteLine();
                    Console.Write("Enter the State Abbreviation of where you're making this order: ");
                    stateInput = Console.ReadLine();
                    Console.WriteLine();

                    if (stateInput == "")
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("You must enter a State Abbreviation.");
                        Console.WriteLine("Press ENTER to continue...");
                        Console.ResetColor();
                        Console.ReadLine();
                    }

                    else if (stateInput.Length != 2)
                    {
                        _errorResponse.ErrorTime         = DateTime.Now;
                        _errorResponse.ErrorSourceMethod = "Add Order Method";
                        _errorResponse.Message           = "State input not 2 letters long.";
                        _errorResponse.Input             = stateInput;
                        _oops.SubmitErrorToLog(_errorResponse);

                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("That is not a state abbreviation.");
                        Console.WriteLine("Press ENTER to continue...");
                        Console.ResetColor();
                        Console.ReadLine();
                        Console.Clear();
                    }
                } while (stateInput.Length != 2);

                var response = _oops.FetchStateTaxInfo(stateInput);

                if (response.Success)
                {
                    _orderInfo.State   = response.StateTaxInfo.StateAbbreviation;
                    _orderInfo.TaxRate = response.StateTaxInfo.TaxRate;
                    Console.WriteLine("You have chosen {0}. It has a Tax Rate of {1}%.",
                                      response.StateTaxInfo.StateName, _orderInfo.TaxRate);
                    Console.WriteLine("Press ENTER to continue...");
                    Console.ReadLine();
                    validState = true;
                }

                else
                {
                    _errorResponse.ErrorTime         = DateTime.Now;
                    _errorResponse.ErrorSourceMethod = "Add Order Method";
                    _errorResponse.Message           = "State input is not in the database.";
                    _errorResponse.Input             = stateInput;
                    _oops.SubmitErrorToLog(_errorResponse);

                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine(response.Message);
                    Console.WriteLine("Press ENTER to continue...");
                    Console.ResetColor();
                    Console.ReadLine();
                }
            } while (!validState);
        }
Ejemplo n.º 3
0
        public void PromptForEditsFromUser()
        {
            Console.Clear();
            Console.WriteLine("INSTRUCTIONS:");
            Console.WriteLine("-The current order info will be inside parentheses.");
            Console.WriteLine("-Leave the field blank and press ENTER if you don't want to edit it.");
            Console.WriteLine();
            Console.WriteLine("Press ENTER to begin editing.");
            Console.ReadLine();

            bool validState       = false;
            bool validProductType = false;
            bool validName        = false;

            //Prompt for Name
            do
            {
                Console.Clear();
                Console.Write("Enter Customer Name ({0}): ", _orderToEdit.CustomerName);
                string nameInput = Console.ReadLine();
                Console.WriteLine();

                string validInput;

                if (nameInput != "")
                {
                    if (nameInput == _orderToEdit.CustomerName)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Your Name already is {0}.", _orderToEdit.CustomerName);
                        Console.WriteLine("To keep the same Customer Name, press ENTER during the prompt.");
                        Console.WriteLine("Press ENTER to continue...");
                        Console.ResetColor();
                        Console.ReadLine();
                    }
                    else
                    {
                        do
                        {
                            Console.Write("Are you sure you want to change your name to {0}? (Y)es or (N)o: ",
                                          nameInput);
                            validInput = Console.ReadLine().ToUpper();
                        } while (validInput != "Y" && validInput != "N");

                        if (validInput == "Y")
                        {
                            _orderPreEdit.CustomerName = nameInput;
                            validName = true;
                            _changesCount++;
                        }
                    }
                }

                else
                {
                    validName = true;
                }
            } while (!validName);

            //Prompt for State
            do
            {
                string stateInput = "";

                do
                {
                    Console.Clear();
                    Console.Write("Enter State Abbreviation ({0}): ", _orderToEdit.State);
                    stateInput = Console.ReadLine();
                    Console.WriteLine();

                    if (stateInput.Length != 2 && stateInput != "")
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("That is not two letters. Press ENTER to continue.");
                        Console.ReadLine();
                        Console.ResetColor();
                    }
                } while (stateInput.Length != 2 && stateInput != "");

                if (stateInput != "")
                {
                    if (stateInput.ToUpper() == _orderToEdit.State)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("Your State already is {0}.", _orderToEdit.State);
                        Console.WriteLine("To keep the same State, press ENTER during the prompt.");
                        Console.WriteLine("Press ENTER to continue...");
                        Console.ResetColor();
                        Console.ReadLine();
                    }
                    else
                    {
                        string confirmation;
                        do
                        {
                            Console.Write("Are you sure you want to change your state to {0}? (Y)es or (N)o: ",
                                          stateInput);
                            confirmation = Console.ReadLine().ToUpper();
                        } while (confirmation != "Y" && confirmation != "N");

                        if (confirmation == "Y")
                        {
                            var response = _oops.FetchStateTaxInfo(stateInput);

                            if (response.Success)
                            {
                                _orderPreEdit.State   = response.StateTaxInfo.StateAbbreviation;
                                _orderPreEdit.TaxRate = response.StateTaxInfo.TaxRate;
                                validState            = true;
                                _changesCount++;
                            }

                            else
                            {
                                _errorResponse.ErrorTime         = DateTime.Now;
                                _errorResponse.ErrorSourceMethod = "Edit Order Method";
                                _errorResponse.Message           = "Invalid state input";
                                _errorResponse.Input             = stateInput;
                                _oops.SubmitErrorToLog(_errorResponse);
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine();
                                Console.WriteLine(response.Message);
                                Console.ResetColor();
                                Console.ReadLine();
                            }
                        }
                    }
                }

                else if (stateInput == "")
                {
                    validState = true;
                }
            } while (!validState);

            //Prompt for Product Type

            Console.Clear();
            Console.WriteLine("Now we will edit Product Type.");
            Console.WriteLine("Press ENTER to continue...");
            Console.ReadLine();
            Console.Clear();

            string input;

            do
            {
                Console.Write("Would you like to see the products list? (Y)es or (N)o: ");
                input = Console.ReadLine().ToUpper();
            } while (input != "Y" && input != "N");

            do
            {
                Console.Clear();

                string productInput = "";

                if (input == "Y")
                {
                    var productsList = _oops.FetchProductsList();

                    Console.WriteLine(
                        "Here is a list of our Products, Materials Cost Rate, and Labor Cost Rate: ");

                    foreach (var product in productsList)
                    {
                        Console.WriteLine("{0}:", product.ProductType);
                        Console.WriteLine("-Cost/sqft: {0:c}", product.CostPerSquareFoot);
                        Console.WriteLine("-Labor cost/sqft: {0:c}", product.LaborCostPerSquareFoot);
                        Console.WriteLine();
                    }
                }

                Console.Write("Enter Product Type ({0}): ", _orderToEdit.ProductType);
                productInput = Console.ReadLine();

                if (productInput != "")
                {
                    if (productInput.ToUpper() == _orderToEdit.ProductType)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine();
                        Console.WriteLine("Your Product Type already is {0}.", _orderToEdit.ProductType);
                        Console.WriteLine("To keep the same Product Type, press ENTER during the prompt.");
                        Console.WriteLine("Press ENTER to continue...");
                        Console.ResetColor();
                        Console.ReadLine();
                    }

                    else
                    {
                        var response = _oops.FetchProductInfo(productInput);

                        if (response.Success)
                        {
                            _orderPreEdit.ProductType            = response.ProductInfo.ProductType;
                            _orderPreEdit.CostPerSquareFoot      = response.ProductInfo.CostPerSquareFoot;
                            _orderPreEdit.LaborCostPerSquareFoot = response.ProductInfo.LaborCostPerSquareFoot;
                            validProductType = true;
                            _changesCount++;
                        }

                        else
                        {
                            _errorResponse.ErrorTime         = DateTime.Now;
                            _errorResponse.ErrorSourceMethod = "Edit Order Method";
                            _errorResponse.Message           = "Invalid product entry";
                            _errorResponse.Input             = productInput;
                            _oops.SubmitErrorToLog(_errorResponse);
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine();
                            Console.WriteLine(response.Message);
                            Console.WriteLine("Press ENTER to continue...");
                            Console.ResetColor();
                            Console.ReadLine();
                        }
                    }
                }

                else if (productInput == "")
                {
                    validProductType = true;
                }
            } while (!validProductType);

            //Prompt to edit Area
            bool   validInt        = false;
            string areaInputString = "";

            do
            {
                Console.Clear();
                Console.Write("Enter Area in sqft ({0}): ", _orderToEdit.Area);
                areaInputString = Console.ReadLine();
                if (areaInputString != "")
                {
                    decimal areaInputInt;

                    if (decimal.TryParse(areaInputString, out areaInputInt))
                    {
                        if (areaInputInt == _orderToEdit.Area)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine();
                            Console.WriteLine("Your Area already is {0} sqft.", _orderToEdit.Area);
                            Console.WriteLine("To keep the same Area, press ENTER during the prompt.");
                            Console.WriteLine("Press ENTER to continue...");
                            Console.ResetColor();
                            Console.ReadLine();
                        }
                        else if (areaInputInt > 0)
                        {
                            _orderPreEdit.Area = areaInputInt;
                            validInt           = true;
                            _changesCount++;
                        }
                        else
                        {
                            _errorResponse.ErrorTime         = DateTime.Now;
                            _errorResponse.ErrorSourceMethod = "Edit Order Method";
                            _errorResponse.Message           = "Negative area input";
                            _errorResponse.Input             = areaInputString;
                            _oops.SubmitErrorToLog(_errorResponse);
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine();
                            Console.WriteLine("You must enter a value greater than.");
                            Console.WriteLine("Press ENTER to continue...");
                            Console.ResetColor();
                            Console.ReadLine();
                        }
                    }
                    else
                    {
                        _errorResponse.ErrorTime         = DateTime.Now;
                        _errorResponse.ErrorSourceMethod = "Edit Order Method";
                        _errorResponse.Message           = "Invalid area input";
                        _errorResponse.Input             = areaInputString;
                        _oops.SubmitErrorToLog(_errorResponse);
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine();
                        Console.WriteLine("That is not a number.");
                        Console.WriteLine("Press ENTER to continue...");
                        Console.ResetColor();
                        Console.ReadLine();
                        Console.Clear();
                    }
                }

                else
                {
                    _orderPreEdit.Area = 0;
                    validInt           = true;
                }
            } while (!validInt);
        }