public IEnumerable<Team> GetForCurrentYear() { using (var dbContext = new TtcDbContext()) { var teams = dbContext.Teams .Include(x => x.Players) .Include(x => x.Opponents) .Where(x => x.Year == Constants.CurrentSeason) .ToArray(); var result = Mapper.Map<IList<TeamEntity>, IList<Team>>(teams); foreach (var team in result) { var key = new TeamRankingKey(team.Competition, team.Frenoy.DivisionId); if (RankingCache.ContainsKey(key)) { team.Ranking = RankingCache[key]; } } InvalidateCache(); return result; } }
public async Task <IEnumerable <Team> > GetForCurrentYear() { using (var dbContext = new TtcDbContext()) { int currentSeason = dbContext.CurrentSeason; var teams = await dbContext.Teams .Include(x => x.Players) .Include(x => x.Opponents) .Where(x => x.Year == currentSeason) .ToArrayAsync(); var result = Mapper.Map <IList <TeamEntity>, IList <Team> >(teams); foreach (var team in result) { var key = new TeamRankingKey(team.Competition, team.Frenoy.DivisionId); if (RankingCache.ContainsKey(key)) { team.Ranking = RankingCache[key]; } } InvalidateCache(); return(result); } }
private ICollection<DivisionRanking> GetFrenoyRanking(TtcDbContext dbContext, Competition competition, int divisionId) { var key = new TeamRankingKey(competition, divisionId); if (RankingCache.ContainsKey(key)) { return RankingCache[key]; } var frenoy = new FrenoyTeamsApi(dbContext, competition); var ranking = frenoy.GetTeamRankings(divisionId); if (!RankingCache.ContainsKey(key)) { lock (CacheLock) { if (!RankingCache.ContainsKey(key)) { RankingCache.Add(key, ranking); } } } return ranking; }
private static async Task <ICollection <DivisionRanking> > GetFrenoyRanking(TtcDbContext dbContext, Competition competition, int divisionId) { var key = new TeamRankingKey(competition, divisionId); if (RankingCache.ContainsKey(key)) { return(RankingCache[key]); } var frenoy = new FrenoyTeamsApi(dbContext, competition); var ranking = await frenoy.GetTeamRankings(divisionId); if (!RankingCache.ContainsKey(key)) { lock (CacheLock) { if (!RankingCache.ContainsKey(key)) { RankingCache.Add(key, ranking); } } } return(ranking); }