public void Track(T user) { bool flag = true; while (flag) { Console.Clear(); Console.WriteLine("Choose activity:\n"); Console.WriteLine("1. Reading"); Console.WriteLine("2. Exercising"); Console.WriteLine("3. Working"); Console.WriteLine("4. Other hobbies"); Console.WriteLine("5. Back"); bool activityValidation = int.TryParse(Console.ReadLine(), out int activityChoice); if (activityValidation) { if (activityChoice == 1) { reading.ReadingActivity(); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Console.WriteLine("Press ENTER to stop."); string stop = Console.ReadLine(); if (stop == "") { stopwatch.Stop(); TimeSpan time = stopwatch.Elapsed; double convertedTime = Convert.ToDouble(time.TotalSeconds); user.Reading += convertedTime / 60; Console.WriteLine($"Time spent on this activity: {Math.Round(convertedTime / 60, 2)} min."); Console.WriteLine("Press any key to go back to the Main Menu."); Console.ReadKey(); flag = false; } } else if (activityChoice == 2) { exercising.ExercisingActivity(); Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); Console.WriteLine("Press ENTER to stop."); string stop = Console.ReadLine(); if (stop == "") { stopwatch.Stop(); TimeSpan time = stopwatch.Elapsed; double convertedTime = Convert.ToDouble(time.TotalSeconds); user.Exercising += convertedTime / 60; Console.WriteLine($"Time spent on this activity: {Math.Round(convertedTime / 60, 2)} min."); Console.WriteLine("Press any key to go back to the Main Menu."); Console.ReadKey(); flag = false; } } else if (activityChoice == 3) { working.WorkingActivity(user); flag = false; } else if (activityChoice == 4) { otherHobbies.OtherHobiesActivity(user); flag = false; } else if (activityChoice == 5) { break; } } } }
public void Track(T user) { bool flag = true; while (flag) { Console.Clear(); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Choose activity:\n"); Console.WriteLine("1.) Reading"); Console.WriteLine("2.) Exercising"); Console.WriteLine("3.) Working"); Console.WriteLine("4.) Other hobbies"); Console.WriteLine("5.) Back to main menu"); bool activityValidation = int.TryParse(Console.ReadLine(), out int activityChoice); if (activityValidation) { if (activityChoice <= 5 && activityChoice > 0) { if (activityChoice == 1) { readingActivity.ReadingActivity(user); _database.UpdateUser(user); flag = false; } else if (activityChoice == 2) { exercisingActivity.ExercisingActivity(user); _database.UpdateUser(user); flag = false; } else if (activityChoice == 3) { workingActivity.WorkingActivity(user); _database.UpdateUser(user); flag = false; } else if (activityChoice == 4) { otherHobbiesActivity.OtherHobiesActivity(user); _database.UpdateUser(user); flag = false; } else if (activityChoice == 5) { break; } } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Invalid input. Please try again !"); Console.WriteLine("Press any key to try again."); Console.ReadKey(); } } else { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Invalid input. Please try again !"); Console.WriteLine("Press any key to try again."); Console.ReadKey(); } } }