public List <LeagueSeasonTeams> GetRangeOfTeams(List <int> teamIds, LeagueSeason season) { if (Db.Database.Connection.State == System.Data.ConnectionState.Closed) { Db.Database.Connection.Open(); } var results = (from n in Db.LeagueSeasonTeams where teamIds.Contains(n.FootballTeamId) && n.LeagueSeasonId == season.LeagueSeasonId select n).ToList(); if (results.Count != teamIds.Count) { var repo = new LogRepository(); foreach (int teamId in teamIds) { if (results.FindIndex(i => i.FootballTeamId == teamId) == -1) { //create new record in LeagueSeasonTeams table var team = new LeagueSeasonTeams { FootballTeamId = teamId, LeagueSeasonId = season.LeagueSeasonId, LastUpdate = DateTime.Now }; Db.LeagueSeasonTeams.Add(team); Db.SaveChanges(); results.Add(team); repo.WriteLog(Database.SystemData.Severity.Information, "Insert to LeagueSeasonTeams table new record", nameof(AnalysisDataRepository), "localhost", "[teamId = " + team.FootballTeamId + "][LeagueSeasonId = " + team.LeagueSeasonId + "]", ""); } } } Db.Database.Connection.Close(); return(results); }
private void AnalyzedTeam(LeagueSeasonTeams team) { var teamsSeasonGames = leagueRepo.GetAllSeasonGames(team.LeagueSeasonId) .Where(g => g.HomeTeamId == team.FootballTeamId || g.AwayTeamId == team.FootballTeamId); var teamForm5 = new FootballTeamForm { TeamId = team.FootballTeamId, LeagueSeasonId = team.LeagueSeasonId, TimePeriod = TimePeriod.Last5Matches }; var teamForm10 = new FootballTeamForm { TeamId = team.FootballTeamId, LeagueSeasonId = team.LeagueSeasonId, TimePeriod = TimePeriod.Last10Matches }; var teamFormAll = new FootballTeamForm { TeamId = team.FootballTeamId, LeagueSeasonId = team.LeagueSeasonId, TimePeriod = TimePeriod.AllMatches }; var teamFormAllHome = new FootballTeamForm { TeamId = team.FootballTeamId, LeagueSeasonId = team.LeagueSeasonId, TimePeriod = TimePeriod.AllHomeMatches }; var teamFormAllAway = new FootballTeamForm { TeamId = team.FootballTeamId, LeagueSeasonId = team.LeagueSeasonId, TimePeriod = TimePeriod.AllAwayMatches }; var i = 0; foreach (var game in teamsSeasonGames) { if (game.Result == 0) { continue; } var gameTotal = game.HomeTeamGoals + game.AwayTeamGoals; ComputeTeamFormByGame(teamFormAll, game); if (i < 5) { ComputeTeamFormByGame(teamForm5, game); } if (i < 10) { ComputeTeamFormByGame(teamForm10, game); } if (game.HomeTeamId == team.FootballTeamId) { ComputeTeamFormByGame(teamFormAllHome, game); } else { ComputeTeamFormByGame(teamFormAllAway, game); } i++; } analysisRepo.AddOrUpdateTeamForm(teamForm5); analysisRepo.AddOrUpdateTeamForm(teamForm10); analysisRepo.AddOrUpdateTeamForm(teamFormAll); analysisRepo.AddOrUpdateTeamForm(teamFormAllHome); analysisRepo.AddOrUpdateTeamForm(teamFormAllAway); }