public IActionResult Post([FromBody] Patient patient) { try { if (ModelState.IsValid) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(Patient)); using (StringWriter textWriter = new StringWriter()) { xmlSerializer.Serialize(textWriter, patient); var patientDetails = textWriter.ToString(); var patientRecord = new PatientRecord() { Record = patientDetails }; repository.AddPatientRecord(patientRecord); if (repository.Save()) { return(Created($"/api/patients/{patientRecord.Id}", mapper.Map <Patient, PatientViewModel>(patient))); } } } else { return(BadRequest(ModelState)); } } catch (Exception ex) { logger.LogError($"Failed to save new patient record: {ex}"); } return(BadRequest("Failed to save new patient record")); }