public async Task <IActionResult> Put(long id, [FromBody] AlunoInputDTO inputDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var aluno = new Aluno(inputDTO.Nome, inputDTO.Sobrenome, inputDTO.Email, inputDTO.Celular, inputDTO.Cpf, inputDTO.DataDeNascimento, inputDTO.Genero, inputDTO.InicioDeMatricula, inputDTO.AcademiaId); aluno.Id = id; var result = await _service.Put(aluno); if (result != null) { return(Ok(result)); } else { return(BadRequest()); } } catch (ArgumentException e) { return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message)); } }
public async Task <IActionResult> Post([FromBody] AlunoInputDTO inputDTO) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { var aluno = new Aluno(inputDTO.Nome, inputDTO.Sobrenome, inputDTO.Email, inputDTO.Celular, inputDTO.Cpf, inputDTO.DataDeNascimento, inputDTO.Genero, inputDTO.InicioDeMatricula, inputDTO.AcademiaId); var result = await _service.Post(aluno); if (result != null) { return(Created(new Uri(Url.Link("GetWithId", new { id = result.Id })), result)); } else { return(BadRequest()); } } catch (ArgumentException e) { return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message)); } }