public ActionResult SaveOldPatientBill(OldPatientReportBillViewModel oldPatientReportBillViewModel) { //Patient Age Change var patient = _context.Patients.Single(p => p.Id == oldPatientReportBillViewModel.PatientId); if (!(patient.Age == oldPatientReportBillViewModel.Patient.Age)) { patient.Age = oldPatientReportBillViewModel.Patient.Age; _context.SaveChanges(); } // var reports = new List <Report>(); foreach (var report in oldPatientReportBillViewModel.Reports) { var newReport = new Report { ConsultingPathologistId = _context.Defaultvalues.Single(d => d.Id == 1).Id, Date = oldPatientReportBillViewModel.Report.Date, DateAdded = DateTime.Now, DigitalSignature = oldPatientReportBillViewModel.Report.DigitalSignature, DoctorId = oldPatientReportBillViewModel.Report.DoctorId, InvestigatedBy = oldPatientReportBillViewModel.Report.InvestigatedBy, PatientId = oldPatientReportBillViewModel.PatientId, ReportBy = oldPatientReportBillViewModel.Report.ReportBy, TestTitleId = report.TestTitleId, Price = report.Price }; _context.Reports.Add(newReport); _context.SaveChanges(); reports.Add(newReport); } var bill = new Bill { PatientId = oldPatientReportBillViewModel.PatientId, DoctorId = oldPatientReportBillViewModel.Report.DoctorId, BillBy = "", Date = oldPatientReportBillViewModel.Report.Date, Discount = oldPatientReportBillViewModel.Bill.Discount }; _context.Bills.Add(bill); _context.SaveChanges(); foreach (var report in reports) { var newBillItem = new Billitem { BillId = bill.Id, ReportId = report.Id }; _context.BillItems.Add(newBillItem); _context.SaveChanges(); } return(null); }
public ActionResult SaveOldPatientReport(OldPatientReportViewModel oldPatientReportViewModel) { if (!ModelState.IsValid) { return(View("OldPatientForm", oldPatientReportViewModel)); } var patient = _context.Patients.SingleOrDefault(r => r.Id == oldPatientReportViewModel.PatientId); if (patient == null) { return(HttpNotFound("Patient Not Found")); } if (oldPatientReportViewModel.TestTitleIds[0] == null) { return(HttpNotFound("Form Not Submitted Correctly")); } var reports = new List <Report>(); foreach (var testTitleId in oldPatientReportViewModel.TestTitleIds) { if (!testTitleId.HasValue) { continue; } var testTitle = _context.TestTitles.Single(t => t.Id == testTitleId); var report = new Report { //PatientId = patient.Id, TestTitleId = testTitle.Id, //InvestigatedBy = "", //ReportBy = "", //ConsultingPathologistId = _context.Defaultvalues.Single(d => d.Id == 1).Id, //Date=oldPatientReportViewModel.Report.Date, //DateAdded=DateTime.Now, Price = testTitle.Price, //DoctorId=oldPatientReportViewModel.Report.DoctorId, //DigitalSignature=oldPatientReportViewModel.Report.DigitalSignature }; _context.Reports.Add(report); reports.Add(report); } var oldPatientReportBill = new OldPatientReportBillViewModel { Reports = reports, PatientId = patient.Id, Patient = patient, Report = oldPatientReportViewModel.Report , Bill = new Bill { Discount = 0 } }; return(View("OldPatientBillForm", oldPatientReportBill)); }
public ActionResult OldPatientBillForm(OldPatientReportBillViewModel oldPatientReportBillViewModel) { return(View(oldPatientReportBillViewModel)); }