public IActionResult ReleasePokemon(UserPokemonDetails model) { CaughtPokemon pokemon = _context.CaughtPokemon.Find(model.PokemonId); var user = _userContext.Users.Find(userManager.GetUserId(User)); user.UniquePokemon = user.UniquePokemon - 1; _context.CaughtPokemon.Remove(pokemon); _userContext.SaveChanges(); _context.SaveChanges(); return(RedirectToAction("Pokemon", "Account")); }
public async Task <IActionResult> ConfirmReleasePokemon(int id, string query) { // Join the Pokémon table to the Caught Pokémon table to create a model with more information, including date the Pokémon was captured UserPokemonDetails model = await _context.Pokemon.Join(_context.CaughtPokemon.Where(p => p.PokemonID == id), pokemon => pokemon.PokemonName, caught => caught.PokemonName, (pokemon, caught) => new UserPokemonDetails { PokemonId = caught.PokemonID, CatchDate = caught.CatchDate, Image = caught.IsShiny ? pokemon.ShinyImage : pokemon.Image, Name = caught.PokemonName, PokedexNum = pokemon.PokedexNum, IsShiny = caught.IsShiny, Type_1 = pokemon.Type_1, Type_2 = pokemon.Type_2, queryString = query }).FirstOrDefaultAsync(); return(PartialView("_ConfirmReleasePokemon", model)); }