Ejemplo n.º 1
0
        public async Task <IActionResult> PutPokemon([FromRoute] string id, [FromBody] Pokemon pokemon)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != pokemon.Code)
            {
                return(BadRequest());
            }

            _context.Entry(pokemon).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PokemonExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 2
0
 public ActionResult Edit(Pokemon pokemon, int PokeTypeId)
 {
     if (PokeTypeId != 0)
     {
         var returnedJoin = _db.Pokedex
                            .Any(join => join.PokemonId == pokemon.PokemonId && join.PokeTypeId == PokeTypeId);
         if (!returnedJoin)
         {
             _db.Pokedex.Add(new Pokedex()
             {
                 PokeTypeId = PokeTypeId, PokemonId = pokemon.PokemonId
             });
         }
     }
     _db.Entry(pokemon).State = EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 3
0
 public ActionResult Edit([Bind(Include = "Id,Name,Description,Rating,Picture")] Pokemon pokemon)
 {
     if (ModelState.IsValid)
     {
         db.Entry(pokemon).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(pokemon));
 }
Ejemplo n.º 4
0
        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 ActionResult Edit(Trainer trainer)
 {
     _db.Entry(trainer).State = EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }
 public ActionResult Edit(PokeType pokeType)
 {
     _db.Entry(pokeType).State = EntityState.Modified;
     _db.SaveChanges();
     return(RedirectToAction("Index"));
 }