public PlayerResult Get(int id) { var dataCache = new DataCache(); var player = PlayersService.GetInstance().GetPlayer(id, dataCache); var sports = SportsService.GetInstance().GetSports(); var leagues = LeaguesService.GetInstance().GetLeagues(); var stats = StatsService.GetInstance().GetAllStats(playerID: id, dataCache: dataCache); var statTypes = GamesService.GetInstance().GetStatTypes().OrderBy(s => s.GridDisplayOrder); var playerResult = new PlayerResult() { ID = player.ID, Name = player.Name, Games = player.Games?.Select(g => new PlayerGameResult() { ID = g.ID, GameDate = g.GameDate, Team1Score = g.Team1Score, Team2Score = g.Team2Score }).ToList(), Teams = player.Teams?.Select(t => { var league = leagues.First(l => l.ID == t.LeagueID); var sport = sports.First(s => s.ID == league.SportID); return(new PlayerTeamResult() { ID = t.ID, Name = t.Name, LeagueID = t.LeagueID, Number = t.PlayerNumber, SportID = league.SportID, LeagueName = string.Format("{0} - {1} {2} - {3}", sport.Name, league.StartDate.Year, league.Season.ToString(), league.Name) }); }).OrderBy(t => t.LeagueName).ToList(), HockeyStats = stats .Select(s => ConvertObjects.ConvertType(s)) .Where(s => s.Sport == SportsList.Hockey && leagues.Exists(l => l.ID == s.LeagueID)) .OrderBy(s => leagues.First(l => l.ID == s.LeagueID).StartDate) .ToList(), BaseballStats = stats .Select(s => ConvertObjects.ConvertType(s)) .Where(s => s.Sport == SportsList.Baseball && leagues.Exists(l => l.ID == s.LeagueID)) .OrderBy(s => leagues.First(l => l.ID == s.LeagueID).StartDate) .ToList(), BasketballStats = stats .Select(s => ConvertObjects.ConvertType(s)) .Where(s => s.Sport == SportsList.Basketball && leagues.Exists(l => l.ID == s.LeagueID)) .OrderBy(s => leagues.First(l => l.ID == s.LeagueID).StartDate) .ToList(), HockeyStatTypes = statTypes.Select(s => ConvertObjects.ConvertType(s)).Where(st => st.Sport == SportsList.Hockey).ToList(), BaseballStatTypes = statTypes.Select(s => ConvertObjects.ConvertType(s)).Where(st => st.Sport == SportsList.Baseball).ToList(), BasketballStatTypes = statTypes.Select(s => ConvertObjects.ConvertType(s)).Where(st => st.Sport == SportsList.Basketball).ToList(), }; UpdateStatRow(playerResult.HockeyStats, player, leagues); UpdateStatRow(playerResult.BaseballStats, player, leagues); UpdateStatRow(playerResult.BasketballStats, player, leagues); return(playerResult); }
public ActionResult Index(string city) { NewsService newsService = new NewsService(); WeatherService weatherService = new WeatherService(); SportsService sportsService = new SportsService(); PortalViewModel model = new PortalViewModel { News = newsService.GetNews(city), Weather = weatherService.GetWeather(city), Sports = sportsService.GetScores(city) }; return(View(model)); }
private SportsResults GetSportsLeagues() { var sportsResults = new SportsResults(); var currentLeagues = new List <SportsResult>(); var oldLeagues = new List <SportsResult>(); var sports = SportsService.GetInstance().GetSports(); foreach (var sport in sports) { var leagues = LeaguesService.GetInstance().GetLeagues(sport.ID); foreach (var league in leagues) { string name = string.Format("{0} - {1} {2} - {3}", sport.Name, league.StartDate.Year, league.Season.ToString(), league.Name); bool isCurrent = league.StartDate <= DateTime.Now && league.EndDate >= DateTime.Now; if (isCurrent) { currentLeagues.Add(new SportsResult() { Name = name, SportsLeagueSelection = new SportsLeague() { LeagueID = league.ID, SportID = sport.ID } }); } else { oldLeagues.Add(new SportsResult() { Name = name, SportsLeagueSelection = new SportsLeague() { LeagueID = league.ID, SportID = sport.ID } }); } } } sportsResults.OldLeagues = oldLeagues; sportsResults.CurrentLeagues = currentLeagues; return(sportsResults); }
public async Task <ActionResult> Index(string city) { NewsService newsService = new NewsService(); WeatherService weatherService = new WeatherService(); SportsService sportsService = new SportsService(); var newsTask = newsService.GetNewsAsync(city); var weatherTask = weatherService.GetWeatherAsync(city); var sportsTask = sportsService.GetScoresAsync(city); await Task.WhenAll(newsTask, weatherTask, sportsTask); PortalViewModel model = new PortalViewModel { News = newsTask.Result, Weather = weatherTask.Result, Sports = sportsTask.Result }; return(View(model)); }
public SportsController(SportsService sportsService) { _sportsService = sportsService; }