//EditingBaseballPlayer method public static void EditingBaseballPlayer() { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"{"Player Type",-20} {"Player ID",10} {"Player Name",-20} {"Team Name",-20} {"Games Played",20} {"Runs",20} {"Home Runs",20} {"Points",20}\n"); foreach (var i in myList) { if (i.PlayerType == PlayerType.BaseballPlayer) { Console.WriteLine(i); } } Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("\nEditing Baseball Player\n"); Console.WriteLine("Enter ID of player you want to edit: "); int id; bool idIsNumeric = Int32.TryParse(Console.ReadLine(), out id); while (!idIsNumeric) { Console.WriteLine("Invalid Input.Please Try again\n"); Console.WriteLine("Enter ID of player you want to edit: "); idIsNumeric = Int32.TryParse(Console.ReadLine(), out id); } if (id <= myList.Count && myList[id - 1].PlayerType == PlayerType.BaseballPlayer) { Console.Write("Enter Player's new name: "); string baseballPlayer = Console.ReadLine(); while (string.IsNullOrWhiteSpace(baseballPlayer)) { Console.WriteLine("Invalid Input.Please Try again\n"); Console.Write("Enter Player's new name: "); baseballPlayer = Console.ReadLine(); } Console.Write("Enter Team name: "); string baseballTeamName = Console.ReadLine(); while (string.IsNullOrWhiteSpace(baseballTeamName)) { Console.WriteLine("Invalid Input.Please Try again\n"); Console.Write("Enter new Team name: "); baseballTeamName = Console.ReadLine(); } Console.Write("Enter Games Played: "); int baseballGamesPlayed; bool gamePlayedIsNumeric = Int32.TryParse(Console.ReadLine(), out baseballGamesPlayed); while (!gamePlayedIsNumeric) { Console.WriteLine("Invalid Input.Please Try again\n"); Console.Write("Enter Games Played: "); gamePlayedIsNumeric = Int32.TryParse(Console.ReadLine(), out baseballGamesPlayed); } Console.Write("Enter Runs: "); int baseballRuns; bool runsIsNumeric = Int32.TryParse(Console.ReadLine(), out baseballRuns); while (!runsIsNumeric) { Console.WriteLine("Invalid Input.Please Try again\n"); Console.Write("Enter Runs: "); runsIsNumeric = Int32.TryParse(Console.ReadLine(), out baseballRuns); } Console.Write("Enter HomeRuns: "); int baseballHomeRuns; bool homeRunsIsNumeric = Int32.TryParse(Console.ReadLine(), out baseballHomeRuns); while (!homeRunsIsNumeric) { Console.WriteLine("Invalid Input.Please Try again\n"); Console.Write("Enter Home Runs: "); homeRunsIsNumeric = Int32.TryParse(Console.ReadLine(), out baseballHomeRuns); } myList[id - 1] = new BaseballPlayer(PlayerType.BaseballPlayer, id, baseballPlayer, baseballTeamName, baseballGamesPlayed, baseballRuns, baseballHomeRuns); Console.WriteLine("\nPlayer with ID = " + id + " updated\n"); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"{"Player Type",-20} {"Player ID",10} {"Player Name",-20} {"Team Name",-20} {"Games Played",20} {"Runs",20} {"Home Runs",20} {"Points",20}\n"); foreach (var i in myList) { if (i.PlayerType == PlayerType.BaseballPlayer) { Console.WriteLine(i); } } } else { Console.WriteLine("Invalid Input! We dont have that id in Baseball Players Table"); EditingBaseballPlayer(); } Console.ReadKey(); Console.ForegroundColor = ConsoleColor.White; EditingPlayer(); }
//AddingBaseballPlayer method public static void AddingBaseballPlayer() { Console.WriteLine("\nAdding Baseball Player\n"); Console.Write("Enter Player Name: "); string baseballPlayer = Console.ReadLine(); while (string.IsNullOrWhiteSpace(baseballPlayer)) { Console.WriteLine("Invalid Input.Please Try again\n"); Console.Write("Enter Player Name: "); baseballPlayer = Console.ReadLine(); } Console.Write("Enter Team name: "); string baseballTeamName = Console.ReadLine(); while (string.IsNullOrWhiteSpace(baseballTeamName)) { Console.WriteLine("Invalid Input.Please Try again\n"); Console.Write("Enter Team name: "); baseballTeamName = Console.ReadLine(); } Console.Write("Enter Games Played: "); int baseballGamesPlayed; bool gamePlayedIsNumeric = Int32.TryParse(Console.ReadLine(), out baseballGamesPlayed); while (!gamePlayedIsNumeric) { Console.WriteLine("Invalid Input.Please Try again\n"); Console.Write("Enter Games Played: "); gamePlayedIsNumeric = Int32.TryParse(Console.ReadLine(), out baseballGamesPlayed); } Console.Write("Enter Runs: "); int baseballRuns; bool runsIsNumeric = Int32.TryParse(Console.ReadLine(), out baseballRuns); while (!runsIsNumeric) { Console.WriteLine("Invalid Input.Please Try again\n"); Console.Write("Enter Runs: "); runsIsNumeric = Int32.TryParse(Console.ReadLine(), out baseballRuns); } Console.Write("Enter Home Runs: "); int baseballHomeRuns; bool homeRunsIsNumeric = Int32.TryParse(Console.ReadLine(), out baseballHomeRuns); while (!homeRunsIsNumeric) { Console.WriteLine("Invalid Input.Please Try again\n"); Console.Write("Enter Home Runs: "); homeRunsIsNumeric = Int32.TryParse(Console.ReadLine(), out baseballHomeRuns); } Player newBaseballPlayer = new BaseballPlayer(PlayerType.BaseballPlayer, myList.Count + 1, baseballPlayer, baseballTeamName, baseballGamesPlayed, baseballRuns, baseballHomeRuns); myList.Add(newBaseballPlayer); Console.WriteLine("\nNew Player Added.\n\nView All Baseball Player: \n\n"); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine($"{"Player Type",-20} {"Player ID",10} {"Player Name",-20} {"Team Name",-20} {"Games Played",20} {"Runs",20} {"Home Runs",20} {"Points",20}\n"); foreach (var i in myList) { if (i.PlayerType == PlayerType.BaseballPlayer) { Console.WriteLine(i); } } Console.ReadKey(); Console.ForegroundColor = ConsoleColor.White; AddingPlayer(); }