public ActionResult AddPrescriptionToPatient(string patientID) { if (patientID == null) { return(View("Error")); } var db = new ApplicationDbContext(); var non = from map in db.PrescriptionMap join prescription in db.Prescriptions on map.PrescriptionID equals prescription.PrescriptionID where map.UserID == patientID select prescription; var p = db.Prescriptions.ToList().Except(non).ToList(); var name = db.Users.Where(u => u.Id == patientID).FirstOrDefault().Identifier.FullName; var model = new AddPrescriptionToPatientViewModel { Prescriptions = p, PatientName = name, PatientID = patientID, }; return(View(model)); }
public ActionResult AddPrescriptionToPatient(AddPrescriptionToPatientViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var db = new ApplicationDbContext(); var patientPrescription = new PrescriptionsMap { UserID = model.PatientID, PrescriptionID = model.PrescriptionID }; db.PrescriptionMap.Add(patientPrescription); db.SaveChanges(); return(RedirectToAction("Index")); }