예제 #1
0
        public void AddOrderTestNewFile()
        {
            string mode = "File";
            string productPath = @"DataFiles\Orders\";
            var orderManager = new OrderManager(mode, productPath);

            Order order = new Order()
            {
                OrderNumber = 1,
                CustomerName = "Ringo",
                State = "OH",
                TaxRate = 0.0625m,
                ProductType = "Wood",
                Area = 100m,
                CostPerSqFt = 5.15m,
                LaborCostPerSqFt = 4.75m,
                TotalMaterialCost = 515m,
                TotalLaborCost = 475m,
                TotalTax = 61.88m,
                Total = 1051.88m
            };

            var result = orderManager.AddOrder(order,"06012013");

            Assert.AreEqual(result.Data.Count, 1);
            Assert.IsTrue(result.Success);
            Assert.AreEqual(result.Data[0].CustomerName, "Ringo");
        }
        public void AddOrder(Order newOrder, string date)
        {
            string datedFilePath = _filePath + date + ".txt";

            if (!(File.Exists(datedFilePath)))
            {
                using (var writer = File.CreateText(datedFilePath))
                {
                    writer.Write(
                        "OrderNumber,CustomerName,State,TaxRate,ProductType,Area,CostPerSquareFoot,LaborCostPerSquareFoot,MaterialCost,LaborCost,Tax,Total");
                }
            }

            using (var writer = File.AppendText(datedFilePath))
            {
                writer.WriteLine();
                writer.Write("{0},", newOrder.OrderNumber);
                writer.Write("{0},", "\"" + newOrder.CustomerName + "\"");
                writer.Write("{0},", newOrder.State);
                writer.Write("{0},", newOrder.TaxRate);
                writer.Write("{0},", newOrder.ProductInfo.ProductType);
                writer.Write("{0},", newOrder.Area);
                writer.Write("{0},", newOrder.ProductInfo.CostPerSquareFoot);
                writer.Write("{0},", newOrder.ProductInfo.LaborCostPerSquareFoot);
                writer.Write("{0},", newOrder.MaterialCost);
                writer.Write("{0},", newOrder.LaborCost);
                writer.Write("{0},", newOrder.Tax);
                writer.Write("{0}", newOrder.Total);
            }
        }
예제 #3
0
        public Response AddOrder(string orderDate, string customerName, string state, string productType, decimal area)
        {
            //var repo = new OrderRepository(); //change to interface type later
            Order newOrder = new Order();
            newOrder.CustomerName = customerName; //clean these calculations up (possibly new method?)
            newOrder.Area = area;
            newOrder.OrderNumber = _repo.GetOrderNumber(orderDate);
            newOrder.OrderDate = orderDate;
            newOrder.ProductType =
                _repo.GetProduct(productType.Substring(0, 1).ToUpper() + productType.Substring(1).ToLower());
            var currentState = _repo.GetState(state);
            newOrder.State = currentState.StateAbb;
            newOrder.TaxRate = currentState.TaxRate;
            decimal matCost = area*newOrder.ProductType.MaterialCost;
            newOrder.MaterialCost = matCost;
            decimal labCost = area*newOrder.ProductType.LaborCost;
            newOrder.LaborCost = labCost;
            decimal tax = (matCost + labCost)*(currentState.TaxRate/100);
            newOrder.Tax = tax;
            newOrder.Total = matCost + labCost + tax;

            var response = new Response();

            if (true)
            {
                response.Success = true;
                response.Order = newOrder;
                return response;
            }
        }
        public OrderTestRepository()
        {
            string[] orderStrings = File.ReadAllLines(_dataFilePath);

            for (int i=1; i < orderStrings.Length; i++)
            {
                //TODO: allow saved entries to have a , in the string.
                string[] stringOrderDetails = orderStrings[i].Split(',');
                if (stringOrderDetails.Count() != 13)
                {
                    throw new Exception($"{stringOrderDetails.Count()} fields found while loading order, should be 13.  \nPlease check the file to see if the format has been altered.  \n" + orderStrings[i]);
                }
                Order orderToAdd = new Order();

                orderToAdd.Date = DateTime.Parse(stringOrderDetails[0]);
                orderToAdd.Number = Int32.Parse(stringOrderDetails[1]);
                orderToAdd.CustomerName = stringOrderDetails[2];
                orderToAdd.State = stringOrderDetails[3];
                orderToAdd.TaxPercent = Decimal.Parse(stringOrderDetails[4]);
                orderToAdd.ProductType = stringOrderDetails[5];
                orderToAdd.Area = Decimal.Parse(stringOrderDetails[6]);
                orderToAdd.CostPerSquareFoot = Decimal.Parse(stringOrderDetails[7]);
                orderToAdd.LaborCostPerSquareFoot = Decimal.Parse(stringOrderDetails[8]);
                orderToAdd.MaterialCost = Decimal.Parse(stringOrderDetails[9]);
                orderToAdd.LaborCost = Decimal.Parse(stringOrderDetails[10]);
                orderToAdd.Tax = Decimal.Parse(stringOrderDetails[11]);
                orderToAdd.Total = Decimal.Parse(stringOrderDetails[12]);

                orders.Add(orderToAdd);
            } //for each line in file.
        }
        public void RemoveOrder(Order orderToRemove)
        {
            DateTime dateToRemoveFrom = orderToRemove.Date;
            int orderNumberToRemove = orderToRemove.Number;
            List<Order> ordersForDate = LoadOrdersForDate(dateToRemoveFrom);

            if (!ordersForDate.Any())
            {
                throw new ArgumentException($"Tried to remove an order from a date with no orders.\nDate: {dateToRemoveFrom}");
            }

            IEnumerable<Order> matchingOrders = ordersForDate.Where(o => o.Date == dateToRemoveFrom && o.Number == orderNumberToRemove);
            if (matchingOrders.Count() > 1)
            {
                throw new Exception($"Multiple orders with same date and number discovered during RemoveOrder operation.  Date: {dateToRemoveFrom}");
            }
            if (!matchingOrders.Any())
            {
                throw new ArgumentException($"Tried to remove an order that doesn't exist. \nDate: {dateToRemoveFrom} \nNumber: {orderNumberToRemove}");
            }

            ordersForDate.Remove(matchingOrders.First());
            DeleteFileForDate(orderToRemove.Date);

            if (ordersForDate.Count > 1)
            {
                SaveOrdersForDate(ordersForDate);
            }
        }
예제 #6
0
파일: Program.cs 프로젝트: jekrch/ClassWork
        public static void AddOrder()
        {
            Console.Clear();
            Order orderToAdd = new Order();

            orderToAdd.CustomerName = CustomerPrompt();

            ///Console.WriteLine($"\t\nOrder Number: {orderToDisplay.OrderNumber}");

            //Console.Write($"\tCustomer Name: ");

            //Console.WriteLine($"\tState: {orderToDisplay.StateTaxRate.State}");
            //    Console.WriteLine($"\tTax Rate: {orderToDisplay.StateTaxRate.TaxPercent}");

            //Console.WriteLine($"\tArea: {orderToDisplay.Area}");

            //Console.WriteLine($"\tProduct Type: {orderToDisplay.ProductInfo.ProductType}");
            //    Console.WriteLine($"\tLabor Cost Per Square Foot: {orderToDisplay.ProductInfo.LaborCostPerSquareFoot}");
            //    Console.WriteLine(
            //    $"\tMaterial Cost Per Square Foot: {orderToDisplay.ProductInfo.MaterialCostPerSquareFoot}");
            //    Console.WriteLine($"\tMaterial Cost: {orderToDisplay.MaterialCost}");

            //    Console.WriteLine($"\tLabor Cost: {orderToDisplay.LaborCost}");
            //    Console.WriteLine($"\tTax: {orderToDisplay.Tax}");
            //    Console.WriteLine($"\tTotal: {orderToDisplay.Total}");
        }
예제 #7
0
 public List<Order> AddingOrder(Order anOrder)
 {
     IOrderRepo repo1 = OrderRepoFactory.GetOrderRepository();
     var AllOrders = repo1.GetOrders("06012013");
     AllOrders.Add(anOrder);
     return AllOrders;
 }
        public void AddOrderTest()
        {
            var orderRepo = new TestOrderRepository();
            Order newOrder = new Order();
            newOrder.ProductInfo = new Product();

            newOrder.OrderNumber = 4;
            newOrder.CustomerName = "Dave";
            newOrder.TaxRate = (decimal) 6.25;
            newOrder.ProductInfo.ProductType = "Wood";
            newOrder.Area = (decimal) 100.00;
            newOrder.ProductInfo.CostPerSquareFoot = (decimal) 5.15;
            newOrder.ProductInfo.LaborCostPerSquareFoot = (decimal) 4.75;
            newOrder.MaterialCost = (decimal) 515.00;
            newOrder.LaborCost = (decimal) 475.00;
            newOrder.Tax = (decimal) 61.88;
            newOrder.Total = (decimal) 1051.88;
            newOrder.State = "OH";

            orderRepo.AddOrder(newOrder, "06012014");

            var orderList = orderRepo.GetOrderInformation("06012014");
            var numOrders = orderList.Count();

            Assert.AreEqual(numOrders, 4);
        }
예제 #9
0
        public Response EditedOrder(Response orderInfo)
        {
            //var repo = new OrderRepository(); //change to interface type later
            Order newOrder = new Order
            {
                CustomerName = orderInfo.Order.CustomerName,
                Area = orderInfo.Order.Area,
                OrderNumber = orderInfo.Order.OrderNumber,
                OrderDate = orderInfo.Order.OrderDate,
                ProductType = orderInfo.Order.ProductType,
                State = orderInfo.Order.State,
                TaxRate = orderInfo.Order.TaxRate
            };
            //clean these calculations up (possibly new method?)
            decimal matCost = orderInfo.Order.Area*newOrder.ProductType.MaterialCost;
            newOrder.MaterialCost = matCost;
            decimal labCost = orderInfo.Order.Area*newOrder.ProductType.LaborCost;
            newOrder.LaborCost = labCost;
            decimal tax = (matCost + labCost)*(orderInfo.Order.TaxRate/100);
            newOrder.Tax = tax;
            newOrder.Total = matCost + labCost + tax;

            var response = new Response();

            if (true)
            {
                response.Success = true;
                response.Order = newOrder;
                return response;
            }
        }
예제 #10
0
        //public List<Order> _allOrders = new List<Order>();
        public List<Order> LoadOrders(string Orderdate)
        {
            List<Order> order = new List<Order>();

            string[] data = File.ReadAllLines(@"Data\Orders.txt");
            for (int i = 1; i < data.Length; i++)
            {
                string[] row = data[i].Split(',');

                Order toAdd = new Order();
                toAdd.OrderNumber = int.Parse(row[0]);
                toAdd.CustomerName = row[1];
                toAdd.State = row[2];
                toAdd.TaxRate = decimal.Parse(row[3]);
                toAdd.ProductType = row[4];
                toAdd.Area = decimal.Parse(row[5]);
                toAdd.CostPerSquareFoot = decimal.Parse(row[6]);
                toAdd.LaborCostPerSquareFoot = decimal.Parse(row[7]);
                toAdd.MaterialCost = decimal.Parse(row[8]);
                toAdd.LaborCost = decimal.Parse(row[9]);
                toAdd.Tax = decimal.Parse(row[10]);
                toAdd.Total = decimal.Parse(row[11]);
                toAdd.OrderDate = row[12];

                order.Add(toAdd);
            }

            return order;
        }
예제 #11
0
        public void AssignProductValues(Order order)
        {
            var product = _productRepository.GetByProduct(order.Product.ProductType);

            order.Product.CostPersquareFoot = product.CostPersquareFoot;
            order.Product.LaborCostPerSquareFoot = product.LaborCostPerSquareFoot;
        }
예제 #12
0
 public List<Order> GetOrders(string date)
 {
     //get orders from files
     List<Order> orders = new List<Order>();
     if (File.Exists(@".\Data\Orders_" + date + ".txt"))
     {
         string[] data = File.ReadAllLines(@".\Data\Orders_" + date + ".txt");
         for (int i = 0; i < data.Length; i++)
         {
             string[] row = data[i].Split(',');
             Order toAdd = new Order();
             toAdd.OrderNumber = int.Parse(row[0]);
             toAdd.CustomerName = row[1];
             toAdd.State = row[2];
             toAdd.TaxRate = decimal.Parse(row[3]);
             toAdd.ProductType = row[4];
             toAdd.Area = decimal.Parse(row[5]);
             toAdd.CostPerSquareFoot = decimal.Parse(row[6]);
             toAdd.LaborCostPerSquareFoot = decimal.Parse(row[7]);
             toAdd.MaterialCost = decimal.Parse(row[8]);
             toAdd.LaborCost = decimal.Parse(row[9]);
             toAdd.Tax = decimal.Parse(row[10]);
             toAdd.Total = decimal.Parse(row[11]);
             orders.Add(toAdd);
         }
         return orders;
     }
     else
     {
         Console.WriteLine("That order does not exist.");
         return orders;
     }
 }
예제 #13
0
        public void OrderDisplay(Order order)
        {
            Console.WriteLine(@"Order number: {0}
             Customer Name: {1}
             State: {2}
             Taxrate: {3:c}
             Product Type: {4}
             Material Cost Per Square Foot: {5:c}
             Labor Cost Per Square Foot: {6:c}
             Area: {7}
             Material Cost: {8:c}
             Labor Cost: {9:c}
             Tax: {10:C}
             Total: {11:C}"
            , order.OrderNumber, order.CustomerName, order.State, order.TaxRate, order.ProductType,
            order.MaterialCost, order.LaborCostPerSquareFoot, order.Area, order.MaterialCost,
            order.LaborCost, order.Tax, order.Total);

            Console.WriteLine("Press enter to return to main menu:");
            string we = Console.ReadLine();

            if (string.IsNullOrEmpty(we))
            {

                DisplayMenu m = new DisplayMenu();
                m.MainMenu();
            }
        }
예제 #14
0
        public void AssignStateValues(Order order)
        {
            var stateTax =_taxRepository.GetByState(order.StateTax.StateAbbreviation);

            order.StateTax.StateName = stateTax.StateName;
            order.StateTax.TaxRate = stateTax.TaxRate;
        }
예제 #15
0
 public void EditOrderTest()
 {
     // arrange
     var date = "09222015";
     var order1 = new Order();
     var manager = new OrderManager();
     order1.orderNumber = 6;
     order1.customerName = "Wise";
     order1.stateName = "OH";
     order1.taxRate = 6.25M;
     order1.productType = "Wood";
     order1.Area = 100.00M;
     order1.CostPerSquareFoot = 5.15M;
     order1.LaborCostPerSquareFoot = 4.75M;
     order1.MaterialCost = 515.00M;
     order1.LaborCost = 475.00M;
     order1.Tax = 61.88M;
     order1.Total = 1051.88M;
     // act
     manager.AddOrder(order1, date);
     order1.customerName = "Dave";
     var response = manager.EditOrder(order1, date, 6);
     var newname = response.Data.Order.customerName;
     // assert
     Assert.AreNotEqual(newname, "Wise");
 }
        public void AddOrderOpsTest()
        {
            var ops = new OrderOperations();
            Order newOrder = new Order();
            newOrder.ProductInfo = new Product();

            newOrder.OrderNumber = 4;
            newOrder.CustomerName = "Dave";
            newOrder.TaxRate = (decimal)6.25;
            newOrder.ProductInfo.ProductType = "Wood";
            newOrder.Area = (decimal)100.00;
            newOrder.ProductInfo.CostPerSquareFoot = (decimal)5.15;
            newOrder.ProductInfo.LaborCostPerSquareFoot = (decimal)4.75;
            newOrder.MaterialCost = (decimal)515.00;
            newOrder.LaborCost = (decimal)475.00;
            newOrder.Tax = (decimal)61.88;
            newOrder.Total = (decimal)1051.88;
            newOrder.State = "OH";

            ops.AddOrder(newOrder, "06012014");

            var response = ops.GetOrders("06012014");
            var orderNum = response.OrderList.Count();

            Assert.AreEqual(orderNum, 4);
        }
예제 #17
0
        public Response<Order> AddOrder(Order order, string _date)
        {
            Response<Order> response = new Response<Order>();
            Order newOrder = new Order();

            newOrder.CustomerName = order.CustomerName;
            newOrder.Area = order.Area;
            newOrder.ProductType = order.ProductType;
            newOrder.State = order.State;
            newOrder.CostPerSqFt = order.CostPerSqFt;
            newOrder.LaborCostPerSqFt = order.LaborCostPerSqFt;
            newOrder.TaxRate = order.TaxRate;
            newOrder.TotalMaterialCost = order.TotalMaterialCost;
            newOrder.TotalLaborCost = order.TotalLaborCost;
            newOrder.TotalTax = order.TotalTax;
            newOrder.Total = order.Total;

            try
            {
                var responseOrder = _orderRepo.Add(newOrder,_date);
                response.Success = true;
                response.Message = "Account Added!";
                response.Data = new List<Order> { responseOrder };
            }
            catch (Exception)
            {
                response.Success = false;
                response.Message = "ERROR, Please try again later";
            }

            return response;
        }
 public static void Execute(Order order)
 {
     CalculateMaterialCost(order);
     CalculateLaborCost(order);
     CalculateTaxCost(order);
     CalculateOrderTotal(order);
 }
예제 #19
0
        //takes new order from prompts in UI and assigns the properties to it
        public void CreateOrder(AddEntryRequest request)
        {
            Order newOrder = new Order();
            newOrder.OrderDate = request.OrderDate;
            newOrder.CustomerName = request.CustomerName;
            newOrder.State = request.State;
            //newOrder.TaxRate=a method and conditional
            newOrder.ProductType = request.ProductType;

            if (request.ProductType == "WOOD")  ////changed to newOrder.Product Type
            {
                newOrder.CostPerSquareFoot = 5.15m;
                newOrder.LaborCostPerSquareFoot = 4.75m;
            }
            else if (request.ProductType == "TILE")  // added else if; CHANGED PRODUCT NAMES TO CAPS
            {
                newOrder.CostPerSquareFoot = 3.50m;
                newOrder.LaborCostPerSquareFoot = 4.15m;
            }
            else if (request.ProductType == "CARPET") // added else if; CHANGED PRODUCT NAMES TO CAPS
            {
                newOrder.CostPerSquareFoot = 2.25m;
                newOrder.LaborCostPerSquareFoot = 2.10m;
            }
            else
            {
                newOrder.CostPerSquareFoot = 1.75m;
                newOrder.LaborCostPerSquareFoot = 2.10m;
            }

            newOrder.Area = request.Area;
            /////////////////////////////
            if (request.State == "OH")
            {
                newOrder.TaxRate = 0.0625M;
                // taxRateOperations.IsAllowedState("OH");

            }
            else if (request.State == "PA")///made them else if
            {
                newOrder.TaxRate = 0.0675M;
            }
            else if (request.State == "MI")// made this else if
            {
                newOrder.TaxRate = 0.0575M;
            }
            else
            {
                newOrder.TaxRate = 0.06M;
            }
            newOrder.MaterialCost = (newOrder.Area * newOrder.CostPerSquareFoot);
            newOrder.LaborCost = (newOrder.Area * newOrder.LaborCostPerSquareFoot);
            newOrder.Tax = (newOrder.Area * newOrder.TaxRate);//Addded this line to calculate total tax
            newOrder.Total = ((newOrder.MaterialCost + newOrder.LaborCost + newOrder.Tax));//changed this line to incorporate tax in the total

            ListofOrders.Add(newOrder);//add my newly created order to my list.
            WriteToFile(ListofOrders);//send my new list with orders from the file and newly added orders and send it my
                                      //writetofile to send my list to the file again.
        }
예제 #20
0
        public Response EditOrder(Order newOrder, string date)
        {
            Response response = new Response();

                _repo.EditOrder(newOrder, date);
                response.Message = "Order has been updated.";
                return response;
        }
예제 #21
0
        public void AddOrder(Order order)
        {
            // check if the tax rate is good
            // check if the product is good
            // do the calculations

            _orderRepository.AddOrderToRepository(order);
        }
        public void AssignOrderNumberTest()
        {
            Order order = new Order();
            order.Date = new DateTime(2013, 06, 01);

            order = OrderOperations.AssignOrderNumber(order);
            int numberOfOrders = OrderOperations.GetOrdersByDate(new DateTime(2013, 06, 01)).Count;

            Assert.AreEqual(order.Number, numberOfOrders + 1);
        }
        public void CalculateRemainingOrderFieldsTest(string state, string productType, decimal area, decimal expectedTotal)
        {
            Order orderToTest = new Order();
            orderToTest.State = state;
            orderToTest.ProductType = productType;
            orderToTest.Area = area;
            orderToTest = OrderOperations.CalculateRemainingOrderFields(orderToTest);

            Assert.AreEqual(expectedTotal, decimal.Round(orderToTest.Total, 2));
        }
예제 #24
0
        public void AddOrderWithValidState()
        {
            TaxManager om = new TaxManager(new MockStateTaxRepository());
            Order order = new Order();
            order.StateTax.StateAbbreviation = "OH";
            var response = om.AddState(order);

            Assert.AreEqual(true, response.Success);
            Assert.AreEqual(AddOrderStatus.Ok, response.Status);
        }
        public void AddOrderNumber(Order newOrder)
        {
            var allOrders = repo.LoadAll(newOrder.OrderDate);
            newOrder.OrderNumber = allOrders.Max(o => o.OrderNumber) + 1;

            allOrders.Add(newOrder);
            orderDate = newOrder.OrderDate;
            FileName = "Orders_" + orderDate + ".txt";
            SaveListToFile(allOrders);
        }
예제 #26
0
        public void AddProductWithValidProductType()
        {
            ProductManager om = new ProductManager(new MockProductRepository());
            Order order = new Order();
            order.Product.ProductType = "Wood";
            var response = om.AddProduct(order);

            Assert.AreEqual(true, response.Success);
            Assert.AreEqual(AddOrderStatus.Ok, response.Status);
        }
예제 #27
0
        public void CheckDeleteOrder()
        {
            TestSetUp();

            repo.DeleteOrder(2, date);

            Order order = new Order();
            order = repo.LoadOrder(2, date);

            Assert.IsNull(order);
        }
예제 #28
0
        public MockOrderRepository()
        {
            string _filePath = @"DataFiles\Orders_12122054.txt";

            GetProducts();

            //need to check if filepath is null!!
            var reader = File.ReadAllLines(_filePath);

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

                var order = new Order();
                order.ProductType = new ProductTypes();

                order.OrderNumber = int.Parse(columns[0]);

                for (int j = 1; j < columns.Count() - 11; j++)
                {
                    order.CustomerName += columns[j] + ",";
                }
                order.CustomerName += columns[columns.Count() - 11];

                order.State = columns[columns.Count() - 10];
                order.TaxRate = decimal.Parse(columns[columns.Count() - 9]);
                order.ProductType.ProductType = (columns[columns.Count() - 8]);
                order.Area = decimal.Parse(columns[columns.Count() - 7]);
                order.ProductType.MaterialCost = decimal.Parse(columns[columns.Count() - 6]);
                order.ProductType.LaborCost = decimal.Parse(columns[columns.Count() - 5]);
                order.MaterialCost = decimal.Parse(columns[columns.Count() - 4]);
                order.LaborCost = decimal.Parse(columns[columns.Count() - 3]);
                order.Tax = decimal.Parse(columns[columns.Count() - 2]);
                order.Total = decimal.Parse(columns[columns.Count() - 1]);

                order.OrderDate = (_filePath.Substring(17, 8));

                Orders.Add(order);
            }

            var results =
                Orders.OrderBy(o => o.OrderDate)
                    .GroupBy(o => o.OrderDate)
                    .Select(dateOrders => new {Date = dateOrders.Key, Orders = dateOrders});

            foreach (var result in results)
            {
                allOrdersOnDate.Add(result.Date, new List<Order>(result.Orders));
            }
        }
예제 #29
0
 public void Execute(OrderOperations orderOps)
 {
     _orderOps = orderOps;
     _newOrder = new Order();
     _newOrder.ProductInfo = new Product();
     GetCustomerNameFromUser();
     GetCustomerState();
     GetProductType();
     GetArea();
     BuildOrder();
     DisplayNewOrder();
 }
예제 #30
0
 public static void AddOrder(Order orderToAdd)
 {
     try
     {
         Repo.AddOrder(orderToAdd);
     }
     catch (Exception e)
     {
         Logger.Log(e.Message);
         throw new Exception("\tThere was an error adding your order:\n\t" + e.Message);
     }
 }