public async Task LikeGameAsync(int gameId) { var gameDetails = new GameDetailedResponse(); string path = Path.Combine(FileSystem.AppDataDirectory, FileName); if (File.Exists(path)) { var file = File.ReadAllText(path); if (!string.IsNullOrEmpty(file)) { FavoriteGames = JsonConvert.DeserializeObject <Dictionary <int, GameDetailedResponse> >(file); } if (!FavoriteGames.ContainsKey(gameId)) { gameDetails = await _gameApiClient.GetGameByIdAsync(gameId); gameDetails.IsLiked = true; await SaveFavoriteGameToFileAsync(gameDetails); } } else { gameDetails = await _gameApiClient.GetGameByIdAsync(gameId); gameDetails.IsLiked = true; await SaveFavoriteGameToFileAsync(gameDetails); } }
private async ValueTask <bool> IsGameExistsAsync(long gameId) { try { await _gameApiClient.GetGameByIdAsync(gameId); return(true); } catch (ApiException ex) when(ex.StatusCode == HttpStatusCode.NotFound) { return(false); } }