コード例 #1
0
        public void CanAddOrder()
        {
            var repo = new MockOrdersRepo();

            var newOrder = new Order()
            {
                Area = 10,
                CostPerSquareFoot = 5.15M,
                LaborCost = 47.50M,
                LaborCostPerSquareFoot = 4.75M,
                MaterialCost = 51.50M,
                Name = "nick",
                OrderNumber = 0,
                ProductType = "Wood",
                StateAbbr = "PA",
                TaxCost = 668.2500M,
                TaxRate = 6.75M,
                TotalCost = 767.2500M
            };

            repo.CreateOrder(newOrder);
            List<Order> orders = repo.GetAllOrders(DateTime.Today.ToString("MMddyyyy"));

            Assert.AreEqual(newOrder.TotalCost, orders.Last().TotalCost);
            Assert.AreEqual(newOrder.Name, orders.Last().Name);
        }
コード例 #2
0
 // The OrderManager will call GetTotals, passing in the new order, and will get back the order with the updated params
 public Order GetTotals(Order order)
 {
     order.LaborCost = order.LaborCostPerSquareFoot * order.Area;
     order.MaterialCost = order.CostPerSquareFoot * order.Area;
     order.TaxCost = (order.LaborCost + order.MaterialCost) * (order.TaxRate / 100);
     order.TotalCost = order.LaborCost + order.MaterialCost + order.TaxCost;
     return order;
 }
コード例 #3
0
        //public UnityContainer GetAllOrders(string d)
        //{
        //}
        public Order CreateOrder(Order o)
        {
            string f = @"MockData\Orders_" + _today + ".txt";

            var ordersList = GenerateOrderNumber(o);

            WriteToFile(f, ordersList);

            return o;
        }
コード例 #4
0
        private Order GetArea(Order selectedOrder)
        {
            Console.Clear();
            string promptUser = "******" +
                                "Enter the new area (current area: " + selectedOrder.Area + ")\n\n" +
                                ">>>> ";
            Console.Write(promptUser);
            string input = Console.ReadLine();

            if (input == "")
                return selectedOrder;

            selectedOrder.Area = _validation.IsDecimalValid(input, promptUser);
            return selectedOrder;
        }
コード例 #5
0
        public Order EditOrder(Order o, string d)
        {
            string f = @"MockData\Orders_" + d + ".txt";

            var ordersList = GetAllOrders(d);
            int indexToUpdate = 0;

            foreach (var t in ordersList.Where(t => t.OrderNumber == o.OrderNumber))
            {
                indexToUpdate = ordersList.IndexOf(t);
            }

            ordersList[indexToUpdate] = o;

            WriteToFile(f, ordersList);

            return o;
        }
コード例 #6
0
        public void AddOrderTest()
        {
            var manager = new OrderManager();
            var newOrder = new Order()
            {
                Area = 10,
                CostPerSquareFoot = 5.15M,
                LaborCostPerSquareFoot = 4.75M,
                Name = "Nick",
                OrderNumber = 0,
                ProductType = "Wood",
                StateAbbr = "PA",
                TaxRate = 6.75M,
            };

            var order = manager.AddOrder(newOrder);

            Assert.AreEqual("Nick", newOrder.Name);
        }
コード例 #7
0
        public void Execute()
        {
            OrderManager manager = new OrderManager();
            Order newOrder = new Order();

            newOrder.Name = GetCustomerName();

            Tax newTax = GetState();
            Product newProduct = GetProductType();

            newOrder.Area = GetArea();
            newOrder.StateAbbr = newTax.StateAbbr;
            newOrder.TaxRate = newTax.TaxRate;
            newOrder.ProductType = newProduct.ProductType;
            newOrder.CostPerSquareFoot = newProduct.CostPerSqFt;
            newOrder.LaborCostPerSquareFoot = newProduct.LaborCostPerSqFt;

            Console.Clear();
            Console.WriteLine("New order information:\n");
            Console.WriteLine("{0, -9} - Name\n{1, -9} - State\n{2, -9} - Material\n{3, -9} - Area\n",
                newOrder.Name, newOrder.StateAbbr, newOrder.ProductType, newOrder.Area);

            if (!GetConfirmation())
                return;

            var response = manager.AddOrder(newOrder);

            if (response.Success)
            {
                Console.Clear();
                Console.WriteLine(response.Message);
                PrintNewOrder(response.Data);
            }
            else
            {
                Console.Clear();
                Console.WriteLine("Something happened when trying to add the order.");
                Console.WriteLine(response.Message);
            }

            Console.Write("Press any key to return to the menu...");
            Console.ReadKey();
        }
コード例 #8
0
        // Adds order to list as well, and returns it
        public List<Order> GenerateOrderNumber(Order newOrder)
        {
            FileInfo f = new FileInfo(@"MockData\Orders_" + _today + ".txt");

            var ordersList = new List<Order>();

            if (f.Exists)
            {
                ordersList = GetAllOrders(_today);
                newOrder.OrderNumber = ordersList.Last().OrderNumber + 1;
            }
            else
            {
                newOrder.OrderNumber = 1;
            }

            ordersList.Add(newOrder);

            return ordersList;
        }
コード例 #9
0
        public void AddOrderComputationTest()
        {
            var manager = new OrderManager();
            var newOrder = new Order()
            {
                Area = 10,
                CostPerSquareFoot = 5.15M,
                LaborCostPerSquareFoot = 4.75M,
                Name = "nick",
                OrderNumber = 0,
                ProductType = "Wood",
                StateAbbr = "PA",
                TaxRate = 6.75M,
            };

            var order = manager.AddOrder(newOrder);

            Assert.AreEqual(47.5M, newOrder.LaborCost);
            Assert.AreEqual(51.5M, newOrder.MaterialCost);
            Assert.AreEqual(105.6825, newOrder.TotalCost);
            Assert.AreEqual(6.6825, newOrder.TaxCost);
        }
コード例 #10
0
        public Response<Order> EditOrder(Order selectedOrder, string date)
        {
            Response<Order> response = new Response<Order>();

            try
            {
                Computation totals = new Computation();

                selectedOrder = totals.GetTotals(selectedOrder);
                response.Data = _repo.EditOrder(selectedOrder, date);
                response.Success = true;
                response.Message = "Order successfully updated.";
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = "Error occurred.";
                _repo.LogError(ex);
            }

            return response;
        }
コード例 #11
0
        public Response<Order> AddOrder(Order newOrder)
        {
            Response<Order> response = new Response<Order>();

            try
            {
                Computation totals = new Computation();

                newOrder = totals.GetTotals(newOrder);
                response.Data = _repo.CreateOrder(newOrder);
                response.Success = true;
                response.Message = "Order successfully added.";
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = "Error occurred.";
                _repo.LogError(ex);
            }

            return response;
        }
コード例 #12
0
        private Order GetProductType(Order selectedOrder)
        {
            Console.Clear();
            string promptUser = "******" +
                                "Available materials (current material: " + selectedOrder.ProductType + "):\n\n" +
                                "Carpet, Laminate, Tile, Wood\n\n" +
                                ">>>> ";
            Console.Write(promptUser);
            string input = Console.ReadLine();

            if (input == "")
                return selectedOrder;

            input = _validation.NotNull(input, promptUser);

            Product product = _validation.IsProductTypeValid(input, promptUser);

            selectedOrder.ProductType = product.ProductType;
            return selectedOrder;
        }
コード例 #13
0
        public void LogDeletedOrder(Order order)
        {
            List<string> deletedOrdersLog = new List<string>();
            string[] reader;

            if (File.Exists("deleted_orders_log.txt"))
            {
                reader = File.ReadAllLines("deleted_orders_log.txt");

                deletedOrdersLog.AddRange(reader);
            }

            string orderConcat =
                $"{order.OrderNumber},{order.Name},{order.StateAbbr},{order.TaxRate},{order.ProductType},{order.Area},{order.CostPerSquareFoot}," +
                $"{order.LaborCostPerSquareFoot},{order.MaterialCost},{order.LaborCost},{order.TaxCost},{order.TotalCost}";

            deletedOrdersLog.Add(orderConcat);

            using (var writer = File.CreateText("deleted_orders_log.txt"))
            {
                foreach (var o in deletedOrdersLog)
                    writer.WriteLine(o);
            }
        }
コード例 #14
0
        public Response<Order> RemoveOrder(string d, Order orderToRemove)
        {
            Response<Order> response = new Response<Order>();

            try
            {
                List<Order> ordersList = _repo.GetAllOrders(d);
                ProdOrdersRepo pRepo = new ProdOrdersRepo();

                int indexToRemove = 0;

                foreach (var t in ordersList.Where(t => t.OrderNumber == orderToRemove.OrderNumber))
                {
                    indexToRemove = ordersList.IndexOf(t);
                }

                pRepo.LogDeletedOrder(ordersList[indexToRemove]);

                ordersList.RemoveAt(indexToRemove);

                _repo.UpdateFile(ordersList, d);

                response.Success = true;
                response.Message = "Order successfully removed.";
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = "Error occurred.";
                _repo.LogError(ex);
            }

            return response;
        }
コード例 #15
0
        // Here down starts the editing
        private Order GetCustomerName(Order selectedOrder)
        {
            Console.Clear();
            string promptUser = "******" +
                                "Enter new customer name (current name: " + selectedOrder.Name + ")\n\n" +
                                ">>>> ";
            Console.Write(promptUser);
            string input = Console.ReadLine();

            if (input == "")
                return selectedOrder;

            selectedOrder.Name = input;
            return selectedOrder;
        }
コード例 #16
0
        public List<Order> GetAllOrders(string d)
        {
            string filePath = @"MockData\Orders_" + d + ".txt";

            List<Order> orders = new List<Order>();

            if (!File.Exists(filePath))
                return null;

            var reader = File.ReadAllLines(filePath);

            for (int i = 1; i < reader.Length; i++)
            {
                var columns = reader[i].Split(',');

                var order = new Order
                {
                    OrderNumber = int.Parse(columns[0]),
                    Name = columns[1],
                    StateAbbr = columns[2],
                    TaxRate = decimal.Parse(columns[3]),
                    ProductType = (columns[4]),
                    Area = decimal.Parse(columns[5]),
                    CostPerSquareFoot = decimal.Parse(columns[6]),
                    LaborCostPerSquareFoot = decimal.Parse(columns[7]),
                    MaterialCost = decimal.Parse(columns[8]),
                    LaborCost = decimal.Parse(columns[9]),
                    TaxCost = decimal.Parse(columns[10]),
                    TotalCost = decimal.Parse(columns[11])
                };

                orders.Add(order);
            }

            return orders;
        }
コード例 #17
0
        private void PrintOrder(Order selectedOrder)
        {
            Console.Clear();

            Console.WriteLine("Order Number:  - - - - - - - " + selectedOrder.OrderNumber);
            Console.WriteLine("Customer Name: > > > > > > > " + selectedOrder.Name);
            Console.WriteLine("State: - - - - - - - - - - - " + selectedOrder.StateAbbr);
            Console.WriteLine("Tax Rate:  > > > > > > > > > {0:P}", selectedOrder.TaxRate / 100);
            Console.WriteLine("Product Type:  - - - - - - - " + selectedOrder.ProductType);
            Console.WriteLine("Area:  > > > > > > > > > > > " + selectedOrder.Area);
            Console.WriteLine("Cost Per Square Foot:  - - - {0:C}", selectedOrder.CostPerSquareFoot);
            Console.WriteLine("Labor Cost Per Square Foot:  {0:C}", selectedOrder.LaborCostPerSquareFoot);
            Console.WriteLine("-------------------------------------------");
            Console.WriteLine("\nTotal material cost is:  > > {0:C}", selectedOrder.MaterialCost);
            Console.WriteLine("Total labor cost is: - - - - {0:C}", selectedOrder.LaborCost);
            Console.WriteLine("Total tax cost is: > > > > > {0:C}\n", selectedOrder.TaxCost);
            Console.WriteLine("-------------------------------------------");
            Console.WriteLine("\nTotal: {0:C}", selectedOrder.TotalCost);
            Console.WriteLine("\n==========================================\n");
        }
コード例 #18
0
 private void PrintEditedOrder(Order i)
 {
     Console.WriteLine("Order Number:  - - - - - - - " + i.OrderNumber);
     Console.WriteLine("Customer Name: > > > > > > > " + i.Name);
     Console.WriteLine("State: - - - - - - - - - - - " + i.StateAbbr);
     Console.WriteLine("Tax Rate:  > > > > > > > > > {0:P}", i.TaxRate / 100);
     Console.WriteLine("Product Type:  - - - - - - - " + i.ProductType);
     Console.WriteLine("Area:  > > > > > > > > > > > " + i.Area);
     Console.WriteLine("Cost Per Square Foot:  - - - {0:C}", i.CostPerSquareFoot);
     Console.WriteLine("Labor Cost Per Square Foot:  {0:C}", i.LaborCostPerSquareFoot);
     Console.WriteLine("-------------------------------------------");
     Console.WriteLine("\nTotal material cost is:  > > {0:C}", i.MaterialCost);
     Console.WriteLine("Total labor cost is: - - - - {0:C}", i.LaborCost);
     Console.WriteLine("Total tax cost is: > > > > > {0:C}\n", i.TaxCost);
     Console.WriteLine("-------------------------------------------");
     Console.WriteLine("\nTotal: {0:C}", i.TotalCost);
 }
コード例 #19
0
        private Order GetState(Order selectedOrder)
        {
            Console.Clear();
            string promptUser = "******" +
                                "Available states (current state: " + selectedOrder.StateAbbr + "):\n\n" +
                                "Ohio (OH), Pennsylvania (PA), Michigan (MI), Indiana (IN)\n\n" +
                                ">>>> ";
            Console.Write(promptUser);
            string input = Console.ReadLine();

            if (input == "")
                return selectedOrder;

            input = _validation.NotNull(input, promptUser);

            Tax tax = _validation.IsStateValid(input, promptUser);

            selectedOrder.StateAbbr = tax.StateAbbr;
            return selectedOrder;
        }