/// <summary> /// saves an instance of type Dantist in DB /// </summary> /// <param name="dantist"></param> public static void SaveDantist(Dantist dantist) { using (var ctx = new PatientsContext()) { ctx.Entry(dantist).State = EntityState.Modified; ctx.SaveChanges(); } }
/// <summary> /// adds an instance of type Dantist to DB /// </summary> /// <param name="dantist"></param> public static void AddDantist(Dantist dantist) { using (var ctx = new PatientsContext()) { ctx.Dantists.Add(dantist); ctx.SaveChanges(); } }
/// <summary> /// returns list of instances of type Patient for an instance of type Dantist wiht given id /// </summary> /// <param name="searchText"></param> /// <param name="dantistId"></param> /// <returns></returns> public static List <Patient> GetAllPatients(string searchText, int dantistId) { using (var ctx = new PatientsContext()) { Dantist dantist = ctx.Dantists.Find(dantistId); List <Patient> patients = dantist.Patients.Where(s => s.Name.Contains(searchText) || s.Surname.Contains(searchText) || s.PhoneNumber.Contains(searchText) || s.Address.CityOrTown.Contains(searchText) || string.IsNullOrEmpty(searchText)).OrderByDescending(s => s.LastVisitDate).ToList(); return(patients); } }
/// <summary> /// add an instance of type Patient to an instance of type Dantist /// with given id and saves that to DB /// </summary> /// <param name="dantistId"></param> /// <param name="patient"></param> public static void AddPatient(int dantistId, Patient patient) { using (var ctx = new PatientsContext()) { Dantist dantist = ctx.Dantists.Find(dantistId); dantist.Patients.Add(patient); ctx.Entry(dantist).State = EntityState.Modified; ctx.SaveChanges(); } }
/// <summary> /// checks if an instance exists in DB /// </summary> /// <param name="Name"></param> /// <param name="Surname"></param> /// <param name="DoB"></param> /// <param name="dantistId"></param> /// <returns></returns> public static Boolean PatientExists(string Name, string Surname, DateTime DoB, int dantistId) { using (var ctx = new PatientsContext()) { Dantist dantist = ctx.Dantists.Find(dantistId); if (dantist.Patients.Where(s => s.Name == Name && s.Surname == Surname && s.DOB == DoB).ToList().Count != 0) { return(true); } return(false); } }
/// <summary> /// removes an instance of type Dantist from DB /// </summary> /// <param name="id"></param> public static void DeleteDantist(int?id, string folderPath) { using (var ctx = new PatientsContext()) { Dantist dantist = ctx.Dantists.Find(id); ctx.Dantists.Remove(dantist); ctx.SaveChanges(); } if (Directory.Exists(folderPath)) { Directory.Delete(folderPath, true); } }
/// <summary> /// returns an instance of type Dantist upon given parameters /// </summary> /// <param name="id"></param> /// <param name="email"></param> /// <returns></returns> public static Dantist GetDantist(int?id = null, string email = null) { using (var ctx = new PatientsContext()) { if (id != null) { Dantist dantist = ctx.Dantists.Find(id); return(dantist); } else { List <Dantist> dantists = ctx.Dantists.Where(m => m.Email == email).ToList(); Dantist dantist = dantists[0]; return(dantist); } } }