private static string GetNewDescription(Todo todoSelection, TodoCollection todoCollection) { Print.NewLine("\nWrite a new description for this todo. Just enter without typing anything will exit."); string newDescription = Console.ReadLine(); if (!string.IsNullOrEmpty(newDescription) && todoCollection.Exists(newDescription)) { Print.NewLine("The entry already exists. Try again.", ConsoleColor.Red); return(GetNewDescription(todoSelection, todoCollection)); } return(newDescription); }
private static void RunSelection(TodoCollection todoCollection, string choice) { var todoSelection = todoCollection.FindById(choice); Print.Line($"You selected: ", clearConsole: true); Print.NewLine(todoSelection.Description, todoSelection.Color); Print.Line($"Priority level is: "); Print.NewLine(todoSelection.PriorityLevel.ToString(), Priority.GetColor(todoSelection.PriorityLevel)); var menu = new CharConsoleMenu() { Choices = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("d", "escription edit"), new KeyValuePair <string, string>("p", "riority edit"), new KeyValuePair <string, string>("r", "emove") }, SpacingCount = 0, IdWrapColor = ConsoleColor.Yellow, TextColor = ConsoleColor.Blue }; menu.OutputToConsole("Please make a selection", ConsoleColor.Green); string modify = menu.GetUserInput().ToLower(); if (modify == menu.Choices[0].Key.ToString()) // d { string newDescription = GetNewDescription(todoSelection, todoCollection); if (!string.IsNullOrEmpty(newDescription)) { todoCollection.Update(todoSelection, new Todo() { Description = newDescription, PriorityLevel = todoSelection.PriorityLevel }); todoCollection.Save(); } } else if (modify == menu.Choices[1].Key.ToString()) // p { todoCollection.Update(todoSelection, new Todo() { Description = todoSelection.Description, PriorityLevel = GetPriorityForNewEntry() }); todoCollection.Save(); } else if (modify == menu.Choices[2].Key.ToString()) // r { todoCollection.Remove(todoSelection); todoCollection.Save(); } }
private static bool Run(string todoPath, bool exit = false) { if (!exit) { var todoCollection = new TodoCollection(todoPath, false); if (!todoCollection.DbExists()) { todoCollection.Initialize(); exit = false; } else { Console.Clear(); todoCollection.Load(); OutputAppTitle("console-todo"); todoCollection.OutputToConsole(); Print.NewLine("\nWrite a new todo to add it. A number to edit. Just enter without typing anything to exit.\n", ConsoleColor.White); exit = GetMainMenuUserInput(todoCollection); } } return(!exit); }