Esempio n. 1
0
        public async Task <PokemonChunckModel> GetPokemonsChunck(string u)
        {
            PokemonHttpCallerModel caller = new PokemonHttpCallerModel();
            PokemonChunckModel     chunck = await caller.GetPokemon(u);

            chunck.PokeList = chunck.PokeList;
            chunck.Next     = chunck.Next;
            chunck.Previous = chunck.Previous;
            chunck.Message  = chunck.Message;

            return(chunck);
        }
Esempio n. 2
0
        public async Task <PokemonChunckModel> GetPokemonsFromApi()
        {
            var uri = "https://pokeapi.co/api/v2/pokemon/";


            //PokemonHttpCallerModel caller = new PokemonHttpCallerModel();
            PokemonChunckModel chunck = await GetPokemonsChunck(uri);

            //await caller.GetPokemon(uri);

            chunck.PokeList = chunck.PokeList;
            chunck.Next     = chunck.Next;
            chunck.Previous = chunck.Previous;
            chunck.Message  = chunck.Message;

            return(chunck);
        }
Esempio n. 3
0
        public async Task <PokemonChunckModel> GetPokemon(string u)
        {
            var                next     = "";
            var                previous = "";
            var                pokemons = new List <PokemonModel>();
            string             msn;
            PokemonChunckModel chunck = new PokemonChunckModel();
            HttpCaller         caller = new HttpCaller();
            var                resp   = await caller.GetMethod(u);

            try
            {
                var json_d = JsonConvert.DeserializeObject <PokemonCallApiModel>(resp);
                if (json_d.count > 0)
                {
                    next     = json_d.next;
                    previous = json_d.previous;
                    msn      = "success";
                    foreach (var Result in json_d.results)
                    {
                        pokemons.Add(new PokemonModel()
                        {
                            Name = Result.name,
                            Url  = Result.url,
                            Link = "https://img.pokemondb.net/artwork/" + Result.name + ".jpg"
                        });
                    }
                }
                else
                {
                    msn = "No hay pokemon en la cuenta api";
                }
            }
            catch (Exception ex)
            {
                msn = "Error";
                Console.WriteLine("ERROR---------------------------- " + ex.Message + " // " + ex.ToString());
            }

            chunck.PokeList = pokemons;
            chunck.Next     = next;
            chunck.Previous = previous;
            chunck.Message  = msn;

            return(chunck);
        }