public ActionResult InsertNewPatient(PatientDto patientRequestModel) { if (patientRequestModel != null) { try { if (patientRequestModel.Patient != null) { patientService.InsertPatient(patientRequestModel.Patient); } else { return(Ok(GetResponse(ResponseType.FAIL, ResponseStatusCode.FAIL, GetError(ErrorCodes.dataNotFound, "Failed", "Patient details are missing")))); } //Insert the selected tests if (patientRequestModel.SelectedTestTitles != null && patientRequestModel.SelectedTestTitles.Count > 0) { foreach (var title in patientRequestModel.SelectedTestTitles) { var otherTests = testService.GetOtherTests().Where(otherTest => otherTest.TestGroupId == title.GroupId && otherTest.TestTitleId == title.Id).ToList(); if (otherTests != null && otherTests.Count > 0) { foreach (var test in otherTests) { testService.InsertTestResult(new TestResults().GetTestResult(test, patientRequestModel.Patient)); } } } } } catch (Exception e) { Program.Logger.Error(e); return(Ok(GetResponse(ResponseType.FAIL, ResponseStatusCode.FAIL, GetError(ErrorCodes.dataNotFound, "Failed", "Error occurred while registering new patient")))); } return(Ok(GetResponse(ResponseType.ACK, ResponseStatusCode.SUCCESS))); } else { return(BadRequest(GetResponse(ResponseType.ERROR, ResponseStatusCode.ERROR, GetError(ErrorCodes.invalidData, "Invalid input", "Please enter proper patient details")))); } }