public async Task <IActionResult> GetPokemonDetails(int id, SelectPokemonViewModel userPokemon)
        {
            _quizFlow.ResetSession(); //user may have left quiz screen so reset session
            if (userPokemon.PokemonSelected != null)
            {
                var pokedexViewModelString = await _pokemonService.GetAdditionalPokemonInfo(userPokemon.PokemonSelected);

                return(View(pokedexViewModelString));
            }

            var pokedexViewModel = new PokedexViewModel();

            pokedexViewModel = await _pokemonService.GetAdditionalPokemonInfo(id);

            return(View(pokedexViewModel));
        }
Beispiel #2
0
        public async Task <SelectPokemonViewModel> GetPokemonByGeneration()
        {
            var generationTracker = 1;
            var pokemonList       = new SelectPokemonViewModel();

            while (generationTracker < 8)
            {
                var api = await _pokemonApi.GetPokemonByGeneration(generationTracker);

                if (generationTracker == 1)
                {
                    foreach (var pokemon in api.pokemon_species)
                    {
                        var pokemonToList = new PokemonResponse
                        {
                            PokemonName = pokemon.name
                        };
                        pokemonList.Gen1.Add(pokemonToList);
                        pokemonList.Gen1.Sort((x, y) => string.Compare(x.PokemonName, y.PokemonName));
                    }
                }
                else if (generationTracker == 2)
                {
                    foreach (var pokemon in api.pokemon_species)
                    {
                        var pokemonToList = new PokemonResponse
                        {
                            PokemonName = pokemon.name
                        };
                        pokemonList.Gen2.Add(pokemonToList);
                        pokemonList.Gen2.Sort((x, y) => string.Compare(x.PokemonName, y.PokemonName));
                    }
                }
                else if (generationTracker == 3)
                {
                    foreach (var pokemon in api.pokemon_species)
                    {
                        var pokemonToList = new PokemonResponse
                        {
                            PokemonName = pokemon.name
                        };
                        pokemonList.Gen3.Add(pokemonToList);
                        pokemonList.Gen3.Sort((x, y) => string.Compare(x.PokemonName, y.PokemonName));
                    }
                }
                else if (generationTracker == 4)
                {
                    foreach (var pokemon in api.pokemon_species)
                    {
                        var pokemonToList = new PokemonResponse
                        {
                            PokemonName = pokemon.name
                        };
                        pokemonList.Gen4.Add(pokemonToList);
                        pokemonList.Gen4.Sort((x, y) => string.Compare(x.PokemonName, y.PokemonName));
                    }
                }
                else if (generationTracker == 5)
                {
                    foreach (var pokemon in api.pokemon_species)
                    {
                        var pokemonToList = new PokemonResponse
                        {
                            PokemonName = pokemon.name
                        };
                        pokemonList.Gen5.Add(pokemonToList);
                        pokemonList.Gen5.Sort((x, y) => string.Compare(x.PokemonName, y.PokemonName));
                    }
                }
                else if (generationTracker == 6)
                {
                    foreach (var pokemon in api.pokemon_species)
                    {
                        var pokemonToList = new PokemonResponse
                        {
                            PokemonName = pokemon.name
                        };
                        pokemonList.Gen6.Add(pokemonToList);
                        pokemonList.Gen6.Sort((x, y) => string.Compare(x.PokemonName, y.PokemonName));
                    }
                }
                else if (generationTracker == 7)
                {
                    foreach (var pokemon in api.pokemon_species)
                    {
                        var pokemonToList = new PokemonResponse
                        {
                            PokemonName = pokemon.name
                        };
                        pokemonList.Gen7.Add(pokemonToList);
                        pokemonList.Gen7.Sort((x, y) => string.Compare(x.PokemonName, y.PokemonName));
                    }
                }
                generationTracker++;
            }
            return(pokemonList);
        }