Guest User

Untitled

a guest
Oct 4th, 2023
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.32 KB | None | 0 0
  1. public static void EditGoal()
  2. {
  3.     Console.Clear();
  4.  
  5.     List<Goal> allGoals = GoalQueries.GetAllGoals();
  6.     var tableData = new List<List<object>>();
  7.  
  8.     foreach (Goal goal in allGoals)
  9.     {
  10.         var item = new List<object>() {
  11.             goal.Id, goal.Name, goal.StartDate, goal.EndDate, goal.DaysToGoal, goal.HoursPerDay, goal.Achieved
  12.         };
  13.  
  14.         tableData.Add(item);
  15.     }
  16.  
  17.     TableVisualizationEngine.ShowTable(tableData, goalColHeaders);
  18.  
  19.     Console.WriteLine("\nTo Select A Goal To Edit, Enter It's ID Number");
  20.     Console.Write("Your Selection: ");
  21.     string input = Console.ReadLine();
  22.     int selectedId = UserValidation.ValidateIdSelection(UserValidation.ValidateNumericInput(input), null, allGoals);
  23.  
  24.     Goal currentGoal = GoalQueries.GetSelectedGoal(selectedId);
  25.     Goal updatedGoal = StartGoalEdit(currentGoal);
  26.     GoalQueries.UpdateGoal(updatedGoal);
  27. }
  28.  
  29. public static Goal StartGoalEdit(Goal currentGoal)
  30. {
  31.     Console.WriteLine("\nWhen Editing Information, If you want it left the same then press ENTER to skip.");
  32.     Console.WriteLine($"\nCurrent Name: {currentGoal.Name}");
  33.     Console.Write("Enter Corrected Name: ");
  34.  
  35.     string input = Console.ReadLine();
  36.     string newName = UserValidation.VerifyEmptyOrChanged(
  37.         currentGoal.Name,
  38.         UserValidation.ValidateAlphaInput(input, "Enter Corrected Name"));
  39.  
  40.     Console.WriteLine($"\nCurrent Start Date: {currentGoal.StartDate}");
  41.     Console.Write("Enter Corrected Start Date: ");
  42.  
  43.     input = Console.ReadLine();
  44.     string newStartDate = UserValidation.VerifyEmptyOrChanged(
  45.         currentGoal.StartDate,
  46.         UserValidation.VerifyDateInput(input));
  47.  
  48.     Console.WriteLine($"\nCurrent End Date: {currentGoal.EndDate}");
  49.     Console.Write("Enter Corrected End Date: ");
  50.  
  51.     input = Console.ReadLine();
  52.     string newEndDate = UserValidation.VerifyEmptyOrChanged(
  53.         currentGoal.EndDate,
  54.         UserValidation.VerifyDateInput(input));
  55.  
  56.     Console.WriteLine($"\nCurrent Hours Per Day: {currentGoal.HoursPerDay}");
  57.     Console.WriteLine("Enter Corrected Hours Per Day: ");
  58.     input = Console.ReadLine();
  59.     int newHoursPerDay = int.Parse(UserValidation.VerifyEmptyOrChanged(
  60.         currentGoal.HoursPerDay.ToString(),
  61.         UserValidation.ValidateNumericInput(input).ToString()));
  62.  
  63.     int newDaysToGoal = Helpers.DaysToGoal(newStartDate, newEndDate);
  64.  
  65.     Goal updatedGoal = new()
  66.     {
  67.         Name = newName,
  68.         StartDate = newStartDate,
  69.         EndDate = newEndDate,
  70.         DaysToGoal = newDaysToGoal,
  71.         HoursPerDay = newHoursPerDay,
  72.         Achieved = "No"
  73.     };
  74.  
  75.     Console.WriteLine("------------------------------------");
  76.     Console.WriteLine($"Goal Name: {updatedGoal.Name}");
  77.     Console.WriteLine($"Start Date: {updatedGoal.StartDate}");
  78.     Console.WriteLine($"End Date: {updatedGoal.EndDate}");
  79.     Console.WriteLine($"Coding Hours Per Day: {updatedGoal.HoursPerDay}");
  80.     Console.WriteLine($"Days Until Goal: {updatedGoal.DaysToGoal}");
  81.     Console.WriteLine($"Goal Achieved: {updatedGoal.Achieved}");
  82.     Console.WriteLine("------------------------------------");
  83.  
  84.     Console.WriteLine();
  85.     bool satisfied = UserValidation.ValidateYesNo("\nAre You Satisfied With This Information? Y/N");
  86.  
  87.     return satisfied ? updatedGoal : StartGoalEdit(currentGoal);
  88. }
Advertisement
Add Comment
Please, Sign In to add comment