/// <summary> /// Updates all non-DIHMT-specific fields of the /// game in the database /// </summary> /// <param name="dGame">The game to be updated</param> /// <param name="includeGenres">Indicates whether or not the DbGameGenres-table should be updated, too</param> private static void UpdateGameFromGb(DisplayGame dGame, bool includeGenres = false) { var gbGame = GbGateway.GetGame(dGame.Id); var dbGame = CreateDbGameObjectWithoutNavigation(gbGame); dbGame.IsRated = dGame.IsRated; dbGame.Basically = dGame.Basically; dbGame.RatingExplanation = dGame.RatingExplanation; dbGame.RatingLastUpdated = dGame.RatingLastUpdated; dbGame.LastUpdated = DateTime.UtcNow; DbAccess.SaveGame(dbGame); var dbGamePlatforms = CreateDbGamePlatformsListWithoutNavigation(gbGame); DbAccess.SaveGamePlatforms(dbGamePlatforms); if (!includeGenres || gbGame.Genres == null || !gbGame.Genres.Any()) { return; } var dbGameGenres = CreateDbGameGenresListWithoutNavigation(gbGame); DbAccess.SaveGameGenres(dbGameGenres); }
/// <summary> /// Pulls any necessary information on the game from /// GiantBomb, and then returns a DisplayGame object that /// is as updated as it needs to be. /// </summary> /// <param name="id">Id of the game to be returned</param> /// <param name="includeGenres">Whether to look for genre info or not</param> /// <returns></returns> public static DisplayGame RefreshDisplayGame(int id, bool includeGenres = false) { var displayGame = CreateDisplayGameObject(id); if (displayGame == null) { var gbGame = GbGateway.GetGame(id); SaveGameToDb(gbGame); displayGame = CreateDisplayGameObject(id); } if (includeGenres && (displayGame.Genres == null || !displayGame.Genres.Any())) { UpdateGameFromGb(displayGame, true); displayGame = CreateDisplayGameObject(id); } if ((DateTime.UtcNow - displayGame.LastUpdated).Days >= 7) { UpdateGameFromGb(displayGame); displayGame = CreateDisplayGameObject(id); } return(displayGame); }
/// <summary> /// Queries GB's search engine for games, and adds any results /// to our DB that don't yet exist there. /// </summary> /// <param name="q">Query</param> /// <param name="page">Page number</param> public static void SearchGbAndCacheResults(string q, int page) { var rawResults = GbGateway.Search(q, page); if (!rawResults.Any()) { return; } var filteredResults = FilterOutUnsupportedPlatforms(rawResults); SaveGamesToDb(filteredResults); }