Ejemplo n.º 1
0
        public EditOrderResponse EditRules(DateTime OrderDate, string CustomerName, string State, string ProductType, decimal Area, EditOrderResponse Response)
        {
            Response.success = false;

            if (Area < 100)
            {
                Response.message = "Area of orders must be a minimun of 100.00 square feet.";
                return(Response);
            }

            List <Taxes> taxes = new List <Taxes>();

            taxes = ReadFromTaxesFile.ReadTaxes(FilePaths.TaxesFilePath);
            foreach (var tax in taxes)
            {
                if (tax.StateAbbreviation.ToUpper() == State.ToUpper())
                {
                    Response.success = true;
                    break;
                }
                else
                {
                    Response.success = false;
                    continue;
                }
            }

            if (Response.success == false)
            {
                Response.message = "You did not enter a valid state abbreviation.";
                return(Response);
            }

            List <Product> products = new List <Product>();

            products = ReadFromProductsFile.ReadProducts(FilePaths.ProductsFilePath);
            foreach (var product in products)
            {
                if (product.ProductType.ToLower() == ProductType.ToLower())
                {
                    Response.success = true;
                    break;
                }
                else
                {
                    Response.success = false;
                    continue;
                }
            }

            if (Response.success == false)
            {
                Response.message = "You did not enter a valid product type.";
                return(Response);
            }

            return(Response);
        }
Ejemplo n.º 2
0
        public Order MakeCalculations(Order Order, DateTime Date, string CustomerName, string State, string ProductType, decimal Area)
        {
            List <Taxes> Taxes = new List <Taxes>();

            Taxes = ReadFromTaxesFile.ReadTaxes(FilePaths.TaxesFilePath);
            List <Product> Products = new List <Product>();

            Products = ReadFromProductsFile.ReadProducts(FilePaths.ProductsFilePath);
            List <Order> Orders = new List <Order>();

            Orders = ReadOrdersFromFile.ReadOrders(FilePath.GetFilePath(Date));



            if (Orders.Count == 0)
            {
                Order.OrderNumber = 1;
            }
            else
            {
                var maxOrderNumber = Orders.Max(order => order.OrderNumber);
                Order.OrderNumber = maxOrderNumber + 1;
            }


            var stateTaxRate = Taxes.Where(state => state.StateAbbreviation.ToUpper() == State.ToUpper()).Select(state => state.TaxRate); //some kind of problem here when editing

            foreach (var tax in stateTaxRate)
            {
                Order.TaxRate = Math.Round(tax, 2);
                break;
            }

            var costPerSqFoot = Products.Where(product => product.ProductType.ToLower() == ProductType.ToLower()).Select(product => product.CostPerSquareFoot);

            foreach (var cost in costPerSqFoot)
            {
                Order.CostPerSquareFoot = Math.Round(cost, 2);
                break;
            }

            var laborCostPerSqFoot = Products.Where(product => product.ProductType.ToLower() == ProductType.ToLower()).Select(product => product.LaborCostPerSquareFoot);

            foreach (var cost in laborCostPerSqFoot)
            {
                Order.LaborCostPerSquareFoot = Math.Round(cost, 2);
                break;
            }

            Order.MaterialCost = Math.Round((Area * Order.CostPerSquareFoot), 2);
            Order.LaborCost    = Math.Round((Area * Order.LaborCostPerSquareFoot), 2);
            Order.Tax          = Math.Round(((Order.MaterialCost + Order.LaborCost) * (Order.TaxRate / 100)), 2);
            Order.Total        = Math.Round((Order.MaterialCost + Order.LaborCost + Order.Tax), 2);

            return(Order);
        }
Ejemplo n.º 3
0
        public void Execute()
        {
            OrderManager     manager   = OrderManagerFactory.Create();
            Order            order     = new Order();
            DateTime         orderDate = new DateTime().Date;
            Calculations     calculate = new Calculations();
            PrintReceipt     print     = new PrintReceipt();
            AddOrderResponse response  = new AddOrderResponse();


            while (true)
            {
                Console.Clear();
                Console.WriteLine("Add an order");
                Console.WriteLine(TextHelper.ConsoleBar);
                Console.WriteLine("Please enter the following information....");
                Console.WriteLine();

                while (true)
                {
                    Console.WriteLine("Date of Order: ");
                    if (DateTime.TryParse(Console.ReadLine(), out orderDate))
                    {
                        order.Date = orderDate;
                        break;
                    }

                    Console.WriteLine("That was not a valid date. Press any key to continue...");
                    Console.ReadKey();
                }

                while (true)
                {
                    Console.Clear();
                    Console.WriteLine("Customer Name: ");
                    string customerName = Console.ReadLine();

                    order.CustomerName = customerName;

                    if (String.IsNullOrWhiteSpace(order.CustomerName))
                    {
                        Console.WriteLine("You did not enter anything! Press any key to continue...");
                        Console.ReadKey();
                    }

                    else
                    {
                        break;
                    }
                }

                List <Taxes> taxes = new List <Taxes>();
                taxes = ReadFromTaxesFile.ReadTaxes(FilePaths.TaxesFilePath);
                Console.Clear();
                Console.WriteLine("We service the states of...");
                foreach (var tax in taxes)
                {
                    Console.WriteLine(tax.StateAbbreviation + " ");
                }
                Console.WriteLine("\nPlease enter your state (use abbreviation): ");
                order.State = Console.ReadLine().ToUpper();

                List <Product> products = new List <Product>();
                products = ReadFromProductsFile.ReadProducts(FilePaths.ProductsFilePath);
                Console.Clear();
                Console.WriteLine("Products currently in stock:");
                foreach (var product in products)
                {
                    Console.WriteLine(product.ProductType + " ");
                }

                Console.WriteLine("\nPlease enter your product selection:");
                order.ProductType = Console.ReadLine();

                while (true)
                {
                    Console.Clear();
                    Console.WriteLine("Enter the area of the floor (sq ft). Minimun order is 100: ");
                    decimal area;
                    if (decimal.TryParse(Console.ReadLine(), out area))
                    {
                        order.Area = area;
                        break;
                    }
                    else
                    {
                        Console.WriteLine("That was not a valid entry! Press any key to continue...");
                        Console.ReadKey();
                        continue;
                    }
                }

                response = manager.AddOrder(order.Date, order.CustomerName, order.State, order.ProductType, order.Area);
                if (!response.success)
                {
                    Console.WriteLine("There was an error with your order...");
                    Console.WriteLine(response.message);
                    Console.WriteLine("Press any key to continue...");
                    Console.ReadKey();
                }
                else
                {
                    break;
                }
            }

            order = calculate.MakeCalculations(order, order.Date, order.CustomerName, order.State, order.ProductType, order.Area);
            while (true)
            {
                print.Print(order);
                Console.WriteLine("Are you sure you want to place this order (Y/N)? ");
                string userResponse = Console.ReadLine().ToUpper();
                switch (userResponse)
                {
                case "Y":
                    AddOrderFile addOrder = new AddOrderFile();
                    addOrder.AddOrderToFile(response.Orders, order, order.Date);
                    Console.WriteLine("Order has been saved! Press any key to continue...");
                    Console.ReadKey();
                    break;

                case "N":
                    Console.WriteLine("Order has been canceled. Press any key to continue...");
                    Console.ReadKey();
                    break;

                default:
                    Console.WriteLine("That was not a valid choice. Press any key to try again...");
                    Console.ReadKey();
                    continue;
                }
                break;
            }
        }
Ejemplo n.º 4
0
        public Order GetNewOrderInfoFromUser(Order order)
        {
            PrintReceipt print = new PrintReceipt();

            Console.Clear();
            print.Print(order);
            Console.WriteLine("Please update the following info. If no change is needed for a field, leave the field blank and press enter.");
            Console.WriteLine(TextHelper.ConsoleBar);
            Console.WriteLine();


            Console.WriteLine("Customer Name: ");
            string userInput = Console.ReadLine();

            if (!String.IsNullOrWhiteSpace(userInput))
            {
                order.CustomerName = userInput;
            }

            List <Taxes> taxes = new List <Taxes>();

            taxes = ReadFromTaxesFile.ReadTaxes(FilePaths.TaxesFilePath);
            Console.WriteLine("We service the states of...");
            foreach (var tax in taxes)
            {
                Console.Write(tax.StateAbbreviation + " ");
            }
            Console.WriteLine("\nPlease enter your state (use abbreviation): ");
            userInput = Console.ReadLine();
            if (!String.IsNullOrWhiteSpace(userInput))
            {
                order.State = userInput.ToUpper();
            }


            List <Product> products = new List <Product>();

            products = ReadFromProductsFile.ReadProducts(FilePaths.ProductsFilePath);
            Console.WriteLine("Products currently in stock:");
            foreach (var product in products)
            {
                Console.Write(product.ProductType + " ");
            }

            Console.WriteLine("\nPlease enter your product selection:");
            userInput = Console.ReadLine();
            if (!String.IsNullOrWhiteSpace(userInput))
            {
                order.ProductType = userInput;
            }


            while (true)
            {
                Console.WriteLine("Enter the area of the floor (sq ft): ");
                userInput = Console.ReadLine();
                decimal area;
                if (!String.IsNullOrWhiteSpace(userInput))
                {
                    if (decimal.TryParse(userInput, out area))
                    {
                        order.Area = area;
                        break;
                    }
                    else
                    {
                        Console.WriteLine("That was not a valid entry! Press any key to continue...");
                        Console.ReadKey();
                        continue;
                    }
                }
                break;
            }
            return(order);
        }