public PokemonsViewModel() { try { _pageResource = new PokemonOffsetLimit(); _pokemonList = new ObservableCollection <PokemonCard>(); _nextCommand = new RelayCommand(Next); _previousCommand = new RelayCommand(Previous); _selectCommand = new SelectPokemonCommand(Select); ExecuteRequest(_firstRequest); } catch (Exception e) { Console.WriteLine("error " + e.Message); } }
public void ExecuteRequest(String url) { try { if (String.IsNullOrEmpty(url)) { throw new Exception(); } this._pageResource = JsonConvert.DeserializeObject <PokemonOffsetLimit>(HttpRequest.HttpGetRequest(url)); this._pokemonList.Clear(); foreach (BaseContent content in _pageResource.results) { try { this._pokemonList.Add(JsonConvert.DeserializeObject <PokemonCard>(HttpRequest.HttpGetRequest(content.Url))); } catch (Exception e) { Console.WriteLine("error while tryng to insert pokemon - " + e.Message); } } } catch (Exception e) { Console.WriteLine("error while tryng to request pokemons - " + e.Message); } }