Exemplo n.º 1
0
        public async Task <ActionResult <Pkmn> > PostPkmn(Pkmn pkmn)
        {
            if (pkmn.Type == null || pkmn.Name == null || pkmn.Type == "" || pkmn.Name == "")
            {
                return(BadRequest("Some required fields are empty (Type or Name)."));
            }
            else
            {
                if (pkmn.Height == 0)
                {
                    pkmn.Height = 5;
                }
                if (pkmn.Weight == 0)
                {
                    pkmn.Weight = 5;
                }
                if (!Array.Exists(types, element => element == pkmn.Type))
                {
                    return(BadRequest("Invalid type."));
                }
            }
            _context.Pkmn.Add(pkmn);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetPkmn", new { id = pkmn.Id }, pkmn));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PutPkmn(int id, Pkmn pkmn)
        {
            if (id != pkmn.Id)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
 public void UpdateDisguisedPID(SpritedBattlePokemonParty sParty)
 {
     if (Pkmn.Status2.HasFlag(PBEStatus2.Disguised))
     {
         PBEBattlePokemon p = Pkmn.GetPkmnWouldDisguiseAs();
         DisguisedPID = p is null ? PartyPkmn.PID : sParty[p].PartyPkmn.PID;
     }
     else
     {
         DisguisedPID = PartyPkmn.PID; // Set back to normal
     }
 }