public ActionResult Create(PhysicianPreferenceCreate model, string[] selectedMedications, string[] selectedEquipments, string[] selectedProcedures) { if (selectedMedications != null && selectedEquipments != null && selectedProcedures != null) { foreach (var medication in selectedMedications) { var physPrefService = CreatePhysicianPreferenceService(); var medId = int.Parse(medication); model.MedicationId = medId; physPrefService.CreatePhysicianPreference(model); } foreach (var equipment in selectedEquipments) { var physPrefService = CreatePhysicianPreferenceService(); var equipId = int.Parse(equipment); model.EquipmentId = equipId; physPrefService.CreatePhysicianPreference(model); } foreach (var procedure in selectedProcedures) { var physPrefService = CreatePhysicianPreferenceService(); var procedId = int.Parse(procedure); model.ProcedureId = procedId; physPrefService.CreatePhysicianPreference(model); } } if (ModelState.IsValid) { return(RedirectToAction("Index")); } if (!ModelState.IsValid) { return(View(model)); } var service = CreatePhysicianPreferenceService(); if (service.CreatePhysicianPreference(model)) { TempData["SaveResult"] = "Your physician preference entry was saved."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Physician preference entry could not be created."); return(View(model)); }
public bool CreatePhysicianPreference(PhysicianPreferenceCreate model) { var entity = new PhysicianPreference() { OwnerID = _userId, PhysicianID = model.PhysicianId, ProcedureID = model.ProcedureId, EquipmentID = model.EquipmentId, MedicationID = model.MedicationId, PreferenceNote = model.PreferenceNote }; using (var ctx = new ApplicationDbContext()) { ctx.PhysicianPreferences.Add(entity); return(ctx.SaveChanges() == 1); } }