Esempio n. 1
0
        public async Task AddNextEvolution()
        {
            var pokemonsSerialized = _pokemonRepository.GetPokemonsSerialized();

            foreach (var pokeSer in pokemonsSerialized)
            {
                if (pokeSer.NextEvolution != null && pokeSer.NextEvolution.Count > 0)
                {
                    var poke = _pokemonRepository.GetPokemonByNumber(pokeSer.Number);

                    foreach (var evolution in pokeSer.NextEvolution)
                    {
                        if (!poke.NextEvolution.Where(x => x.NextPokemon.Number == evolution.Number).Any())
                        {
                            var newPoke      = _pokemonRepository.GetPokemonByNumber(evolution.Number);
                            var newEvolution = new PokemonNextEvolution(poke.Id, newPoke.Id);
                            dbSet.Add(newEvolution);

                            context.SaveChanges();
                        }
                    }
                }
            }

            await context.SaveChangesAsync();
        }
Esempio n. 2
0
        public async Task <GetPokemonDto> BuildPokemonByNumber(int pokemonNumber)
        {
            GetPokemonDto pokemonDto;

            pokemonDto = await _pokemonRepository.GetPokemonByNumber(pokemonNumber);

            if (String.IsNullOrEmpty(pokemonDto.Name))
            {
                pokemonDto = await _pokemonExternalService.GetPokemonByNumber(pokemonNumber);
                await AddPokemon(pokemonDto.Adapt <AddPokemonDto>());
            }

            return(pokemonDto);
        }