public static bool DeleteTask(List <Task> list) { Task selectedTask = GetSelectedTaskFromUser(list, "Enter task # to delete: "); UserInput.Display("Task to be deleted:\n\n"); selectedTask.DisplayTask(); if (UserInput.UserConfirmationPrompt("\nAre you sure(Y/N)? ")) { return(list.Remove(selectedTask)); } else { UserInput.Display("\nDelete cancelled!\n\n"); } return(false); }
private static bool PerformAdvancedTask(int selectedOption, List <Task> taskList) { if (selectedOption == 1) { DisplayTasksByOwnerName(taskList); } else if (selectedOption == 2) { DisplayAllTaskBeforeDate(taskList); } else if (selectedOption == 3) { try { Task selectedTask = GetSelectedTaskFromUser(taskList, "Enter Task# to edit: "); selectedTask.DisplayTask(); if (UserInput.UserConfirmationPrompt("Are you sure(Y/N)")) { selectedTask = Task.AddOrEdit(selectedTask, true); UserInput.Display("Updated!"); } else { UserInput.Display("Cancelled by user."); } } catch (Exception) { UserInput.Display("Item does not exists!"); } } else { return(false); } return(true); }
public static void MarkTaskAsComplete(List <Task> list) { int[] indexOfTask = UserInput.GetUserMultipleInputAsInteger("Task# to set to complete " + "(use space to enter multiple tasks#): "); foreach (int index in indexOfTask) { list[index - 1].DisplayTask(); } if (UserInput.UserConfirmationPrompt("\nAre you sure(Y/N)? ")) { foreach (int index in indexOfTask) { list[index - 1].MarkAsComplete(); } UserInput.Display("\nCompleted!\n\n"); } else { UserInput.Display("\nStatus change cancelled!\n\n"); } }
static void Main(string[] args) { List <Task> taskList = new List <Task>(); bool repeat = true; taskList = TestData(); while (repeat) { try { switch (GetInputFromMainMenu()) { case 1: Console.Clear(); DisplayAllTasks(taskList); Pause(); break; case 2: taskList.Add(Task.AddOrEdit(null)); UserInput.Display("New task added!"); Pause(); break; case 3: if (DeleteTask(taskList)) { UserInput.Display("\nDeleted!\n\n"); } Pause(); break; case 4: MarkTaskAsComplete(taskList); Pause(); break; case 5: Console.Clear(); while (repeat) { int selectedOption = AdvancedOptionMenu(); //if user exit advanced option repeat equals false repeat = PerformAdvancedTask(selectedOption, taskList); if (repeat) { Pause(); } } repeat = true; //Set back to true for main menu break; case 6: if (UserInput.UserConfirmationPrompt("Are you sure(Y/N)?")) { repeat = false; } break; default: break; } } catch (ArgumentOutOfRangeException) { UserInput.Display("That record does not exists. " + "Use option 1 to view the list of tasks"); } }//while UserInput.Display("Goodbye!\n"); }