public TeamsRepository() { sportsRepo = new SportsRepository(); var ctx = HttpContext.Current; IEnumerable <SportInfo> sports = sportsRepo.GetAllSports(); if (ctx != null) { if (ctx.Cache[cacheKey] == null) { TeamInfo teamOne = new TeamInfo() { TeamName = "Miami Heat", TeamSport = sports.FirstOrDefault(x => x.SportName == "Basketball") }; TeamInfo teamTwo = new TeamInfo() { TeamName = "Los Angeles Lakers", TeamSport = sports.FirstOrDefault(x => x.SportName == "Basketball") }; TeamInfo teamThree = new TeamInfo() { TeamName = "Pittsburg Steelers", TeamSport = sports.FirstOrDefault(x => x.SportName == "Football") }; TeamInfo teamFour = new TeamInfo() { TeamName = "Indianapolis Colts", TeamSport = sports.FirstOrDefault(x => x.SportName == "Football") }; List <TeamInfo> teams = new List <TeamInfo>(); teams.Add(teamOne); teams.Add(teamTwo); teams.Add(teamThree); teams.Add(teamFour); ctx.Cache[cacheKey] = teams; } } }
public PlayersRepository() { sportsRepo = new SportsRepository(); teamRepo = new TeamsRepository(); var ctx = HttpContext.Current; IEnumerable <SportInfo> sports = sportsRepo.GetAllSports(); IEnumerable <TeamInfo> teams = teamRepo.GetAllTeams(); if (ctx != null) { if (ctx.Cache[cacheKey] == null) { List <PlayerInfo> players = new List <PlayerInfo>(); createBasketballPlayersData(players, teams); createFootballPlayersData(players, teams); ctx.Cache[cacheKey] = players; } } }