예제 #1
0
 private static void DrawCustomerInformation(CustomerOrder order)
 {
     Console.WriteLine($"Name: {order.CustomerName}");
     Console.WriteLine($"State: {order.StateKey}");
     Console.WriteLine($"Floor Type: {order.ProductKey}");
     Console.WriteLine($"Amount Purchased (SqFt): {order.AreaString} ");
 }
예제 #2
0
 /// <summary>
 /// Puts edited edited order into old spot
 /// </summary>
 /// <param name="order"></param>
 /// <param name="orderNumber"></param>\
 /// <param name="date">date where the data lives</param>
 public void EditOrder(CustomerOrder order, int orderNumber, string date)
 {
     var repo = RepositoryFactory.CreateOrderRepository(date);
     //subtract 1 to accout for the offset
     orderNumber--;
     repo.EditOrder(order, orderNumber);
 }
예제 #3
0
 private static void DrawProductInformation(CustomerOrder order)
 {
     var productsManager = new ProductManager();
     var productsResponse = productsManager.GetProductResponse(order.ProductKey);
     Console.WriteLine($"Material cost per SqFt: {productsResponse.Product.MaterialCostSqFt:C}");
     Console.WriteLine($"Labor cost per SqFt: {productsResponse.Product.LaborCostSqFt:C}");
 }
예제 #4
0
        /// <summary>
        /// Prompts the user for an area and adds it to an order
        /// </summary>
        /// <param name="order">Order that is to be updated </param>
        /// <param name="headerText">Text that is to be displayed on the header</param>
        /// <returns>Updated customer order</returns>
        public CustomerOrder GetAreaFromCustomer(CustomerOrder order)
        {
            Console.Clear();
            _orderForm.AddOrder(order, _headerText);
            Console.WriteLine();
            Console.Write($"How many square feet of {order.ProductKey} does the customer want? ");

            string input = Console.ReadLine();

            if (string.IsNullOrEmpty(input) && _edit)
            {
                return order;
            }

            decimal area;
            bool isValid = decimal.TryParse(input, out area);

            while(!isValid || area <= 0)
            {
                Console.Clear();
                _orderForm.AddOrder(order, _headerText);
                Console.WriteLine();
                Console.WriteLine("Please enter a number...");
                Console.Write($"How many square feet of {order.ProductKey} does the customer want? ");
                input = Console.ReadLine();
                isValid = decimal.TryParse(input, out area);
            }

            order.Area = area;
            order.AreaString = input;
            return order;
        }
예제 #5
0
        public void Execute()
        {
            CustomerOrder order = new CustomerOrder();
            OrderManager orderManager = new OrderManager();
            Prompts prompts = new Prompts();
            Wrappers wrappers = new Wrappers();

            _headerText = "Add Order";

            string date = $"{DateTime.Today.Month.ToString()}{DateTime.Today.Day.ToString()}{DateTime.Today.Year.ToString()}";

            Console.Clear();

            prompts.SetHeaderText(_headerText);

            order = prompts.GetNameFromCustomer(order);
            order = prompts.GetStateFromCustomer(order);
            order = prompts.GetProductFromCustomer(order);
            order = prompts.GetAreaFromCustomer(order);

            Console.Clear();
            _orderForm.AddOrder(order, _headerText);

            order = orderManager.SetOrderNumber(order, date);
            order = orderManager.OrderCalculations(order);
            Console.Clear();
            _orderForm.DisplayFullOrder(order, _headerText);
            Console.WriteLine();

            while (true)
            {
                Console.WriteLine("Would you like to save this order? (Y/N)");

                switch (Console.ReadKey(false).Key)
                {
                    case ConsoleKey.Y:
                        orderManager.AddOrderToRepo(order, date);
                        Console.Clear();
                        wrappers.DrawHeader("Order Saved");
                        wrappers.DrawFooter();
                        Thread.Sleep(1000);
                        return;
                    case ConsoleKey.N:
                        Console.Clear();
                        wrappers.DrawHeader("Order not Saved");
                        wrappers.DrawFooter();
                        Thread.Sleep(1000);
                        return;
                    default:
                        Console.Clear();
                        _orderForm.DisplayFullOrder(order, _headerText);
                        Console.WriteLine();
                        Console.WriteLine("Press Y to save or N to abandon the order...");
                        break;
                }
            }
        }
예제 #6
0
 /// <summary>
 /// Displays order with all the details
 /// </summary>
 /// <param name="order">The order you want to display.</param>
 /// <param name="headerText">What you want the header to say.</param>
 public void DisplayFullOrder(CustomerOrder order, string headerText)
 {
     OrderManager orderManager = new OrderManager();
     order = orderManager.OrderCalculations(order);
     _wrappers.DrawHeader(headerText);
     DrawCustomerInformation(order);
     DrawProductInformation(order);
     DrawTotalInformation(order);
     _wrappers.DrawFooter();
 }
예제 #7
0
 private void DrawTotalInformation(CustomerOrder order)
 {
     var statesManager = new StateManager();
     var stateResponse = statesManager.GetStateResponse(order.StateKey);
     Console.WriteLine(_lines.DrawLine(LineTypes.Equals));
     Console.WriteLine();
     Console.WriteLine($"Total Material Cost: {order.MaterialCostTotal:C}");
     Console.WriteLine($"Total Labor Cost: {order.LaborCostTotal:C}");
     Console.WriteLine($"Subtotal: {(order.MaterialCostTotal + order.LaborCostTotal):C}");
     Console.WriteLine($"{stateResponse.State.StateName}'s tax rate is {stateResponse.State.TaxRate}%");
     Console.WriteLine($"Tax: {order.OrderTax:C}");
     Console.WriteLine(_lines.DrawLine(LineTypes.Equals));
     Console.WriteLine();
     Console.WriteLine($"Order Total: {order.OrderTotal:C}");
 }
예제 #8
0
        public void OrderCalculationsTest()
        {
            var orderManager = new OrderManager();
            CustomerOrder testOrder = new CustomerOrder();
            StateManager stateManager = new StateManager();
            ProductManager productManager = new ProductManager();

            testOrder = orderManager.OrderCalculations(_order);
            var productResponse = productManager.GetProductResponse(_order.ProductKey);
            var laborCost = productResponse.Product.LaborCostSqFt;
            var materialCost = productResponse.Product.MaterialCostSqFt;
            var stateResponse = stateManager.GetStateResponse(_order.StateKey);

            var subTotal = (_order.Area * (materialCost + laborCost));
            var tax = subTotal/stateResponse.State.TaxRate;
            var total = subTotal + tax;

            Assert.AreEqual(total, testOrder.OrderTotal);
        }
예제 #9
0
        public FileOrderRepository(string date)
        {
            _fullPath = $@"C:\_repos\alex-grbach-individual-work\SGFlooring\SGFlooring.UI\DataFiles\CustomerRepo\Orders_{date}.txt";

            if (_orders == null)
            {
                _orders = new List<CustomerOrder>();
                if (File.Exists(_fullPath))
                {
                    using (StreamReader sr = File.OpenText(_fullPath))
                    {
                        sr.ReadLine();
                        string inputLine = "";
                        while ((inputLine = sr.ReadLine()) != null)
                        {
                            string[] inputParts = inputLine.Split(',');
                            CustomerOrder order = new CustomerOrder()
                            {
                                OrderNumber = int.Parse(inputParts[0]),
                                CustomerName = inputParts[1],
                                StateKey = inputParts[2],
                                ProductKey = inputParts[3],
                                AreaString = inputParts[4]
                            };

                            _orders.Add(order);
                        }

                    }
                }
                else
                {
                    using (StreamWriter sw = new StreamWriter(_fullPath, false))
                    {
                        // write the header line
                        sw.WriteLine("OrderNumber,CustomerName,StateKey,ProductKey,Area");
                    }
                }
            }
        }
예제 #10
0
        /// <summary>
        /// Prompts the user for a state and adds it to an order
        /// </summary>
        /// <param name="order">Order that is to be updated </param>
        /// <param name="headerText">Text that is to be displayed on the header</param>
        /// <returns>Updated customer order</returns>
        public CustomerOrder GetStateFromCustomer(CustomerOrder order)
        {
            string input;
            Console.Clear();
            _orderForm.AddOrder(order, _headerText);
            Console.WriteLine();
            _displayFullList.States();
            Console.WriteLine();

            var ops = new StateManager();
            StateResponse response;

            do
            {
                Console.Write("Please enter customers state abbrevation: ");
                input = Console.ReadLine().ToUpper();
                if (string.IsNullOrEmpty(input) && _edit)
                {
                    return order;
                }
                response = ops.GetStateResponse(input);
                if (!response.Success)
                {
                    Console.Clear();
                    _orderForm.AddOrder(order, _headerText);
                    Console.WriteLine();
                    _displayFullList.States();
                    Console.WriteLine();
                    Console.WriteLine(response.Message);
                }
            } while (!response.Success);

            order.StateKey = input;
            return order;
        }
예제 #11
0
        /// <summary>
        /// Prompts the user for a product and adds it to an order
        /// </summary>
        /// <param name="order">Order that is to be updated </param>
        /// <param name="headerText">Text that is to be displayed on the header</param>
        /// <returns>Updated customer order</returns>
        public CustomerOrder GetProductFromCustomer(CustomerOrder order)
        {
            Console.Clear();
            _orderForm.AddOrder(order, _headerText);
            Console.WriteLine();
            _displayFullList.Products();
            Console.WriteLine();

            var ops = new ProductManager();
            ProductResponse response;
            string input;
            do
            {
                Console.Write("Please enter a product: ");
                input = Console.ReadLine();

                if (string.IsNullOrEmpty(input) && _edit)
                {
                    return order;
                }

                if (!string.IsNullOrWhiteSpace(input))
                {
                    //Formating to match key
                    input = (input.ToUpper().First() + input.Substring(1).ToLower());
                }

                response = ops.GetProductResponse(input);

                if (!response.Success)
                {
                    Console.Clear();
                    _orderForm.AddOrder(order, _headerText);
                    Console.WriteLine();
                    _displayFullList.Products();
                    Console.WriteLine();
                    Console.WriteLine(response.Message);
                }
            } while (!response.Success);

            order.ProductKey = input;
            return order;
        }
예제 #12
0
        /// <summary>
        /// Prompts the user for a name and adds it to an order
        /// </summary>
        /// <param name="order">Order that the name is being added to</param>
        /// <param name="headerText">Text to display on the header</param>
        /// <returns>Updated customer order</returns>
        public CustomerOrder GetNameFromCustomer(CustomerOrder order)
        {
            string customerName;
            Console.Clear();
            _orderForm.AddOrder(order, _headerText);
            Console.WriteLine();
            Regex rgx = new Regex(@"^[a-zA-Z0-9 -]*$");
            bool isMatch;
            do
            {
                Console.Write("Please enter the customers name: ");
                customerName = Console.ReadLine();
                isMatch = rgx.IsMatch(customerName);
                //rgx.Replace(customerName, "");
                if (string.IsNullOrWhiteSpace(customerName) && !_edit)
                {
                    Console.Clear();
                    _orderForm.AddOrder(order, _headerText);
                    Console.WriteLine();
                    Console.WriteLine("You have to enter something...");
                }
                else if(string.IsNullOrEmpty(customerName) && _edit)
                {
                    return order;
                }
                else if(!isMatch)
                {
                    Console.Clear();
                    _orderForm.AddOrder(order, _headerText);
                    Console.WriteLine();
                    Console.WriteLine("No Super Special characters aloud in names...\nHyphens are cool though");
                }
            }
            while ((string.IsNullOrWhiteSpace(customerName) && !_edit) || !isMatch);

            //Returns customername with capital values because it is a proper noun!

            string[] customerNameArray = customerName.Split(' ');
            string formattedName = null;
            foreach (var name in customerNameArray)
            {
               formattedName += name.ToUpper().First() + name.Substring(1) + " ";
            }

            order.CustomerName = formattedName;
            return order;
        }
예제 #13
0
 public void AddOrder(CustomerOrder order)
 {
     _orders.Add(order);
 }
예제 #14
0
        /// <summary>
        /// Calculates parts of the Customer Order
        /// </summary>
        /// <param name="order">Order that the calcualtions are to be preformed on.</param>
        /// <returns>Updated order.</returns>
        public CustomerOrder OrderCalculations(CustomerOrder order)
        {
            var stateManager = new StateManager();
            var stateResponse = stateManager.GetStateResponse(order.StateKey);

            var productManager = new ProductManager();
            var productRepsonse = productManager.GetProductResponse(order.ProductKey);

            order.Area = decimal.Parse(order.AreaString);
            order.MaterialCostTotal = order.Area*productRepsonse.Product.MaterialCostSqFt;
            order.LaborCostTotal = order.Area*productRepsonse.Product.LaborCostSqFt;
            decimal subTotal = order.MaterialCostTotal + order.LaborCostTotal;
            order.OrderTax = subTotal/stateResponse.State.TaxRate;
            order.OrderTotal = subTotal + order.OrderTax;

            return order;
        }
예제 #15
0
 public void AddOrder(CustomerOrder order, string headderText)
 {
     _wrappers.DrawHeader(headderText);
     DrawCustomerInformation(order);
     _wrappers.DrawFooter();
 }
예제 #16
0
        public void Execute()
        {
            Console.Clear();
            var orderManager = new OrderManager();
            _prompts.EditMode();
            _prompts.SetHeaderText(HeaderText);

            string date = _prompts.GetDateFromCustomer();

            if (date == null)
            {
                Console.Clear();
                _wrappers.DrawHeader("Invalid date");
                Console.WriteLine("Returning to the main menu");
                _wrappers.DrawFooter();
                Thread.Sleep(1000);
                return;
            }

            int orderNumber = _prompts.GetOrderNumberFromUser(date);

            if (orderNumber < 0 || orderNumber > orderManager.NumberOfOrdersInRepo(date))
            {
                Console.Clear();
                _wrappers.DrawHeader("Invalid Entry...");
                Console.WriteLine("Returning to the main menu");
                _wrappers.DrawFooter();
                Thread.Sleep(1000);
                return;
            }

            CustomerOrderResponse orderResponse = orderManager.DisplayCustomerOrder(orderNumber, date);

            if (!orderResponse.Success)
            {
                Console.Clear();
                _wrappers.DrawHeader(orderResponse.Message);
                _wrappers.DrawFooter();
                Thread.Sleep(1000);
                return;
            }

            Console.Clear();

            CustomerOrder orderEdit = new CustomerOrder();

            _prompts.SetHeaderText(HeaderText);
            //_orderForm.AddOrder(orderEdit, HeaderText);

            CustomerOrder order = orderResponse.Order;
            orderManager.OrderCalculations(order);
            //sets the new values to the old ones for reuse
            orderEdit.CustomerName = order.CustomerName;
            orderEdit.AreaString = order.AreaString;
            orderEdit.Area = order.Area;
            orderEdit.StateKey = order.StateKey;
            orderEdit.ProductKey = order.ProductKey;
            orderEdit.OrderNumber = order.OrderNumber;

            _orderForm.AddOrder(orderEdit, HeaderText);
            orderEdit = _prompts.GetNameFromCustomer(orderEdit);
            Console.Clear();
            _orderForm.AddOrder(orderEdit, HeaderText);
            orderEdit = _prompts.GetStateFromCustomer(orderEdit);
            Console.Clear();
            _orderForm.AddOrder(orderEdit, HeaderText);
            orderEdit = _prompts.GetProductFromCustomer(orderEdit);
            Console.Clear();
            _orderForm.AddOrder(orderEdit, HeaderText);
            orderEdit = _prompts.GetAreaFromCustomer(orderEdit);

            Console.Clear();
            orderEdit = orderManager.OrderCalculations(orderEdit);
            _orderForm.DisplayFullOrder(orderEdit, HeaderText);

            while(true)
            {
                Console.WriteLine("Save edited order (Y/N)");
                switch (Console.ReadKey(false).Key)
                {
                    case ConsoleKey.Y:

                        orderManager.EditOrder(orderEdit, orderNumber, date);
                        Console.Clear();
                        _wrappers.DrawHeader("Changes saved");
                        _wrappers.DrawFooter();
                        Thread.Sleep(1000);
                        return;
                    case ConsoleKey.N:
                        Console.Clear();
                        _wrappers.DrawHeader("Changes not saved");
                        _wrappers.DrawFooter();
                        Thread.Sleep(1000);
                        return;
                    default:
                        Console.Clear();
                        _orderForm.AddOrder(orderEdit, HeaderText);
                        Console.WriteLine("Press either Y or N");
                        continue;
                }
            }
        }
예제 #17
0
        public void SetOrderNumberTest()
        {
            var orderManager = new OrderManager();
            var testOrder = new CustomerOrder();
            testOrder = orderManager.SetOrderNumber(_order, _date);

            Assert.AreEqual(4, testOrder.OrderNumber);
        }
예제 #18
0
 public void EditOrder(CustomerOrder order, int orderNumber)
 {
     _orders[orderNumber] = order;
     WriteFile();
 }
예제 #19
0
 public void AddOrder(CustomerOrder order)
 {
     _orders.Add(order);
     WriteFile();
 }
예제 #20
0
        public CustomerOrder SetOrderNumber(CustomerOrder order, string date)
        {
            try
            {
                order.OrderNumber = (GetAllOrders(date)[NumberOfOrdersInRepo(date) -1].OrderNumber) + 1;
            }
            catch (ArgumentOutOfRangeException)
            {
                order.OrderNumber = 1;
            }

            return order;
        }
예제 #21
0
 /// <summary>
 /// Adds order to the current repository
 /// </summary>
 /// <param name="order">Order to be passed to the repo.</param>
 /// <param name="date">Date of order to add</param>
 public void AddOrderToRepo(CustomerOrder order, string date)
 {
     order = OrderCalculations(order);
     var repo = RepositoryFactory.CreateOrderRepository(date);
     repo.AddOrder(order);
 }