//Saves specialties to all of admins practices public static void SaveSpecialties(PatientLogModel db, List <RefPracSpecialty> specialties, string practiceAdmin) { List <int> ids = new List <int>(); ids = (from a in db.RefPracAdmins where a.UserID == practiceAdmin select a.PracID).ToList(); foreach (int id in ids) { bool exists = (from s in db.RefPracSpecialties where s.PracID == id select s.ID).Any(); if (exists) { foreach (RefPracSpecialty spec in specialties) { RefPracSpecialty oldSpec = (from s in db.RefPracSpecialties where s.PracID == id && s.Specialty == spec.Specialty select s).Single(); oldSpec.FirstChoice = spec.FirstChoice; oldSpec.Backup = spec.Backup; oldSpec.Comments = spec.Comments; db.Entry(oldSpec).State = EntityState.Modified; } } else { foreach (RefPracSpecialty spec in specialties) { spec.PracID = id; db.RefPracSpecialties.Add(spec); } } } db.SaveChanges(); }
//Saves specialties public static void SaveSpecialties(PatientLogModel db, List <RefPracSpecialty> specialties) { //Zero ID indicates this has never been saved to the database before if (specialties[0].ID == 0) { foreach (RefPracSpecialty spec in specialties) { db.RefPracSpecialties.Add(spec); } } else { foreach (RefPracSpecialty spec in specialties) { RefPracSpecialty oldSpec = (from s in db.RefPracSpecialties where s.ID == spec.ID select s).Single(); oldSpec.FirstChoice = spec.FirstChoice; oldSpec.Backup = spec.Backup; oldSpec.Comments = spec.Comments; db.Entry(oldSpec).State = EntityState.Modified; } } db.SaveChanges(); }