public IActionResult PostTeam([FromBody] TeamPostDto teamDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var team = new Team() { Name = teamDto.Name, GameId = teamDto.GameId, CountryId = teamDto.CountryId }; var create = _repo.Create <Team>(team); if (!create.Success) { return(Ok(false)); } return(Ok(true)); } catch (Exception e) { return(BadRequest(e.Message)); } }
public async Task <IActionResult> PutTeam([FromRoute] string id, [FromBody] TeamPostDto teamDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != teamDto.Id) { return(BadRequest()); } try { var getTeam = await _repo.GetFirstAsync <Team>(x => x.Id == id); if (!getTeam.Success) { return(NotFound()); } var team = getTeam.Data; team.Name = teamDto.Name ?? team.Name; team.GameId = teamDto.GameId; team.CountryId = teamDto.CountryId; var update = _repo.Update <Team>(team); if (update.Success) { return(Ok(true)); } return(Ok(false)); } catch (DbUpdateConcurrencyException) { if (!TeamExists(id)) { return(NotFound()); } else { return(BadRequest()); } } }