public async Task <IActionResult> UpdatePaciente(int id, [FromBody] PacienteForCreationDto paciente) { try { if (paciente == null) { return(BadRequest("O objeto nulo")); } if (!ModelState.IsValid) { return(BadRequest("Objeto inválido")); } var PacienteEntity = await _repository.Paciente.GetPacienteByIdAsync(id); if (PacienteEntity == null) { return(NotFound()); } _mapper.Map(paciente, PacienteEntity); _repository.Paciente.UpdatePaciente(PacienteEntity); await _repository.SaveAsync(); return(NoContent()); } catch (Exception) { return(StatusCode(500, "Internal server error")); } }
public async Task <IActionResult> CreatePaciente([FromBody] PacienteForCreationDto paciente) { try { if (paciente == null) { return(BadRequest("O objeto nulo")); } if (!ModelState.IsValid) { return(BadRequest("Objeto inválido")); } var pacienteEntity = _mapper.Map <Paciente>(paciente); _repository.Paciente.CreatePaciente(pacienteEntity); await _repository.SaveAsync(); var createdPaciente = _mapper.Map <PacienteDTO>(pacienteEntity); return(CreatedAtRoute("PacienteById", new { id = createdPaciente.Id }, createdPaciente)); } catch (Exception) { return(StatusCode(500, "Internal server error")); } }