/// <summary> /// Search for a pokemon by pokedex number. /// </summary> /// <param name="id">The pokedex number.</param> /// <returns></returns> public async Task <IActionResult> Get(int id) { //find by the dex number var poke = await _context.Pokemon.Include(p => p.Harvestables).Where(pokemon => pokemon.PokedexNumber == id).Include(p => p.Harvestables).FirstOrDefaultAsync(); // couldn't find it if (poke == null) { return(NotFound()); } //can't find harvestables, populate defaults with No if (poke.Harvestables == null || poke.Harvestables.Count == 0) { poke.Harvestables = await _context.Harvestables.Select(h => new HarvestItem() { IsHarvestable = false, Name = h.Name }).ToListAsync(); } // return pokeview var vm = new PokeView(_config) { Pokemon = poke, PokeImages = await _context.PokemonImages.Where(img => img.PokemonID == id).ToListAsync() }; if (Request.Headers["X-Requested-With"] == "XMLHttpRequest") { return(PartialView("/Views/Partials/PokeDetails.cshtml", vm)); } return(View("/Views/Partials/PokeDetails.cshtml", vm)); }
public async Task <IActionResult> Index() { var PokeList = await _PokedexContext.Pokemon.Include(p => p.Harvestables).Where(p => p.IsInMod).ToListAsync(); PokeView pv; if (PokeList.Count > 0) { var pokeImages = await _PokedexContext.PokemonImages.Where(img => img.PokemonID == PokeList.First().ID).ToListAsync(); pv = new PokeView(_config) { PokemonList = PokeList, Pokemon = PokeList.First(), PokeImages = pokeImages }; } else { pv = new PokeView(_config) { PokemonList = PokeList, Pokemon = null } }; pv.HomeContent = await _PokedexContext.HomePageContent.FirstAsync(); return(View(pv)); }
/// <summary> /// Search thorugh the pokedex for a name of a pokemon /// </summary> /// <remarks>This method is called via Javascript</remarks> /// <param name="keywords">keyphrase used to match against a name</param> /// <returns>Partial View of pokemon list</returns> public async Task <IActionResult> Search(string keywords) { PokeView pv = new PokeView(_config); //search, return everything if it's an empty string if (string.IsNullOrWhiteSpace(keywords)) { pv.PokemonList = await _context.Pokemon.Where(p => p.IsInMod).ToListAsync(); } else { pv.PokemonList = await _context.Pokemon.Where(pokemon => pokemon.Name.ToLower().Contains(keywords.ToLower()) && pokemon.IsInMod) .ToListAsync(); } return(PartialView("/Views/Partials/PokeList.cshtml", pv)); }