Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void EditGoal()
- {
- Console.Clear();
- List<Goal> allGoals = GoalQueries.GetAllGoals();
- var tableData = new List<List<object>>();
- foreach (Goal goal in allGoals)
- {
- var item = new List<object>() {
- goal.Id, goal.Name, goal.StartDate, goal.EndDate, goal.DaysToGoal, goal.HoursPerDay, goal.Achieved
- };
- tableData.Add(item);
- }
- TableVisualizationEngine.ShowTable(tableData, goalColHeaders);
- Console.WriteLine("\nTo Select A Goal To Edit, Enter It's ID Number");
- Console.Write("Your Selection: ");
- string input = Console.ReadLine();
- int selectedId = UserValidation.ValidateIdSelection(UserValidation.ValidateNumericInput(input), null, allGoals);
- Goal currentGoal = GoalQueries.GetSelectedGoal(selectedId);
- Goal updatedGoal = StartGoalEdit(currentGoal);
- GoalQueries.UpdateGoal(updatedGoal);
- }
- public static Goal StartGoalEdit(Goal currentGoal)
- {
- Console.WriteLine("\nWhen Editing Information, If you want it left the same then press ENTER to skip.");
- Console.WriteLine($"\nCurrent Name: {currentGoal.Name}");
- Console.Write("Enter Corrected Name: ");
- string input = Console.ReadLine();
- string newName = UserValidation.VerifyEmptyOrChanged(
- currentGoal.Name,
- UserValidation.ValidateAlphaInput(input, "Enter Corrected Name"));
- Console.WriteLine($"\nCurrent Start Date: {currentGoal.StartDate}");
- Console.Write("Enter Corrected Start Date: ");
- input = Console.ReadLine();
- string newStartDate = UserValidation.VerifyEmptyOrChanged(
- currentGoal.StartDate,
- UserValidation.VerifyDateInput(input));
- Console.WriteLine($"\nCurrent End Date: {currentGoal.EndDate}");
- Console.Write("Enter Corrected End Date: ");
- input = Console.ReadLine();
- string newEndDate = UserValidation.VerifyEmptyOrChanged(
- currentGoal.EndDate,
- UserValidation.VerifyDateInput(input));
- Console.WriteLine($"\nCurrent Hours Per Day: {currentGoal.HoursPerDay}");
- Console.WriteLine("Enter Corrected Hours Per Day: ");
- input = Console.ReadLine();
- int newHoursPerDay = int.Parse(UserValidation.VerifyEmptyOrChanged(
- currentGoal.HoursPerDay.ToString(),
- UserValidation.ValidateNumericInput(input).ToString()));
- int newDaysToGoal = Helpers.DaysToGoal(newStartDate, newEndDate);
- Goal updatedGoal = new()
- {
- Name = newName,
- StartDate = newStartDate,
- EndDate = newEndDate,
- DaysToGoal = newDaysToGoal,
- HoursPerDay = newHoursPerDay,
- Achieved = "No"
- };
- Console.WriteLine("------------------------------------");
- Console.WriteLine($"Goal Name: {updatedGoal.Name}");
- Console.WriteLine($"Start Date: {updatedGoal.StartDate}");
- Console.WriteLine($"End Date: {updatedGoal.EndDate}");
- Console.WriteLine($"Coding Hours Per Day: {updatedGoal.HoursPerDay}");
- Console.WriteLine($"Days Until Goal: {updatedGoal.DaysToGoal}");
- Console.WriteLine($"Goal Achieved: {updatedGoal.Achieved}");
- Console.WriteLine("------------------------------------");
- Console.WriteLine();
- bool satisfied = UserValidation.ValidateYesNo("\nAre You Satisfied With This Information? Y/N");
- return satisfied ? updatedGoal : StartGoalEdit(currentGoal);
- }
Advertisement
Add Comment
Please, Sign In to add comment