public void AddGamestoDatabase() { using (var context = new NHLContext()) { //TODO - refactor converting string searched team to teams.ID into a fucntion to be reused elsewhere Console.WriteLine("Enter game date : "); DateTime gameDate = DateTime.Parse(Console.ReadLine()); Console.WriteLine("Enter Home Team : "); string homeTeam = Console.ReadLine(); var homeTeamID = from t in context.Teams where t.TeamName == homeTeam select t.ID; Console.WriteLine("Enter Away Team : "); string awayTeam = Console.ReadLine(); var awayTeamID = from t in context.Teams where t.TeamName == awayTeam select t.ID; Console.WriteLine("Enter Home Score : "); int homeScore = int.Parse(Console.ReadLine()); Console.WriteLine("Enter Away Score : "); int awayScore = int.Parse(Console.ReadLine()); var game = new Games(gameDate, homeTeamID.First(), awayTeamID.First(), homeScore, awayScore); context.Games.Add(game); context.SaveChanges(); } }
public void UpdateTeamsTable() { using (var context = new NHLContext()) { var resultID = context.TempScoreTable.SingleOrDefault(t => t.SearchedTeamID == SearchedTeamID); if (resultID != null) { resultID.GoalAllowed = GoalAllowed; resultID.GoalScored = GoalScored; context.SaveChanges(); } } }