//Returns all games matching search to be added to db public async Task <IEnumerable <Game> > GetGameToAddSearchResultsAsync(string searchFilter, int pageNumber) { var token = new CancellationTokenSource().Token; var nameSearchString = $"fields cover, name, id; where name ~ *\"{searchFilter}\"*; limit 10; offset {pageNumber * 10};"; var iGdb = new IGDB(); //create igdb object to post game info request var game = await iGdb.PostBasicAsync(nameSearchString, token, GamesUrl); var gameList = new List <Game>(); foreach (var gameJToken in game) //each game has its details assigned to object + added to game list { var gameId = gameJToken .SelectToken("id") .Value <int>(); var gameName = gameJToken .SelectToken("name") .Value <string>(); var basicGameDetails = new Game { Id = gameId, Name = gameName, CoverArtUrl = await GetCoverUrl(gameJToken) }; gameList.Add(basicGameDetails); } //returns list of games to be iterated over in search results return(gameList); }
//Get "x" number of games, used for getting top rated games public async Task <IEnumerable <Game> > GetGamesIdAndPicAsync(IEnumerable <int> idList) { var token = new CancellationTokenSource().Token; var topRatedSearchString = $"fields cover, id; where id = ({string.Join(", ", idList)});"; var iGdb = new IGDB(); //create igdb object to post game info request var game = await iGdb.PostBasicAsync(topRatedSearchString, token, GamesUrl); var gameList = new List <Game>(); foreach (JToken gameJToken in game.Children()) //each game has its details assigned to object + added to game list { var gameId = gameJToken .Value <int>("id"); var basicGameDetails = new Game { Id = gameId, CoverArtUrl = await GetCoverUrl(gameJToken) }; gameList.Add(basicGameDetails); } //returns list of games to be iterated over in search results return(gameList); }
public async Task <IEnumerable <Genre> > GetAllGenresAsync() { var token = new CancellationTokenSource().Token; var iGdb = new IGDB(); var genreJArray = await iGdb.PostBasicAsync(GetGenreString, token, GenreUrl); return((from genreResult in genreJArray let genreId = (int)genreResult.SelectToken("id") let genreName = genreResult.SelectToken("name").ToString() select new Genre { Id = genreId, Name = genreName }).ToList()); }
public IGDBService() { _context = new ApplicationDbContext(); IGDB = new IGDB(); //create igdb object to post game info request }
public async Task <List <Game> > GetSearchResultsAsync(string idList, string searchFilter, string searchType) { string[] websiteValues = { }; var token = new CancellationTokenSource().Token; var topRatedSearchString = $"fields genres, first_release_date, platforms, cover, name, id; where id = ({idList});"; var genreSearchString = $"fields genres, first_release_date, platforms, cover, name, id; where id = ({idList}) & genres = ({searchFilter});"; var nameSearchString = $"fields genres, first_release_date, platforms, cover, name, id; where id = ({idList}) & name ~ *\"{searchFilter}\"*;"; var iGdb = new IGDB(); //create igdb object to post game info request var game = new JArray(); //Case for what type of search (genre, name, etc) switch (searchType) { case "genre": game = await iGdb.PostBasicAsync(genreSearchString, token, GamesUrl); break; case "name": game = await iGdb.PostBasicAsync(nameSearchString, token, GamesUrl); break; case "topRated": game = await iGdb.PostBasicAsync(topRatedSearchString, token, GamesUrl); break; } var gameList = new List <Game>(); foreach (var gameJToken in game) //each game has its details assigned to object + added to game list { var gameName = gameJToken .SelectToken("name") .ToString(); var gameId = gameJToken .SelectToken("id") .Value <int>(); // Gets dictionary with genre ID as key and genre name as value var genreDetails = await GetGenresAsync(gameJToken); var gameWebsite = websiteValues.FirstOrDefault(); var gameObj = new Game { Id = gameId, Name = gameName, FirstReleaseDate = GetReleaseDate(gameJToken).ToString(), GenreName = genreDetails.Values.ToList(), GenreIds = ListToString(genreDetails.Keys.ToList()), Platforms = GetPlatforms(gameJToken), CoverArtUrl = await GetCoverUrl(gameJToken), Websites = gameWebsite }; gameList.Add(gameObj); } //returns list of games to be iterated over in search results return(gameList); }