private static void ApplyChoice(int menuChoice) { switch (menuChoice) { case 1: OrderLookupWorkflow LookupWorkflow = new OrderLookupWorkflow(); LookupWorkflow.Execute(); break; case 2: AddOrderWorkflow AddOrder = new AddOrderWorkflow(); AddOrder.Execute(); break; case 3: EditOrderWorkflow EditOrder = new EditOrderWorkflow(); EditOrder.Execute(); break; case 4: DeleteOrderWorkflow DeleteOrder = new DeleteOrderWorkflow(); DeleteOrder.Execute(); break; case 5: Console.Write("To exit, "); CommonIO.Continue(); break; } }
//private List<Order> myVar = Orders; public void Execute() { CommonIO.ShowHeader("Lookup an order"); List <Order> _allOrders = new List <Order>(); DateTime OrderDate = ConsoleIO.AskForOrderDate(); OrdrLkpResponses AllOrders = new OrdrLkpResponses(); AllOrders = _manager.LoadOrders(OrderDate); _allOrders = AllOrders.Orders; Console.Clear(); if (AllOrders.Success) { foreach (Order OneOrder in _allOrders) { ConsoleIO.DisplayOrderDetails(OneOrder); } CommonIO.Continue(); } else { CommonIO.MessageToUserInBlue(AllOrders.Message); } }
public void SaveOrderToList(Order newOrder) { OrdrLkpResponses AllOrders = new OrdrLkpResponses(); AllOrders = _manager.LoadOrders(newOrder.OrderDate); String userConfirm = ConsoleIO.RequireYorN("Would you like to save this order? (y=yes, n=no)"); _orders = AllOrders.Orders; if (userConfirm == "Y") { int orderNumToReplace = newOrder.OrderNumber; Order OldOrder = _orders.FirstOrDefault(o => o.OrderNumber == newOrder.OrderNumber); int indexToReplace = (_orders.IndexOf(OldOrder)); _orders[indexToReplace] = newOrder; _manager.SaveOrders(newOrder.OrderDate, _orders); userConfirm = userConfirm.ToUpper(); CommonIO.MessageToUserInBlue($"New order ID {newOrder.OrderNumber} has been saved."); CommonIO.Continue(); } else if (userConfirm == "N") { CommonIO.MessageToUserInBlue($"New order ID {newOrder.OrderNumber} was NOT saved."); CommonIO.Continue(); } }
public void Execute() // The construct doesn't get executed when a method is static. // But, without having this static makes it difficult to count orders // AND diffiuclt to get the next order number. { Order orderFromUsr = new Order(); CommonIO.ShowHeader("Add an order"); orderFromUsr = ConsoleIO.GetNewOrder(); OrdrLkpResponses AllOrders = new OrdrLkpResponses(); AllOrders = _manager.LoadOrders(orderFromUsr.OrderDate); if (AllOrders.Success) { _orders = AllOrders.Orders; } else { Console.WriteLine("An error occurred: "); Console.WriteLine(AllOrders.Message); } orderFromUsr = CalcRestofOrder(orderFromUsr); //DateTime OrderDate = orderFromUsr.OrderDate; CommonIO.MessageToUserInBlue("Order entry is complete."); CommonIO.Continue(); ConsoleIO.DisplayOrderDetails(orderFromUsr); String userConfirm = ConsoleIO.RequireYorN("Would you like to save this information? (y=Yes, n=No.)"); if (userConfirm.ToUpper() == "Y") { //List<Order> AllOrders = _manager.LoadOrders(DateTime.Now); _manager.SaveOrder(orderFromUsr); //manager.SaveOrders(AllOrders); CommonIO.MessageToUserInBlue($"New order ID {orderFromUsr.OrderNumber} has been saved."); CommonIO.Continue(); } else { CommonIO.MessageToUserInBlue($"New order ID {orderFromUsr.OrderNumber} was NOT saved."); CommonIO.Continue(); } }
private void DeleteOrder(DateTime OrderDateToDelete, int orderNumtoDelete) { OrderLookupResponse response = _manager.LookupOrder(OrderDateToDelete, orderNumtoDelete); if (response.Success) { ConsoleIO.DisplayOrderDetails(response.Order); string confirmYN = ConsoleIO.RequireYorN("Are you sure you want to remove this order? (y=yes, n=no)"); do { if (confirmYN == "Y") { _orders.RemoveAll(o => o.OrderNumber == response.Order.OrderNumber); //_orders.Remove(_orders[indexToDelete]); //TODO: Learn why .remove did not work and .removeall did work. _manager.SaveOrders(OrderDateToDelete, _orders); CommonIO.MessageToUserInBlue($"Order {orderNumtoDelete} was deleted."); } else if (confirmYN == "N") { CommonIO.MessageToUserInBlue($"Order {orderNumtoDelete} was NOT deleted."); //CommonIO.Continue(); } else { CommonIO.MessageToUserInBlue("Please enter y or n."); } } while ((confirmYN == "Y") && (confirmYN == "N")); } else { Console.WriteLine("An error occurred: "); Console.WriteLine(response.Message); } CommonIO.Continue(); }
public Order GetEdits(Order OrderToEdit) { //Order EditedOrder = new Order(); // Edit Customer Name Console.Write($"Customer Name ({OrderToEdit.CustomerName}), "); CommonIO.MessageToUserInBlue("press Enter for no change."); String newCustomerName = ConsoleIO.AskForNewCustomerName(); if (newCustomerName == "") { Console.WriteLine("Name Unchanged\n"); } else { OrderToEdit.CustomerName = newCustomerName; } // Edit State Console.WriteLine($"Order State ({OrderToEdit.State}):"); CommonIO.MessageToUserInBlue(" 0. No change"); String newState = ConsoleIO.AskForNewStateAbbr(); if (newState != null) { Console.WriteLine("State Unchanged"); } else { OrderToEdit.State = newState; } // Edit Product Console.WriteLine($"Product ({OrderToEdit.ProductType}):"); CommonIO.MessageToUserInBlue(" 0. No change"); Product EditedProduct = ConsoleIO.AskForNewProduct(); if (newState == null) { Console.WriteLine("Product Unchanged"); } else { OrderToEdit.State = newState; } // Edit Area Console.WriteLine($"Area ({OrderToEdit.Area}), "); CommonIO.MessageToUserInBlue("Enter 0 for no change."); //Decimal editedArea = ConsoleIO.AskForArea(); decimal editedArea = 0; int min = 100, max = 100000; bool intCk = false; do { intCk = decimal.TryParse(Console.ReadLine(), out editedArea); if (!intCk) { editedArea = 1; } if (editedArea == 0) { CommonIO.MessageToUserInBlue("Area unchanged."); break; } else if (editedArea < min) { CommonIO.MessageToUserInBlue($"Please enter a number between {min} and {max}"); //CommonIO.Continue(); } } while (editedArea < min || editedArea > max); if (editedArea != 0) { OrderToEdit.Area = editedArea; } CommonIO.MessageToUserInBlue("Editing order is complete. Next, you'll view the edited order and decide if you want to save it."); CommonIO.Continue(); Console.Clear(); ConsoleIO.DisplayOrderDetails(OrderToEdit); //• CustomerName, State, ProductType, Area return(OrderToEdit); }