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 Execute()
        {
            var date = GetDate();
            var ordernumber = GetOrderNumber();
            var manager = new OrderManager();
            var response = manager.DisplayOrders(date);
            if (response.Data == null || response.Data.Orders.Count == 0)
            {
                Console.WriteLine();
                Console.WriteLine("Sorry! There are no orders at all for that particular date..");
                Console.Write("Press any key to continue... ");
                Console.ReadKey();
            }
            else
            {
                var ordertofind = response.Data.Orders.FirstOrDefault(a => a.orderNumber == ordernumber);
                if (ordertofind == null)
                {
                    Console.WriteLine();
                    Console.Write("Order#{0} was not found. Press any key to continue... ", ordernumber);
                    Console.ReadKey();
                }
                else
                {
                    // we found the correct order.
                    Console.Clear();
                    Console.WriteLine("EDIT ORDER SUMMARY");
                    Console.WriteLine("*****************");
                    Console.WriteLine("orderNumber  customerName  stateName  taxRate  productType  Area    CostPerSquareFoot LaborCostPerSquareFoot MaterialCost LaborCost Tax   Total");
                    const string formatordertofind = "{0,-10} {1,11} {2,6} {3,12} {4,14} {5,8:n2} {6,5:n2} {7,17:n2} {8,24:n2} {9,12:n2} {10,8:n2} {11,7:n2}";
                    string line2 = string.Format(formatordertofind, ordertofind.orderNumber, ordertofind.customerName, ordertofind.stateName,
                        ordertofind.taxRate, ordertofind.productType,
                        ordertofind.Area, ordertofind.CostPerSquareFoot,
                        ordertofind.LaborCostPerSquareFoot,
                        ordertofind.MaterialCost, ordertofind.LaborCost,
                        ordertofind.Tax, ordertofind.Total);

                    Console.WriteLine(line2);
                    Console.WriteLine();
                    Console.Write("\nPress ENTER to edit... ");
                    Console.ReadLine();
                    Console.WriteLine();

                    var ordertoedit = new Order();

                    //Update Customer Name
                    string inputname;
                    do
                    {
                        Console.Write("Enter customer name ({0}): ", ordertofind.customerName);
                        inputname = Console.ReadLine();
                    } while (inputname.Contains(",") || inputname.Contains("."));

                    if (inputname != "")
                    {
                        ordertoedit.customerName = inputname;
                    }
                    if (inputname == "")
                    {
                        ordertoedit.customerName = ordertofind.customerName;
                    }

                    // Update State Name
                    ordertoedit.stateName = GetStateName(ordertofind);

                    // Update Product Type
                    ordertoedit.productType = GetProductType(ordertofind);
                    ordertoedit.orderNumber = ordertofind.orderNumber;
                    // Update Area
                    do
                    {
                        Console.Write("Enter area greater than zero ({0}): ", ordertofind.Area);
                        string inputarea = Console.ReadLine();
                        decimal num;
                        bool test = decimal.TryParse(inputarea, out num);
                        if (inputarea == "")
                        {
                            ordertoedit.Area = ordertofind.Area;
                            break;
                        }
                        if (inputarea != "" && test && decimal.Parse(inputarea) > 0)
                        {
                            ordertoedit.Area = num;
                            break;
                        }
                    } while (true);

                    // confirm (y/n)
                    bool prompt = false;
                    string newgame = "";
                    while (prompt == false)
                    {
                        Console.Write("\nCommit new order? (Y/N): ");
                        newgame = Console.ReadLine();
                        if (newgame.ToUpper() == "Y" || newgame.ToUpper() == "YES"
                            || newgame.ToUpper() == "N" || newgame.ToUpper() == "NO")
                        {
                            prompt = true;
                        }
                    }
                    if (newgame.ToUpper() == "Y" || newgame.ToUpper() == "YES")
                    {

                        var response1 = manager.EditOrder(ordertoedit, date, ordernumber); // the order before it's been fully populated.
                        var editedorder = response1.Data.Order; // the one we get back after we load all data.

                        Console.Clear();
                        Console.WriteLine("(SUMMARY OF NEWLY EDITED ORDER)");
                        Console.WriteLine("*****************");
                        Console.WriteLine("orderNumber  customerName  stateName  taxRate  productType  Area    CostPerSquareFoot LaborCostPerSquareFoot MaterialCost LaborCost Tax   Total");
                        const string formateditorder = "{0,1} {1,19} {2,11} {3,12} {4,10} {5,8:n2} {6,9} {7,17} {8,24} {9,11} {10,8:n2} {11,7:n2}";
                        string line1 = string.Format(formateditorder, editedorder.orderNumber,
                            editedorder.customerName, editedorder.stateName,
                            editedorder.taxRate, editedorder.productType,
                            editedorder.Area, editedorder.CostPerSquareFoot,
                            editedorder.LaborCostPerSquareFoot,
                            editedorder.MaterialCost, editedorder.LaborCost,
                            editedorder.Tax, editedorder.Total);
                        Console.WriteLine(line1);
                        Console.WriteLine();
                        Console.Write("Order has been edited. Press any key to continue...");
                        Console.ReadKey();
                    }
                    else // user types no. Revert back to old order information.
                    {
                        manager.EditOrder(ordertofind, date, ordernumber);
                        Console.Write("Edited changes cancelled. Press any key to continue...");
                        Console.ReadKey();
                    }
                }
            }
        }
        public void EditOrder()
        {
            string mode = "File";
            string productPath = @"DataFiles\Orders\";
            var orderManager = new OrderManager(mode, productPath);

            var repo = new OrderFileModeRepo(productPath);
            var order = repo.GetOne(1, "06012013");
            order.State = "IN";
            order.TaxRate = 6.00m;

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

            Assert.AreEqual(result.Data[0].State, "IN");
            Assert.AreEqual(result.Data[0].TaxRate, 6.00m);
            Assert.AreEqual(result.Data[0].TotalTax, 59.4m);
            Assert.IsTrue(result.Success);
        }
        public void Execute()
        {
            Console.Clear();
            string date = HelperMethod.GetDate();
            Console.Clear();
            var orderManager = new OrderManager(Program.Mode, Program.OrderPath);
            var helper = new HelperMethod();

            var retrieve_result = orderManager.GetAllOrder(date);

            if (retrieve_result.Success)
            {
                HelperMethod.displayOrders(retrieve_result.Data);
                int id;

                while (true)
                {
                    id = HelperMethod.GetID();
                    if (id == 0)
                        break;
                    var success = retrieve_result.Data.Any(o => o.OrderNumber == id);

                    if (success)
                        break;

                    Console.WriteLine("Your input ID is not valid, press enter to continue...");
                    Console.ReadKey();
                }

                if (id == 0)
                    return;

                var orderFound = orderManager.GetOneOrder(id, date);

                Order newOrder = new Order();

                if (orderFound.Success)
                {
                    Console.Clear();
                    newOrder = orderFound.Data[0];
                    HelperMethod.displayOrders(orderFound.Data);
                    string name = getCustomerName(orderFound.Data[0].CustomerName);
                    if (name != "")
                    {
                        newOrder.CustomerName = helper.ValidCustomerName(name);
                    }
                    string stateAbbrev = getState(orderFound.Data[0].State);
                    if (stateAbbrev != "")
                    {
                        newOrder.State = helper.validStateRepo(stateAbbrev);
                    }
                    string product = getProduct(orderFound.Data[0].ProductType);
                    if (product != "")
                    {
                        newOrder.ProductType = helper.validProductRepo(product);
                    }
                    string area = getArea(orderFound.Data[0].Area);
                    if (area != "")
                    {
                        newOrder.Area = helper.validArea(area);
                    }
                    var response = orderManager.EditOrder(newOrder, date);

                    if (response.Success)
                    {
                        Console.WriteLine("\n\n\n");
                        Console.WriteLine("Your order has been edited, here is your edited order details. ");
                        HelperMethod.displayOrders(response.Data);
                        Console.WriteLine("Press any key to continue ...");
                        Console.ReadKey();
                    }
                }
                else
                {
                    Console.WriteLine("That is not a valid Order ID. Press any key to continue ... ");
                    Console.ReadKey();
                }

            }
            else
            {
                Console.WriteLine("There are no orders for that date. Press any key to continue ...");
                Console.ReadKey();
            }
        }