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 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); }