Exemplo n.º 1
0
 public void DeleteOrder(Response order)
 {
     string filePath = (String.Format(@"DataFiles\Orders_{0}.txt", order.Order.OrderDate));
     var orders = GetAllOrders(order.Order.OrderDate);
     if (orders.Count == 1)
     {
         File.Delete(filePath);
     }
     else
     {
         orders = orders.Where(a => a.OrderNumber != order.Order.OrderNumber).ToList();
         //orders.Remove(orderToRemove);
         using (var writer = File.CreateText(filePath))
         {
             writer.WriteLine("OrderNumber,CustomerName,State,TaxRate,ProductType,Area,CostPerSquareFoot,LaborCostPerSquareFoot,MaterialCost,LaborCost,Tax,Total");
             foreach (var newo in orders)
             {
                 writer.WriteLine("\n{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11}", newo.OrderNumber,
                newo.CustomerName, newo.State, newo.TaxRate, newo.ProductType.ProductType, newo.Area,
                newo.ProductType.MaterialCost, newo.ProductType.LaborCost, newo.MaterialCost, newo.LaborCost, newo.Tax,
                newo.Total);
             }
         }
     }
 }
Exemplo n.º 2
0
 public void ReturnEdit()
 {
     string expected = "Sam";
     Response orderInfo = new Response();
     orderInfo.Success = true;
     orderInfo.Message = "Hi";
     orderInfo.Order = new Order
     {
         OrderNumber = 4,
         CustomerName = "Willie",
         State = "OH",
         TaxRate = (decimal)6.25,
         ProductType = new ProductTypes
         {
             ProductType = "Wood",
             MaterialCost = (decimal)5.15,
             LaborCost = (decimal)4.75
         },
         Area = 100,
         MaterialCost = (decimal)515.00,
         LaborCost = (decimal)475.00,
         Tax = (decimal)61.875000,
         Total = (decimal)1051.875000
     };
     Target.ChangeOrder(orderInfo);
     Assert.AreNotEqual(orderInfo.Order.CustomerName, expected);
 }
Exemplo n.º 3
0
 public Response<DisplayOrderReceipt> DisplayOrders(string date)
 {
     var response = new Response<DisplayOrderReceipt>();
     var repo = _repo;
     var orders = repo.LoadOrders(date);
     try
     {
         if (orders.Count == 0)
         {
             response.Success = false;
             response.Message = "No orders were found with that date.";
         }
         else
         {
             response.Success = true;
             response.Data = new DisplayOrderReceipt();
             response.Data.Date = int.Parse(date);
             response.Data.Orders = orders;
         }
     }
     catch (Exception ex)
     {
         response.Success = false;
         response.Message = ex.Message;
     }
     return response;
 }
Exemplo n.º 4
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;
        }
Exemplo n.º 5
0
 public void ReturnRemove()
 {
     int expected = 3;
     Response orderInfo = new Response();
     orderInfo.Success = true;
     orderInfo.Message = "Hi";
     orderInfo.Order = new Order
     {
         OrderNumber = 4,
         CustomerName = "Sam",
         State = "OH",
         TaxRate = (decimal)6.25,
         ProductType = new ProductTypes
         {
             ProductType = "Wood",
             MaterialCost = (decimal)5.15,
             LaborCost = (decimal)4.75
         },
         Area = 100,
         MaterialCost = (decimal)515.00,
         LaborCost = (decimal)475.00,
         Tax = (decimal)61.875000,
         Total = (decimal)1051.875000
     };
     Target.DeleteOrder(orderInfo);
     int result = Target.GetAllOrders("12122054").Count;
     Assert.AreEqual(expected, result);
 }
Exemplo n.º 6
0
        public Response GetSpecificOrder(string date, int orderNum)
        {
            Response response = new Response();
            response = GetOrders(date);

            if (response.Success == false)
            {
                return response;
            }
            else
            {
                var result = response.OrderList.Any(n => n.OrderNumber == orderNum);
                if (!result)
                {
                    response.Message = "Your order number cannot be found.";
                    response.Success = false;
                    return response;
                }
                else
                {
                    IEnumerable<Order> specificOrder = (from o in response.OrderList
                        where o.OrderNumber == orderNum
                        select o).ToList();

                    response.OrderList.Clear();
                    foreach (var order in specificOrder)
                    {
                        response.OrderList.Add(order);
                    }
                    return response;
                }
            }
        }
Exemplo n.º 7
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;
            }
        }
Exemplo n.º 8
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;
            }
        }
Exemplo n.º 9
0
        public Response EditOrder(Order newOrder, string date)
        {
            Response response = new Response();

                _repo.EditOrder(newOrder, date);
                response.Message = "Order has been updated.";
                return response;
        }
Exemplo n.º 10
0
 public void ConfirmFinalLastEdit(Response response)
 {
     Console.Write("Do you wish to save these changes to the order (y/n) ? : ");
     var input = Console.ReadLine();
     if (input != null && (input.ToUpper() == "Y" || input.ToUpper() == "YES"))
     {
         Ops.PassEditBll(response);
     }
     else
     {
         Console.WriteLine("No changes will be made to this order.");
         Console.WriteLine("Press enter to return to main menu");
         Console.ReadLine();
     }
 }
Exemplo n.º 11
0
        public Response<Order> AddOrder(Order order, DateTime date)
        {
            var repo = new OrderRepository();
            var response = new Response<Order>();

            if (repo.FileExists(date))
            {
                order.OrderNumber = repo.HighestOrderNumber(date) + 1;

                try
                {
                    repo.CreateOrder(order, date);

                    response.Success = true;

                    response.Data = order;
                }
                catch (Exception ex)
                {
                    response.Success = false;
                    response.Message = "There was an error adding the order: " + ex.Message;
                    repo.ErrorLogger(ex.Message);
                }

                return response;
            }

            else
            {
                order.OrderNumber = 1;

                try
                {
                    repo.CreateFile(date);
                    repo.CreateOrder(order, date, true);
                    response.Success = true;
                    response.Data = order;
                }
                catch (Exception ex)
                {
                    response.Success = false;
                    response.Message = "There was an error adding the order: " + ex.Message;
                    repo.ErrorLogger(ex.Message);
                }

                return response;
            }
        }
Exemplo n.º 12
0
        public Response<Order> DeleteOrder(Order order, string _date)
        {
            Response<Order> response = new Response<Order>();

            try
            {
                _orderRepo.Remove(order, _date);
                response.Success = true;
                response.Message = "Account Edited!";
                response.Data = new List<Order> { order };
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = "There was an unexpected error. Please try again later. " + ex;
            }

            return response;
        }
Exemplo n.º 13
0
        public Response GetOrders(string date)
        {
            var response = new Response();

            var orders = _repo.GetOrderInformation(date);

            if (!orders.Any())
            {
                response.Success = false;
                response.Message = "There are no orders from this date.";
            }
            else
            {
                response.Success = true;
                response.OrderList = orders;
            }

            return response;
        }
Exemplo n.º 14
0
        public void DisplayOrder(Response response)
        {
            if (response.Success)
            {
                Console.Clear();
                Console.WriteLine("Order date : {0}/{1}/{2}", response.Order.OrderDate.Substring(0, 2),
                    response.Order.OrderDate.Substring(2, 2), response.Order.OrderDate.Substring(4));
                Console.WriteLine("Order number {0:0000}", response.Order.OrderNumber);
                Console.WriteLine("\nCustomer name : {0}", response.Order.CustomerName);
                Console.WriteLine("Area : {0} sq ft", response.Order.Area);
                Console.WriteLine("Product type : {0}", response.Order.ProductType.ProductType);
                Console.WriteLine("Material cost per sq ft : {0:c}", response.Order.ProductType.MaterialCost);
                Console.WriteLine("Labor cost per sq ft : {0:c}", response.Order.ProductType.LaborCost);
                Console.WriteLine("Total material cost : {0:c}", response.Order.MaterialCost);
                Console.WriteLine("Total labor cost : {0:c}", response.Order.LaborCost);
                Console.WriteLine("{0} state tax ({1:p}) : {2:c}", response.Order.State, response.Order.TaxRate / 100,
                    response.Order.Tax);
                Console.WriteLine("\nOrder total : {0:c}", response.Order.Total);
                Console.WriteLine();
                Console.WriteLine();

                ConfirmUserCommit(response);

                //method to take this input and use it to either write on the data or not
            }
            if (!response.Success)
            {
                var log = new ErrorLogger()
                {
                    TimeOfError = DateTime.Now,
                    Message = String.Format("RemoveOrder : order does not exist on selected day : {0}", response.Message)
                };
                Ops.ErrorPassdown(log);

                Console.Clear();
                Console.WriteLine("There were no orders matching that data...");
                Console.WriteLine("Press enter to return to main menu");
                Console.ReadLine();
            }
        }
Exemplo n.º 15
0
        public Response ConfirmUserEdit(Response orderInfo)
        {
            Console.Write("Is this the order you wish to edit (y/n) ? : ");
            string input = Console.ReadLine();

            if (input != null && (input.ToUpper() == "Y" || input.ToUpper() == "YES"))
            {
                GetNewUserName(orderInfo);
                GetNewUserState(orderInfo);
                GetNewUserProductType(orderInfo);
                GetNewUserArea(orderInfo);
                Response response = Ops.EditedOrder(orderInfo);
                return response;
            }
            else
            {
                Console.WriteLine("No changes will be made to this order.");
                Console.WriteLine("Press enter to return to main menu");
                Console.ReadLine();
                return null;
            }
        }
Exemplo n.º 16
0
        public void ConfirmUserCommit(Response orderInfo)
        {
            Console.Write("Are you sure you would like to delete this order (y/n) ? : ");
            string input = Console.ReadLine();

            if (input != null && (input.ToUpper() == "Y" || input.ToUpper() == "YES"))
            {
                var uiOrder = orderInfo;

                // this method will pass order info to the BLL
                Ops.PassRemoveFromData(uiOrder);
                Console.WriteLine("Your order has been successfully removed!");
                Console.WriteLine("Press enter to return to main menu");
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine("Order not removed!");
                Console.WriteLine("Press enter to return to main menu");
                Console.ReadLine();
            }
        }
Exemplo n.º 17
0
        public void ConfirmUserCommit(Response orderInfo)
        {
            Console.Write("Do you want to commit these changes to memory (y/n) ? : ");
            string input = Console.ReadLine();

            if (input != null && (input.ToUpper() == "Y" || input.ToUpper() == "YES"))
            {
                var uiOrder = orderInfo;

                // this method will pass order info to the BLL
                Ops.PassAddToData(uiOrder);
                Console.WriteLine("Your order has been saved successfully!");
                Console.WriteLine("Press enter to return to main menu");
                Console.ReadLine();
            }
            else
            {
                Console.WriteLine("Changes not saved!");
                Console.WriteLine("Press enter to return to main menu");
                Console.ReadLine();
            }
        }
Exemplo n.º 18
0
 public Response<AddOrderReceipt> AddOrder(Order order, string date)
 {
     var response = new Response<AddOrderReceipt>();
     response.Data = new AddOrderReceipt();
     var repo = _repo;
     var orders = _repo.LoadOrders(date);
     var taxes = _taxrepo.LoadTaxRate();
     var products = _productrepo.LoadProductType();
     try
     {
         var highAccountNum = 0;
         if (orders.Count > 0)
         {
             highAccountNum = orders.Select(a => a.orderNumber).Max();
         }
         order.orderNumber = highAccountNum + 1;
         var taxrate = taxes.First(a => a.StateAbbreviation == order.stateName);
         order.taxRate = taxrate.TaxRate;
         var producttype = products.First(a => a.ProductType == order.productType);
         order.CostPerSquareFoot = producttype.CostPerSquareFoot;
         order.LaborCostPerSquareFoot = producttype.LaborCostPerSquareFoot;
         order = SetDerivedOrderInfo(order);
         orders.Add(order);
         repo.OverWriteFileWithOrder(orders, date);
         response.Success = true;
         response.Data = new AddOrderReceipt();
         response.Data.Date = int.Parse(date);
         response.Data.Orders = orders;
         response.Data.Order = order;
     }
     catch (Exception ex)
     {
         response.Success = false;
         response.Message = ex.Message;
     }
     return response;
 }
Exemplo n.º 19
0
        public Response EditOrder(string orderDate, int orderNumber)
        {
            //var repo = new OrderRepository();
            var currentOrder = _repo.CheckForOrder(orderDate, orderNumber);

            var response = new Response();
            if (currentOrder != null)
            {
                response.Success = true;
                response.Message = "We found an order matching that data.";
                response.Order = currentOrder;
                return response;
            }
            else
            {
                response.Success = false;
                response.Message = "We did not find an order matching that data.";
                return response;
            }
        }
Exemplo n.º 20
0
        public Response DisplayOrder(Response response)
        {
            if (response.Success)
            {
                Console.Clear();
                Console.WriteLine("Order date : {0}/{1}/{2}", response.Order.OrderDate.Substring(0, 2),
                    response.Order.OrderDate.Substring(2, 2),
                    response.Order.OrderDate.Substring(4));
                Console.WriteLine("Order number {0:0000}", response.Order.OrderNumber);
                Console.WriteLine("\nCustomer name : {0}", response.Order.CustomerName);
                Console.WriteLine("Area : {0} sq ft", response.Order.Area);
                Console.WriteLine("Product type : {0}", response.Order.ProductType.ProductType);
                Console.WriteLine("Material cost per sq ft : {0:c}", response.Order.ProductType.MaterialCost);
                Console.WriteLine("Labor cost per sq ft : {0:c}", response.Order.ProductType.LaborCost);
                Console.WriteLine("Total material cost : {0:c}", response.Order.MaterialCost);
                Console.WriteLine("Total labor cost : {0:c}", response.Order.LaborCost);
                Console.WriteLine("{0} state tax ({1:p}) : {2:c}", response.Order.State, response.Order.TaxRate/100,
                    response.Order.Tax);
                Console.WriteLine("\nOrder total : {0:c}", response.Order.Total);
                Console.WriteLine();
                Console.WriteLine();

                Response orderToEdit = ConfirmUserEdit(response);
                return orderToEdit;

                //method to take this input and use it to either write on the data or not
            }
            if (!response.Success)
            {
                var log = new ErrorLogger()
                {
                    TimeOfError = DateTime.Now,
                    Message = $"EditOrder : error displaying order data from selected date : {response.Message}"
                };
                Ops.ErrorPassdown(log);

                Console.Clear();
                Console.WriteLine("There was an error");
                Console.WriteLine("Press enter to return to main menu");
                Console.ReadLine();

            }
            return null;
        }
Exemplo n.º 21
0
        public Response<Order> EditOrder(Order order, string _date)
        {
            Response<Order> response = new Response<Order>();

            order.TotalMaterialCost = order.Area * order.CostPerSqFt;
            order.TotalLaborCost = order.Area * order.LaborCostPerSqFt;
            order.TotalTax = order.TaxRate / 100m * (order.TotalMaterialCost + order.TotalLaborCost);
            order.Total = order.TotalMaterialCost + order.TotalLaborCost + order.TotalTax;

            try
            {
                _orderRepo.Edit(order,_date);
                response.Success = true;
                response.Message = "Account Edited!";
                response.Data = new List<Order> {order};
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = "There was an unexpected error. Please try again later. " + ex;
            }

            return response;
        }
Exemplo n.º 22
0
        public void PassRemoveFromData(Response response)
        {
            var bllRemoveOrder = response;

            //var repo = new OrderRepository();
            _repo.DeleteOrder(bllRemoveOrder);
        }
Exemplo n.º 23
0
 public void PassEditBll(Response response)
 {
     //var repo = new OrderRepository();
     _repo.ChangeOrder(response);
 }
Exemplo n.º 24
0
        public void PassAddToData(Response orderInfo)
        {
            var bllOrder = orderInfo;

            //var or = new OrderRepository();

            //this method actually writes the order data on the file
            _repo.WriteLine(bllOrder);
        }
Exemplo n.º 25
0
        public Response GetAllOrdersFromDate(string orderDate)
        {
            //var repo = new OrderRepository();

            var response = new Response();

            var orders = _repo.GetAllOrders(orderDate);

            if (orders == null)
            {
                response.Success = false;
                response.Message = "This is not the order you are looking for...";
            }
            else
            {
                response.Success = true;
                response.OrderList = orders;
            }

            return response;
        }
Exemplo n.º 26
0
        public Response<Order> GetAllOrder(string _date)
        {
            Response<Order> response = new Response<Order>();
            try
            {
                var listOrders = _orderRepo.GetAll(_date);

                if (listOrders != null)
                {
                    response.Data = listOrders;
                    response.Success = true;
                }
                else
                {
                    response.Success = false;
                    response.Message = "ORDER NOT FOUND";
                }
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = "ERROR: Please try again later. " + ex;
            }

            return response;
        }
Exemplo n.º 27
0
        public Response<Order> GetOneOrder(int id, string _date)
        {
            Response<Order> response = new Response<Order>();
            var orderFound = _orderRepo.GetOne(id, _date);

            try
            {
                if (orderFound != null)
                {
                    response.Success = true;
                    response.Data = new List<Order>() {orderFound};
                }
                else
                {
                    response.Success = false;
                    response.Message = "Order is not found.";
                }
            }
            catch (Exception ex)
            {
                response.Message = "There was an unexpected error. Please try again later. " + ex;
            }
            return response;
        }
Exemplo n.º 28
0
        public Response<EditOrderReceipt> EditOrder(Order order, string date, int ordernum)
        {
            var response = new Response<EditOrderReceipt>();
            var repo = _repo;
            var orders = _repo.LoadOrders(date);
            var taxes = _taxrepo.LoadTaxRate();
            var products = _productrepo.LoadProductType();

            try
            {
                var taxrate = taxes.First(a => a.StateAbbreviation == order.stateName);
                order.taxRate = taxrate.TaxRate;
                var producttype = products.First(a => a.ProductType == order.productType);
                order.CostPerSquareFoot = producttype.CostPerSquareFoot;
                order.LaborCostPerSquareFoot = producttype.LaborCostPerSquareFoot;
                order = SetDerivedOrderInfo(order);
                var filtered = orders.Where(a => a.orderNumber != ordernum).ToList();
                filtered.Add(order);
                repo.OverWriteFileWithOrder(filtered, date);
                response.Success = true;
                response.Data = new EditOrderReceipt();
                response.Data.Date = int.Parse(date);
                response.Data.Orders = orders;
                response.Data.Order = order;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Message = ex.Message;
            }
            return response;
        }
Exemplo n.º 29
0
        public Response RemoveOrder(string date, int orderNum)
        {
            Response response = new Response();
            response = GetOrders(date);

            var result = response.OrderList.Any(n => n.OrderNumber == orderNum);

            if (response.Success == false)
            {
                return response;
            }
            else if (!result)
            {
                response.Message = "Your order number cannot be found.";
                return response;
            }
            else
            {
                _repo.RemoveOrder(date, orderNum);
                response.Message = "Order has been removed.";
                return response;
            }
        }
Exemplo n.º 30
0
 public Response<RemoveOrderReceipt> RemoveOrder(Order order, string date, int ordernum)
 {
     var response = new Response<RemoveOrderReceipt>();
     //response.Data = new RemoveOrderReceipt;
     var repo = _repo;
     var orders = _repo.LoadOrders(date);
     try
     {
         var filtered = orders.Where(a => a.orderNumber != ordernum).ToList();
         repo.OverWriteFileWithOrder(filtered, date);
         response.Success = true;
         response.Data = new RemoveOrderReceipt();
         response.Data.Date = int.Parse(date);
         response.Data.Orders = orders;
     }
     catch (Exception ex)
     {
         response.Success = false;
         response.Message = ex.Message;
     }
     return response;
 }