public decimal CalculateTax(OrderRequest orderRequest)
        {
            decimal totalPreTax = orderRequest.Order.TotalLaborCost + orderRequest.Order.MaterialCost;
            decimal total = totalPreTax * (orderRequest.Order.TaxRate/100);

            return total;
        }
        public void GetTaxSuccess()
        {
            var ops = OperationsFactory.CreateTaxOperations();
            var request = new OrderRequest()
            {
                OrderDate = new DateTime(2015, 06, 27),
                Order = new Order()
                {
                    OrderNumber = 1,
                    CustomerName = "Lacy",
                    Area = 10,
                    ProductType = "Hardwood",
                    StateAbbreviation = "OH",
                    CostPerSquareFoot = 7.55M,
                    LaborCostPerSquareFoot = 4.12M,
                    MaterialCost = 75.5M,
                    TotalLaborCost = 41.2M,
                    TotalTax = 7.59M
                }

            };
            var response = ops.GetTax(request);
            var item = response.Data.TaxRate;
            Assert.IsTrue(response.Success);
            Assert.AreEqual(0.065M,item);
        }
        public void GetTaxFailure()
        {
            var ops = OperationsFactory.CreateTaxOperations();
            var request = new OrderRequest()
            {
                OrderDate = new DateTime(2015, 06, 27),
                Order = new Order()
                {
                    OrderNumber = 1,
                    CustomerName = "Lacy",
                    Area = 10,
                    ProductType = "Hardwood",
                    StateAbbreviation = "TX",
                    CostPerSquareFoot = 7.55M,
                    LaborCostPerSquareFoot = 4.12M,
                    MaterialCost = 75.5M,
                    TotalLaborCost = 41.2M,
                    TotalTax = 7.59M
                }

            };
            var response = ops.GetTax(request);
            Assert.IsFalse(response.Success);
            Assert.AreEqual("Invalid state entered",response.Message);
        }
        public Response<Order> CreateOrder(OrderRequest orderToAddRequest)
        {
            var response = new Response<Order>();
            try
            {
                var orders = _orderRepo.ListAll(orderToAddRequest.OrderDate);

                if (orderToAddRequest.Order.OrderNumber == 0)
                {
                   orderToAddRequest.Order.OrderNumber = GenerateOrderNumber(orders);
                }

                orderToAddRequest = GetTaxRate(orderToAddRequest);
                orderToAddRequest = UpdateCosts(orderToAddRequest);
                _orderRepo.Add(orderToAddRequest);

                response.Success = true;
                response.Data = orderToAddRequest.Order;

            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return response;
        }
Exemplo n.º 5
0
 public Order GetOrder(OrderRequest orderRequest)
 {
     var orders = ListAll(orderRequest.OrderDate);
     var selectedOrder = orders.First(x => x.OrderNumber == orderRequest.Order.OrderNumber);
     //needs to handle an exception, but I'm not sure why it is throwing this one.
     return selectedOrder;
 }
Exemplo n.º 6
0
 public Order EditOrder(OrderRequest updatedOrderRequest, OrderRequest previousOrderRequest)
 {
     RemoveOrder(previousOrderRequest);
     Add(updatedOrderRequest);
     var order = GetOrder(updatedOrderRequest);
     return order;
 }
        public Response<Order> DeleteOrder(OrderRequest request)
        {
            var response = new Response<Order>();
            var orderRepo = new OrderRepository();

            var listAll = orderRepo.ListAll(request.OrderDate);

            try
            {
                if (listAll.Count > 0)
                {
                    var orderInformation = listAll.First(x => x.OrderNumber == request.Order.OrderNumber);
                    response.Data = orderInformation;
                    orderRepo.RemoveOrder(request);
                    response.Success = true;
                    response.Message = "Order successfully deleted!";
                }
                else
                {

                    response.Success = false;
                    response.Message = "There are no orders to delete for this date";
                }

            }

            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }

            return response;
        }
 public void Execute()
 {
     var request = new OrderRequest();
     Screens.ShowRemoveAnOrder();
     request = OrderToRemoveInformation();
     ConfirmRemoval(request);
     UserInteractions.PressKeyToContinue();
 }
 public void Execute()
 {
     var request = new OrderRequest();
     Screens.ShowAddOrder();
     request = GenerateOrderInformation(request);
     ConfirmAddOrder(request);
     UserInteractions.PressKeyToContinue();
 }
        public OrderRequest OrderToRemoveInformation()
        {
            var request = new OrderRequest();
            request = UserInteractions.PromptForValidOrderDate(request);
            request.Order = new Order();
            request = UserInteractions.PromptForValidOrderNumber(request);

            return request;
        }
        public Response<Order> RemoveOrder(OrderRequest request)
        {
            var ops = OperationsFactory.CreateOrderOperations();
            var response = ops.DeleteOrder(request);

            Console.Clear();

            return response;
        }
 public void CreateOrderSuccess()
 {
     var repo = new OrderRepository();
     var request = new OrderRequest();
     request.Order = new Order();
     request.Order.CustomerName = "K LittleJ";
     repo.Add(request);
     var order = repo.GetOrder(request);
     Assert.AreEqual("K LittleJ",order.CustomerName);
 }
        public void Execute()
        {
            OrderRequest oldOrderRequest = new OrderRequest();
            OrderRequest newOrderRequest = new OrderRequest();
            oldOrderRequest = SetUpOrderRequest(oldOrderRequest);

            newOrderRequest = MakeEdits(oldOrderRequest);
            ConfirmEdits(oldOrderRequest, newOrderRequest);
            UserInteractions.PressKeyToContinue();
        }
        public OrderRequest SetUpOrderRequest(OrderRequest orderRequest)
        {
            var orderDate = UserInteractions.PromptForValidOrderDate(orderRequest);

            orderRequest.OrderDate = orderDate.OrderDate;
            orderRequest.Order = new Order();
            orderRequest = UserInteractions.PromptForValidOrderNumber(orderRequest);

            return orderRequest;
        }
Exemplo n.º 15
0
        public OrderRequest CreateRequest(OrderRequest request)
        {
            request.OrderDate = DateTime.Today;
            request.Order = new Order();
            request.Order.CustomerName = UserInteractions.PromptForRequiredString("Enter Customer Name: ");
            request.Order.StateAbbreviation = UserInteractions.PromptForValidState("Enter two-letter state abbreviation: ");
            request.Order.Area = UserInteractions.PromptForDecimal("Enter area in square feet: ");
            request.Order.ProductType = UserInteractions.PromptForRequiredString("Enter a product type: ");

            return request;
        }
Exemplo n.º 16
0
        public void Add(OrderRequest orderToAddRequest)
        {
            var orders = ListAll(orderToAddRequest.OrderDate);

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

            orders.Add(orderToAddRequest.Order);

            OverwriteFile(orders, orderToAddRequest.OrderDate);
        }
        public void GetOrderSuccess()
        {
            var repo = new OrderRepository();
            var request = new OrderRequest();
            request.Order = new Order();
            request.OrderDate = new DateTime(2015,02,24);
            request.Order.OrderNumber = 1;
            var order = repo.GetOrder(request);

            Assert.AreEqual(1, order.OrderNumber);
            Assert.AreEqual("Diedre Douglas", order.CustomerName);
        }
Exemplo n.º 18
0
        public OrderRequest OrderToRemoveInformation()
        {
            var request = new OrderRequest();

            string message = "Please enter an order date in this format(MM/DD/YYYY): ";
            DateTime orderDate = UserInteractions.PromptForDate(message);
            request.OrderDate = orderDate;
            request.Order = new Order();
            Console.WriteLine("Please enter an order number");
            request.Order.OrderNumber = int.Parse(Console.ReadLine());

            return request;
        }
 public void ConfirmAddOrder(OrderRequest request)
 {
     var ops = OperationsFactory.CreateOrderOperations();
     request = ops.GetTaxRate(request);
     request = ops.UpdateCosts(request);
     Screens.ShowConfirmAddOrder(request.Order);
     var confirm = UserInteractions.PromptForConfirmation("Add Order? (Y)es or (N)o.");
     if (confirm == "Y")
     {
         var response = SaveOrderInformation(request);
         Screens.ShowAddOrderConfirmation(response.Data);
     }
 }
Exemplo n.º 20
0
        public List<Order> RemoveOrder(OrderRequest orderToDeleteRequest)
        {
            string orderDate = orderToDeleteRequest.OrderDate.ToString("mmddyyyy");
            var orders = GetAllOrders(orderDate);

            if (orders != null)
            {
                var orderToReplace = orders.FirstOrDefault(x => x.OrderNumber == orderToDeleteRequest.Order.OrderNumber);
                orders.Remove(orderToReplace);
                //TODO: delete the file if there are no more orders
            }

            OverWriteFile(orders, orderDate);
            return orders;
        }
        public OrderRequest GenerateOrderInformation(OrderRequest request)
        {
            request.OrderDate = DateTime.Today;
            Console.WriteLine("Order Date: {0}", request.OrderDate.ToString("D"));
            request.Order = new Order();

            //user requested
            Console.Write("Please enter your name: ");
            request.Order.CustomerName = Console.ReadLine();
            request.Order.StateAbbreviation = UserInteractions.PromptForValidState("Please enter your state: ");
            request.Order.ProductType = UserInteractions.PromptForValidProductType("Please enter your product type: ");
            request.Order.Area = UserInteractions.PromptForDecimal("Please enter the area: ");

            return request;
        }
Exemplo n.º 22
0
 public void Execute()
 {
     Display.ShowAddOrder();
     OrderRequest request = new OrderRequest();
     OrderRequest filledRequest = CreateRequest(request);
     string answer = UserInteractions.PromptUserForConfirmation("Do you wish to save this order?  Y or N: ");
     if (answer == "Y")
     {
         SubmitRequest(filledRequest);
     }
     else
     {
         var menu = new MainMenu();
         menu.Execute();
     }
 }
 public void ConfirmRemoval(OrderRequest request)
 {
     var ops = OperationsFactory.CreateOrderOperations();
     Screens.ShowConfirmRemoveOrder(request.Order);
     var confirm = UserInteractions.PromptForConfirmation("Remove Order? (Y)es or (N)o.");
     var response = new Response<Order>();
     if (confirm == "Y")
     {
         response = RemoveOrder(request);
         Screens.ShowRemoveOrderConfirmation(response.Data);
     }
     else
     {
         Console.WriteLine("Order not deleted");
     }
 }
Exemplo n.º 24
0
        private void SubmitRequest(OrderRequest request)
        {
            var ops = OperationsFactory.CreateOrderOperations();
            Response < Order > placedOrder = ops.AddOrder(request);

            if (placedOrder.Success)
            {
                Display.ShowAddOrderConfirmation(placedOrder.Data);
                UserInteractions.PressKeyToContinue();
            }
            else
            {
                Display.ShowAddOrderFailed(placedOrder);
                UserInteractions.PressKeyToContinue();
            }
        }
Exemplo n.º 25
0
        public void RemoveOrder(OrderRequest request)
        {
            var ops = OperationsFactory.RemoveOrderOperations();
            var response = ops.DeleteOrder(request);

            Console.Clear();
            if (response.Success)
            {
                Console.WriteLine(response.Message);
                UserInteractions.PressKeyToContinue();
            }
            else
            {
                Console.WriteLine(response.Message);
                UserInteractions.PressKeyToContinue();
            }
        }
Exemplo n.º 26
0
        public Response<Order> AddOrder(OrderRequest request)
        {
            var response = new Response<Order>();

            try
            {
                var orders = _orderRepo.ListAll(request.OrderDate);

                int orderNumber = 0;

                if (orders != null)
                    orderNumber = orders.Max(o => o.OrderNumber);

                //Actually, you need to see if there are any orders.  Add one to the highest order number
                orderNumber++;

                request.Order.OrderNumber = orderNumber;

                var tax = OperationsFactory.CreateTaxOperations();

                request.Order.TaxRate = tax.GetRate(request.Order.StateAbbreviation);

                var costs = OperationsFactory.CreateProductOperations();
                request.Order.LaborCostPerSquareFoot = costs.GetLaborCostPerSquareFoot(request.Order.ProductType);
                request.Order.CostPerSquareFoot = costs.GetCostPerSquareFoot(request.Order.ProductType);

                request.Order.MaterialCost = (request.Order.Area)*(request.Order.CostPerSquareFoot);

                request.Order.LaborCost = (request.Order.Area)*(request.Order.LaborCostPerSquareFoot);

                request.Order.Tax = ((request.Order.MaterialCost + request.Order.LaborCost)*request.Order.TaxRate);

                request.Order.Total = (request.Order.MaterialCost + request.Order.LaborCost + request.Order.Tax);

                _orderRepo.Add(request);

                response.Success = true;
                response.Data = request.Order;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return response;
        }
 public void ConfirmEdits(OrderRequest oldOrderRequest, OrderRequest newOrderRequest)
 {
     var ops = OperationsFactory.CreateOrderOperations();
     newOrderRequest = ops.GetTaxRate(newOrderRequest);
     newOrderRequest = ops.UpdateCosts(newOrderRequest);
     Screens.ShowEditOrderConfirmation(newOrderRequest.Order);
     var confirm = UserInteractions.PromptForConfirmation("Save requested changes to order? (Y)es or (N)o.");
     var response = new Response<Order>();
     if (confirm == "Y")
     {
         response = ops.EditSelectedOrder(oldOrderRequest, newOrderRequest);
         Screens.ShowEditOrderConfirmation(response.Data);
     }
     else
     {
         Console.WriteLine("Changes not saved");
     }
 }
        public Order GetOrder(OrderRequest orderRequest)
        {
            var orders = ListAll(orderRequest.OrderDate);
            try
            {
                if (orders != null)
                {
                    var selectedOrder = orders.First(x => x.OrderNumber == orderRequest.Order.OrderNumber);
                    return selectedOrder;

                }
            }
            catch (Exception)
            {

                return null;
            }
            return null;
        }
        public void CalculateMaterialCostSuccess()
        {
            var ops = OperationsFactory.CreateProductOperations();
            var request = new OrderRequest()
            {
                OrderDate = new DateTime(2015, 06, 27),
                Order = new Order()
                {
                    OrderNumber = 1,
                    CustomerName = "Lacy",
                    Area = 10,
                    ProductType = "Laminate",

                }

            };
            request.Order.CostPerSquareFoot = ops.GetCostPerSquareFoot(request.Order.ProductType);
            decimal cost = ops.CalculateMaterialCost(request);
            Assert.AreEqual(54.8, cost);
        }
Exemplo n.º 30
0
        public void Execute()
        {
            //get orderDate from user
            //get orderNumber from user
            //display only that order to user using PrintOrderDetails
            OrderRequest newOrderRequest = new OrderRequest();
            OrderOperations ops = OperationsFactory.EditOrderOperations();
            string message = "Please enter an order date in this format(MM/DD/YYYY): ";
            DateTime orderDate = UserInteractions.PromptForDate(message);

            //set up new order
            newOrderRequest.OrderDate = orderDate;
            newOrderRequest.Order = new Order();

            Console.Write("Please enter your order number: ");
            var orderNumber = Console.ReadLine();
            newOrderRequest.Order.OrderNumber = int.Parse(orderNumber);

            //set up old order
            OrderRequest oldOrderRequest = new OrderRequest();
            oldOrderRequest.OrderDate = orderDate;
            oldOrderRequest.Order = new Order();
            oldOrderRequest.Order.OrderNumber = int.Parse(orderNumber);
            Response<Order> oldOrderResponse = ops.GetSelectedOrder(oldOrderRequest);
            oldOrderRequest.Order = oldOrderResponse.Data;

            PrintOrderDetails(oldOrderResponse);
            Console.WriteLine();

            //edit order details
            newOrderRequest = MakeEdits(oldOrderRequest);
            Response<Order> editedOrdeResponse = ops.EditSelectedOrder(newOrderRequest, oldOrderRequest);

            //save response to file
            UserInteractions.PressKeyToContinue();
            PrintOrderDetails(editedOrdeResponse);
            UserInteractions.PressKeyToContinue();
        }