Esempio n. 1
0
        public async Task <ActionResult <Player> > Post(Player player, int teamId)
        {
            var thisTeam = _db.Teams
                           .Include(entry => entry.Players)
                           .FirstOrDefault(entry => entry.TeamId == teamId);

            if (thisTeam != null)
            {
                player.TeamId = thisTeam.TeamId;
                player.Team   = thisTeam.TeamName;
                _db.Players.Add(player);
                await _db.SaveChangesAsync();
            }
            else
            {
                return(BadRequest());
            }

            return(CreatedAtAction("Post", new { id = player.PlayerId }, player));
        }
Esempio n. 2
0
 public async Task <ActionResult <Team> > Put(int id, Team team)
 {
     if (id != team.TeamId)
     {
         return(BadRequest());
     }
     _db.Entry(team).State = EntityState.Modified;
     try
     {
         await _db.SaveChangesAsync();
     }
     catch (DbUpdateConcurrencyException)
     {
         if (!TeamExists(id))
         {
             return(NotFound());
         }
         else
         {
             throw;
         }
     }
     return(NoContent());
 }