public async Task <IActionResult> PutHistoricPlayer(int id, HistoricPlayer historicPlayer) { if (id != historicPlayer.HistoricPlayerID) { return(BadRequest()); } _context.Entry(historicPlayer).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!HistoricPlayerExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutNbaTeam(int id, NbaTeam nbaTeam) { if (id != nbaTeam.NbaTeamID) { return(BadRequest()); } _context.Entry(nbaTeam).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!NbaTeamExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PatchTeam([FromRoute] int id, [FromBody] TeamReqModel teamReq) { // Final request model validation if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var team = teamReq.ConvertToTeamModel(); team.Id = id; var existingTeam = await TeamExistsAsync(team.Name); if (existingTeam) { return(BadRequest($"Team name: {team.Name} already exists.")); } _context.Entry(team).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TeamExists(id)) { return(NotFound()); } else { throw; } } return(Ok()); }