public static void ListCurrentTasks(List <UserTask> taskList) { Console.WriteLine("\nCurrent Tasks:"); UserTask.ListTasks(taskList); Console.WriteLine("\nPress enter to return to main menu.\n"); Console.ReadLine(); }
public static void UpdateTaskFromList(List <UserTask> userTaskList, string message) { //which task would you like to update? { UserTask.ListTasks(userTaskList); //print current task list bool tryAgain = true; while (tryAgain) { //prompt user and get input Console.Write(message); string userCoice = Console.ReadLine(); int userChoiceAsNum; bool userChoiceTry = int.TryParse(userCoice, out userChoiceAsNum); //validation to make sure user input is a number, and that number is within the range of the task list if (!userChoiceTry || userChoiceAsNum > userTaskList.Count || userChoiceAsNum <= 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Please enter a valid task number.\n"); Console.ResetColor(); break; } string confirmUpdated = GetUserInput("Are you sure? (y/n): "); tryAgain = false; switch (confirmUpdated) { case "y": //REAL UPDATES GO HERE - SEE ADD TASK METHOD Console.Write("Team Member: "); userTaskList[userChoiceAsNum - 1].TeamMemberName = Console.ReadLine(); //2) get input from user and add it to the new task Console.Write("Description: "); userTaskList[userChoiceAsNum - 1].TaskDescription = Console.ReadLine(); //2.5) date validation. mm/dd/yy format. bool dateCheck = true; string datePattern = @"^(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.]\d\d$"; while (dateCheck) { Console.Write("Date: "); string dateInput = Console.ReadLine(); if (!Regex.IsMatch(dateInput, datePattern)) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Please enter a valid date (mm/dd/yy)."); Console.ResetColor(); } else { userTaskList[userChoiceAsNum - 1].DueDate = dateInput; dateCheck = false; } } Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Task successfully updated."); Console.ResetColor(); break; case "n": ReturnToMainMenu(userTaskList); break; default: tryAgain = true; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Please make a valid selection: (y or n)"); Console.ResetColor(); break; } } // UserTask.ListTasks(userTaskList); //sanity check // asks if user would like to update another item, if so, rerun method, else return to main menu bool updateAgain = true; while (updateAgain) { string userSelection = GetUserInput("Would you like to update another task? (y/n): "); updateAgain = false; switch (userSelection) { case "y": UpdateTaskFromList(userTaskList, message); break; case "n": ReturnToMainMenu(userTaskList); break; default: updateAgain = true; Console.WriteLine("Please make a valid selection: ('y' or 'n')"); break; } } } }
public static void MarkTaskComplete(List <UserTask> userTaskList, string message) { UserTask.ListTasks(userTaskList); //print current task list bool tryAgain = true; while (tryAgain) { //prompt user and get input Console.Write(message); string userCoice = Console.ReadLine(); int userChoiceAsNum; bool userChoiceTry = int.TryParse(userCoice, out userChoiceAsNum); //validation to make sure user input is a number, and that number is within the range of the task list if (!userChoiceTry || userChoiceAsNum > userTaskList.Count || userChoiceAsNum <= 0) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Please enter a valid task number.\n"); Console.ResetColor(); break; } //confirms task deletion. If yes, delete list item and ask if they'd like to delete another, else return to main menu string confirmComplete = GetUserInput("Are you sure? (y/n): "); tryAgain = false; switch (confirmComplete) { case "y": //userTaskList.RemoveAt(userChoiceAsNum - 1); userTaskList[userChoiceAsNum - 1].TaskComplete = true; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Task successfully completed."); Console.ResetColor(); break; case "n": ReturnToMainMenu(userTaskList); break; default: tryAgain = true; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Please make a valid selection: (y or n)"); Console.ResetColor(); break; } } // asks if user would like to delte another item, if so, rerun method, else return to main menu bool removeAgain = true; while (removeAgain) { string userSelection = GetUserInput("Would you like to complete another task? (y/n): "); removeAgain = false; switch (userSelection) { case "y": MarkTaskComplete(userTaskList, message); break; case "n": ReturnToMainMenu(userTaskList); break; default: removeAgain = true; Console.WriteLine("Please make a valid selection: ('y' or 'n')"); break; } } }