public List <PatientDetails> AddPatientTestResult(PatientTestSummary patientModel) { try { using (DiabeticSystemEntities context = new DiabeticSystemEntities()) { PatientTestResult testresult = new PatientTestResult() { PatientId = patientModel.PatientId, SugarBeforeFasting = patientModel.SugarLevelBeforeFasting, SugarAfterFasting = patientModel.SugarLevelAfterFasting, TestDate = patientModel.TestDate }; context.PatientTestResults.Add(testresult); context.SaveChanges(); PatientMembershipDetail membership = (from m in context.PatientMembershipDetails where m.PatientId == patientModel.PatientId select m).FirstOrDefault(); membership.TestRemaining = membership.TestRemaining - 1; context.Entry(membership).State = EntityState.Modified; context.SaveChanges(); } } catch (Exception err) { throw; } return(GetAllPatientDetails(string.Empty, string.Empty)); }
public async Task <List <PatientDetails> > SubmitPatientTestResults(PatientTestSummary testsummary) { List <PatientDetails> patientDetails = new List <PatientDetails>(); using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(azureapiaddress); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage Res = await client.PostAsJsonAsync($"api/DiabeticApi/AddPatientTestResults", testsummary); //Checking the response is successful or not which is sent using HttpClient if (Res.IsSuccessStatusCode) { //Storing the response details recieved from web api var response = Res.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into the Employee list patientDetails = JsonConvert.DeserializeObject <List <PatientDetails> >(response); } } return(patientDetails); }
public async Task <ActionResult> AddPatientTestResult(PatientTestSummary testsummary) { List <PatientDetails> patientDetails = new List <PatientDetails>(); try { patientDetails = await apiCall.SubmitPatientTestResults(testsummary); return(RedirectToAction("Index", "DiabeticDiagnostic")); } catch (Exception) { ModelState.AddModelError("Error", "Something went wrong"); return(View()); } }
public IHttpActionResult AddPatientTestResults(PatientTestSummary testsummary) { List <PatientDetails> testresults = repository.AddPatientTestResult(testsummary); return(Ok(testresults)); }