public IActionResult SaveChanges(FavoritePokemon updatedName) //saves changes when user adds nickname to favorited pokemon { FavoritePokemon pokemonName = _pokemonContext.FavoritePokemon.Find(updatedName.Id); pokemonName.Nickname = updatedName.Nickname; _pokemonContext.Entry(pokemonName).State = Microsoft.EntityFrameworkCore.EntityState.Modified; _pokemonContext.Update(pokemonName); _pokemonContext.SaveChanges(); return(RedirectToAction("Favorites")); }
public IActionResult UpdatePokemon(int id) { FavoritePokemon pokemon = _pokemonContext.FavoritePokemon.Find(id); if (pokemon == null) { return(RedirectToAction("Favorites")); } else { return(View(pokemon)); } }
public async Task <IActionResult> AddPokemon(int id) //adds and saves favorited pokemon to the database { string activeUserId = User.FindFirst(ClaimTypes.NameIdentifier).Value; //finds the user id of the logged in user var newFav = new FavoritePokemon(); var newpokemon = await _pokemonDAL.GetPokemonById(id); string typeConcat = ""; string statConcat = ""; string spriteConcat = ""; for (int i = 0; i < newpokemon.types.Length; i++) //turns types information into a comma separated value to store in db { typeConcat += newpokemon.types[i].type.name; if (i != newpokemon.types.Length - 1) { typeConcat += ","; } } for (int i = 0; i < newpokemon.stats.Length; i++) //turns stats information into a comma separated value to store in db { statConcat += newpokemon.stats[i].stat.name; statConcat += ": "; statConcat += newpokemon.stats[i].base_stat; if (i != newpokemon.stats.Length - 1) { statConcat += ","; } } spriteConcat += newpokemon.sprites.front_default + "," + newpokemon.sprites.front_shiny; //turns sprites information into a comma separated value to store in db newFav.Name = newpokemon.name; newFav.PokemonId = newpokemon.id; newFav.Height = newpokemon.height.ToString(); newFav.Sprite = spriteConcat; newFav.Type = typeConcat; newFav.Weight = newpokemon.weight.ToString(); newFav.BaseExp = newpokemon.base_experience.ToString(); newFav.Stats = statConcat; newFav.UserId = activeUserId; if (ModelState.IsValid) { _pokemonContext.FavoritePokemon.Add(newFav); _pokemonContext.SaveChanges(); } return(RedirectToAction("Favorites")); }