public async Task <ServicesResponse <ParsedGame> > Get(ulong gameId) { var game = (await new GameController().Get(gameId)).Data; var parsedGame = new ParsedGame() { id = game.id, name = game.name, first_release_date = game.first_release_date, cover = game.cover?.url, websites = game.websites, summary = game.summary, rating = game.rating, aggregated_rating = game.aggregated_rating, total_rating = game.total_rating, alternative_names = game.alternative_names, external = game.external, screenshots = game.screenshots, videos = game.videos, artworks = game.artworks, release_dates = game.release_dates }; if (game.developers?.Any() == true) { parsedGame.developers = new List <string>(); foreach (var dev in game.developers) { var dbDev = (await(new CompanyController()).Get(dev)).Data; parsedGame.developers.Add(dbDev.name); } } if (game.game_modes?.Any() == true) { parsedGame.game_modes = new List <string>(); foreach (var mode in game.game_modes) { var dbMode = (await(new GameModeController()).Get(mode)).Data; parsedGame.game_modes.Add(dbMode.name); } } if (game.genres?.Any() == true) { parsedGame.genres = new List <string>(); foreach (var genre in game.genres) { var dbGenre = (await(new GenreController()).Get(genre)).Data; parsedGame.genres.Add(dbGenre.name); } } if (game.publishers?.Any() == true) { parsedGame.publishers = new List <string>(); foreach (var pub in game.publishers) { var dbDev = (await(new CompanyController()).Get(pub)).Data; parsedGame.publishers.Add(dbDev.name); } } if (game.themes?.Any() == true) { parsedGame.themes = new List <string>(); foreach (var theme in game.themes) { var dbTheme = (await(new ThemeController()).Get(theme)).Data; parsedGame.themes.Add(dbTheme.name); } } if (game.platforms?.Any() == true) { parsedGame.platforms = new List <string>(); foreach (var platform in game.platforms) { var dbPlatform = (await(new PlatformController()).Get(platform)).Data; parsedGame.platforms.Add(dbPlatform.name); } } return(new ServicesResponse <ParsedGame>(parsedGame)); }
public async Task <ServicesResponse <ParsedGame> > Get(ulong gameId, [FromQuery] string apiKey) { var cacheCollection = Program.DatabaseCache.GetCollection <ParsedGame>("IGBDParsedGameCache"); var cache = cacheCollection.FindById(gameId); if (cache != null) { var dateDiff = DateTime.Now - cache.creation_time; if (dateDiff.TotalHours <= IGDB.CacheTimeout) { return(new ServicesResponse <ParsedGame>(cache, string.Empty)); } } var url = string.Format(@"games/{0}?fields=name%2Csummary%2Cdevelopers%2Cpublishers%2Cgenres%2Cfirst_release_date%2Ccover%2Cthemes%2Cgame_modes%2Cwebsites&limit=40&offset=0&search={0}", gameId); var libraryStringResult = await IGDB.SendStringRequest(url, apiKey); var game = JsonConvert.DeserializeObject <List <Game> >(libraryStringResult)[0]; var parsedGame = new ParsedGame() { id = game.id, name = game.name, first_release_date = game.first_release_date, cover = game.cover?.url, websites = game.websites, summary = game.summary, creation_time = DateTime.Now }; if (game.developers?.Any() == true) { parsedGame.developers = new List <string>(); foreach (var dev in game.developers) { var dbDev = (await(new CompanyController()).Get(dev, apiKey)).Data; parsedGame.developers.Add(dbDev.name); } } if (game.game_modes?.Any() == true) { parsedGame.game_modes = new List <string>(); foreach (var mode in game.game_modes) { var dbMode = (await(new GameModeController()).Get(mode, apiKey)).Data; parsedGame.game_modes.Add(dbMode.name); } } if (game.genres?.Any() == true) { parsedGame.genres = new List <string>(); foreach (var genre in game.genres) { var dbGenre = (await(new GenreController()).Get(genre, apiKey)).Data; parsedGame.genres.Add(dbGenre.name); } } if (game.publishers?.Any() == true) { parsedGame.publishers = new List <string>(); foreach (var pub in game.publishers) { var dbDev = (await(new CompanyController()).Get(pub, apiKey)).Data; parsedGame.publishers.Add(dbDev.name); } } if (game.themes?.Any() == true) { parsedGame.themes = new List <string>(); foreach (var genre in game.themes) { var dbTheme = (await(new ThemeController()).Get(genre, apiKey)).Data; parsedGame.themes.Add(dbTheme.name); } } cacheCollection.Upsert(parsedGame); return(new ServicesResponse <ParsedGame>(parsedGame, string.Empty)); }