Esempio n. 1
0
        private async Task <List <GameViewModel> > GetLiveHighestRatedGamesAsync()
        {
            var popularGamesView = new List <GameViewModel>();
            var popularGames     = await _igdbClient.GetHighestRatedGamesAsync();

            if (popularGames != null && popularGames.Any())
            {
                await popularGames.ForEachAsync(10, async game =>
                {
                    var coverArt         = $"//images.igdb.com/igdb/image/upload/t_cover_big/{game.Cover?.ImageId}.jpg";
                    var gameViewModel    = new GameViewModel(game.Name, coverArt);
                    gameViewModel.Review = new ReviewViewModel(game);

                    var twitchGames = await _twitchClient.GetGamesByNameAsync(game.Name);

                    if (twitchGames.Data != null && twitchGames.Data.Any())
                    {
                        var firstMatch = twitchGames.Data.First();
                        var id         = Int32.Parse(firstMatch.Id);
                        var streams    = await _twitchClient.GetStreamsByIdAsync(id);

                        if (streams.Data != null && streams.Data.Any())
                        {
                            var streamsViewModel = new List <StreamViewModel>();
                            streamsViewModel.AddRange(streams.Data.Select(x => new StreamViewModel(x)));
                            gameViewModel.Streams = streamsViewModel;
                        }
                    }

                    popularGamesView.Add(gameViewModel);
                });
            }

            return(popularGamesView);
        }