public ActionResult NewPatientReportForm() { var testTitles = _context.TestTitles.ToList(); var doctors = _context.Doctors.ToList(); var newPatientReportViewModel = new NewPatientReportViewModel { Patient = new Patient { }, Report = new Report { Date = DateTime.Now }, TestTitles = testTitles, Doctors = doctors }; return(View(newPatientReportViewModel)); }
public ActionResult SaveNewPatientReport(NewPatientReportViewModel newPatientReportViewModel) { if (!ModelState.IsValid) { var patientReportViewModel = new NewPatientReportViewModel { Patient = newPatientReportViewModel.Patient }; return(View("NewPatientReportForm", patientReportViewModel)); } var patient = newPatientReportViewModel.Patient; _context.Patients.Add(patient); var reports = new List <Report>(); if (newPatientReportViewModel.TestTitleIds[0] == null) { return(HttpNotFound("Form Not Submitted Correctly")); } foreach (var testTitleId in newPatientReportViewModel.TestTitleIds) { if (!testTitleId.HasValue) { continue; } var testTitle = _context.TestTitles.Single(t => t.Id == testTitleId); var Report = new Report { PatientId = patient.Id, TestTitleId = testTitle.Id, Price = testTitle.Price, }; _context.Reports.Add(Report); reports.Add(Report); } var billFormViewModel = new BillFormViewModel { Reports = reports, Patient = patient, Report = newPatientReportViewModel.Report, Bill = new Bill { Discount = 0 }, }; return(View("BillForm", billFormViewModel)); }