//public Entities.JsonModels.RootObject GetAllPoke() => _client.GetPokemons(); //public Entities.GetPokemonModels.Pokemon GetPoke(int pokeId) => _client.GetPokemon(pokeId); public async Task <PagedList <Pokemon> > GetAllPokemonsAsync(PokemonParameters pokemonParameters, bool trackChanges) { var pokemons = await FindAll(trackChanges) .FilterByType(pokemonParameters.Type) .SearchByName(pokemonParameters.Name) .Sort(pokemonParameters.OrderBy) .Include(p => p.Types) .ToListAsync(); return(PagedList <Pokemon> .ToPagedList(pokemons, pokemonParameters.PageNumber, pokemonParameters.PageSize)); }
public static IEnumerable <KeyValuePair <string, PokemonData> > GetPokemon(PokemonParameters parameters) { var query = StaticData.PokemonDictionary.AsEnumerable(); if (!string.IsNullOrWhiteSpace(parameters.Name)) { query = query.Where(x => string.Equals(x.Key, parameters.Name)); } if (parameters.Type1.HasValue) { query = query.Where(x => x.Value.Type.Contains(parameters.Type1.Value.ToString())); } if (parameters.Type2.HasValue) { query = query.Where(x => x.Value.Type.Contains(parameters.Type2.Value.ToString())); } if (parameters.MinFieldLevel.Min.HasValue) { query = query.Where(x => x.Value.MinimumFieldLevel >= parameters.MinFieldLevel.Min.Value); } if (parameters.MinFieldLevel.Max.HasValue) { query = query.Where(x => x.Value.MinimumFieldLevel <= parameters.MinFieldLevel.Max.Value); } if (parameters.SRRange.Min.HasValue) { query = query.Where(x => x.Value.SpeciesRating >= parameters.SRRange.Min.Value); } if (parameters.SRRange.Max.HasValue) { query = query.Where(x => x.Value.SpeciesRating <= parameters.SRRange.Max.Value); } if (parameters.ACRange.Min.HasValue) { query = query.Where(x => x.Value.ArmorClass >= parameters.ACRange.Min.Value); } if (parameters.ACRange.Max.HasValue) { query = query.Where(x => x.Value.ArmorClass <= parameters.ACRange.Max.Value); } return(query); }
public async Task <IEnumerable <PokemonDto> > FindAllPokemonsAsync(PokemonParameters pokemonParameters, HttpResponse response) { var pokemons = await _repositoryManager.Pokemon.GetAllPokemonsAsync(pokemonParameters, false); if (pokemons == null) { _logger.LogInformation($"Pokemons doesn't exist in the DB."); } response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(pokemons.Metadata)); return(_mapper.Map <IEnumerable <PokemonDto> >(pokemons)); }
public async Task <IActionResult> GetPokemons([FromQuery] PokemonParameters pokemonParameters) { var pokemons = await _pokemonService.FindAllPokemonsAsync(pokemonParameters, Response); var pokemons1 = pokemons.Where(p => p.Types.Any(t => t.Name.Contains("p"))); if (pokemons1 == null) { return(NotFound()); } var links = _pokemonService.GenerateLinksOrShapePokemons(pokemons1, pokemonParameters, HttpContext); return(links.HasLinks ? Ok(links.LinkedShapedObjects) : Ok(links.ShapedObjects)); }
public LinkResponse GenerateLinksOrShapePokemons(IEnumerable <PokemonDto> pokemons, PokemonParameters pokemonParameters, HttpContext context) => _pokemonLinks.TryGenerateLinks(pokemons, pokemonParameters.Fields, context);