Exemplo n.º 1
0
        public void CaluclatorTest()
        {
            string taxFile = "Taxes";
            string productFile = "Products";
            string testFIle = "testFile";

            var saveInput = new List<Order>();
            var testOrder = new Order();

            var tax = new TaxRepository();
            var taxList = tax.LoadTaxesAndStatesFromFile();
        }
Exemplo n.º 2
0
        private void GetStateAndTax(Order newOrder)
        {
            var taxloader = new TaxRepository();
            List<Tax> taxList = taxloader.LoadTaxesAndStatesFromFile();
            int count = 0;
            bool isNotValidState = true;
            do
            {
                Console.Write("We operate in the following States:\n");
                foreach (var tax in taxList)
                {
                    Console.WriteLine("{0}", tax.State);
                }

                Console.WriteLine("\nWhich of these states are you in?: ");
                string userInput = Console.ReadLine().ToUpper();

                foreach (var taxSchedule in taxList)
                {

                    if (taxSchedule.State == userInput)
                    {
                        count++;
                        newOrder.State = userInput;
                        newOrder.TaxRate = taxSchedule.TaxRate;
                        isNotValidState = false;

                    }

                }

                if (count == 0)
                {
                    Console.WriteLine("You entered:{0}. That is not a valid state! Make sure you abbreviate, i.e.'OH' ", userInput);
                }

            } while (isNotValidState);
        }
Exemplo n.º 3
0
        public void UpdateOrderInformation(Order selectedOrder)
        {
            Console.WriteLine(
                "To edit the order, enter a new value for each field or leave blank to keep the existing one...");
            Console.WriteLine();

            Console.Write("First Name ({0})", selectedOrder.Name);  //UpdateName method
            string userInput = Console.ReadLine();
            if (!string.IsNullOrEmpty(userInput))
                selectedOrder.Name = userInput;

            bool isValidState = false;       //  UpdateState method
            do
            {
            Console.Write("State ({0})", selectedOrder.State);
            userInput = Console.ReadLine().ToUpper();
            var taxLoader = new TaxRepository();
            List<Tax> taxList = taxLoader.LoadTaxesAndStatesFromFile();
            if (!string.IsNullOrEmpty(userInput)&&(taxList.Exists(t=>t.State==userInput)))
            {
                isValidState = true;
                selectedOrder.State = userInput;
                UpdateTaxRate(selectedOrder);
                UpdateCosts(selectedOrder);
            }
            else if (string.IsNullOrEmpty(userInput))
            {
                break;
            }
            else
            {
                Console.WriteLine("{0} is not a valid entry for State. We operate in:", userInput);
                foreach (var tax in taxList)
                {
                    Console.WriteLine("{0}", tax.State);
                }
            }

            } while (!isValidState);

            bool isValidProduct = false;  //update Product Method
            do
            {
                Console.Write("Product Type ({0})", selectedOrder.ProductType);
                userInput = Console.ReadLine();
                var productLoader = new ProductRespository();
                List<Product> productList = productLoader.LoadProductsFromFile();
                if (!string.IsNullOrEmpty(userInput) && (productList.Exists(p => p.ProductType.ToUpper() == userInput.ToUpper())))
                {
                    isValidProduct = true;
                    selectedOrder.ProductType = userInput;
                    UpdateProductInfo(selectedOrder);
                    UpdateCosts(selectedOrder);
                }
                else if (string.IsNullOrEmpty(userInput))
                {
                    break;
                }
                else
                {
                    Console.WriteLine("{0} is not in our inventory. We carry the following products: ", userInput);
                    foreach (var product in productList)
                    {
                        Console.WriteLine("{0}",product.ProductType );
                    }
                }

            } while (!isValidProduct);

            Console.Write("Area - ({0}):", selectedOrder.Area); //updateArea method
            userInput = Console.ReadLine();
            if (!string.IsNullOrEmpty(userInput))
            {
                bool res;
                decimal userArea;
                do
                {
                   // Console.Write("Area: ({0})", selectedOrder.Area);
                   // userInput = Console.ReadLine();

                    res = decimal.TryParse(userInput, out userArea);
                    if (!res)
                    {
                        Console.WriteLine("Invalid choice");
                        Console.Write("Area - ({0}):", selectedOrder.Area);
                        userInput = Console.ReadLine();
                        res = decimal.TryParse(userInput, out userArea);
                    }

                } while (!res);
                selectedOrder.Area = userArea;
                UpdateCosts(selectedOrder);

            }
            ConfirmAndUpdateOrder(selectedOrder);
        }
Exemplo n.º 4
0
 private void UpdateTaxRate(Order selectedOrder)
 {
     TaxRepository t = new TaxRepository();
     var taxList = t.LoadTaxesAndStatesFromFile();
     var res = taxList.Find(p => p.State == selectedOrder.State); //or where instead of find and extra line?
     selectedOrder.TaxRate = res.TaxRate;
     //Tax taxObj = res.First();
     //selectedOrder.TaxRate = taxObj.TaxRate;
 }