public async Task <ActionResult <Patient> > PostPatient(PatientCreateDto patient) { //var item = this._mapper.Map<Patient>(patient); //await this._repository.Add(item); //var dto = this._mapper.Map<PatientDto>(item); //return CreatedAtAction("GetPatient", new { id = dto.Id }, dto); if (patient == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var finalPatient = _mapper.Map <Patient>(patient); await _repository.Add(finalPatient); if (!await _repository.Save()) { return(StatusCode(500, "A problem happened while handling your request.")); } var createdPatientToReturn = _mapper.Map <PatientDto>(finalPatient); return(CreatedAtAction("Getpatient", new { id = createdPatientToReturn.Id }, createdPatientToReturn)); }