private float GetFantasyPointsForNflPlayerDuringWeek(NflPlayer nflPlayer, int week) { var involvedGames = _dbContext.NflGames // find games during that week that the player's team was involved in .Where(g => g.Week == week) .Where(g => g.PrimaryTeamId == nflPlayer.Team.Id || g.SecondaryTeamId == nflPlayer.Team.Id) .ToList(); // return list from database var playerScore = involvedGames // convert/calculate the fantasy points for that player's team in those games .Select(g => GetFantasyPointsForTeamInGame(g, nflPlayer.TeamId)) // and add up all the points from the games (if multiple). .Sum(); return(playerScore); }
public WeatherToolVM GetTeamRoster(string teamId, int gameWeekId) { FantasyContent content; WeatherToolVM weatherToolVM = new WeatherToolVM(); string url = string.Format(@"http://fantasysports.yahooapis.com/fantasy/v2/team/{0}/roster;week={1}", teamId, gameWeekId); try { content = Client.ExecuteRequest <FantasyContent>(url); //content = Client.ExecuteRequest<FantasyContent>(@"http://fantasysports.yahooapis.com/fantasy/v2/team/359.l.247388.t.9/roster;week=2"); } catch (SportsApiException) { var token = Client.RefreshToken(); content = Client.ExecuteRequest <FantasyContent>(url); } List <NflPlayer> roster = new List <NflPlayer>(); foreach (var player in content?.Team.TeamRoster.Players) { NflPlayer nflPlayer = new NflPlayer() { NflTeam = player.EditorialTeamFullName, PlayerName = player.Name.Full, PlayerPosition = player.DisplayPosition, PlayerImageUrl = player.ImageUrl }; roster.Add(nflPlayer); } weatherToolVM.TeamRoster = roster; return(weatherToolVM); }