private async void LoadingModel(object sender, DoWorkEventArgs e) { tempdoc.Clear(); tempApp.Clear(); try { using (me = new MedicalModel(ConfigurationManager.Connect())) { await me.Database.Connection.OpenAsync(); foreach (ScheduleM.Doctor doctor in me.userdata.Where(a => !me.accountdata.FirstOrDefault(b => b.IdAD == a.AccountDataIdUD).DeletedAD).ToList() .Where(n => me.priviledges.FirstOrDefault(p => p.IdP == me.accountdata.FirstOrDefault(b => b.IdAD == n.AccountDataIdUD).PriviledgesIdAD).IncludeScheduleP).ToList() .Select(a => new ScheduleM.Doctor { Id = a.IdUD, Name = a.NameUD, })) { tempdoc.Add(doctor); } foreach (ScheduleM.Patient patient in me.patientdata.OrderBy(p => p.NamePD).Select(p => new ScheduleM.Patient() { Id = p.IdPD, Name = p.NamePD, TajNumber = p.TAJNumberPD })) { ScheduleM.Patients.Add(patient); } if (me.scheduledata.Count() != 0) { foreach (scheduledata appointment in me.scheduledata.ToList()) { ScheduleM.Appointment app = new ScheduleM.Appointment() { StillNotVisited = appointment.StillNotVisitedSD, DoctorId = appointment.DoctorIdSD, EndTime = appointment.FinishSD, Id = appointment.IdSD, Label = appointment.StatusSD, Notes = appointment.NotesSD, PatientName = !appointment.StillNotVisitedSD ? ScheduleM.Patients.Where(p => p.Id == me.scheduleperson_st. Where(sp => sp.IdSP == appointment.PatientIdSD).FirstOrDefault().ExistedIdSP).FirstOrDefault().Name : me.newperson.Where(n => n.IdNP == me.scheduleperson_st.Where(sp => sp.IdSP == appointment.PatientIdSD). FirstOrDefault().NewPersonIdSP).FirstOrDefault().PatientNameNP, StartTime = appointment.StartSD, StoreInDB = true, PatientTajNumber = !appointment.StillNotVisitedSD ? ScheduleM.Patients.Where(p => p.Id == me.scheduleperson_st. Where(sp => sp.IdSP == appointment.PatientIdSD).FirstOrDefault().ExistedIdSP).FirstOrDefault().TajNumber : me.newperson.Where(n => n.IdNP == me.scheduleperson_st.Where(sp => sp.IdSP == appointment.PatientIdSD). FirstOrDefault().NewPersonIdSP).FirstOrDefault().TAJNumberNP }; tempApp.Add(app); } } } workingConn = true; } catch (Exception ex) { Log.WriteException(ex); workingConn = false; } }
private async void CreateDoWork(object sender, DoWorkEventArgs e) { ScheduleM.Appointment appointment = ScheduleM.Appointments.Where(s => !s.StoreInDB).Single(); try { using (me = new MedicalModel(ConfigurationManager.Connect())) { await me.Database.Connection.OpenAsync(); newperson np = new newperson(); int belong; if (appointment.StillNotVisited) { np.PatientNameNP = appointment.PatientName; np.TAJNumberNP = appointment.PatientTajNumber; me.newperson.Add(np); await me.SaveChangesAsync(); belong = np.IdNP; } else { belong = ScheduleM.Patients.Single(p => p.TajNumber == appointment.PatientTajNumber).Id; } scheduleperson_st spst; if (appointment.StillNotVisited) { spst = new scheduleperson_st() { ExistedIdSP = null, NewPersonIdSP = belong }; me.scheduleperson_st.Add(spst); } else if (!me.scheduleperson_st.Any(sc => sc.ExistedIdSP == belong)) { spst = new scheduleperson_st() { ExistedIdSP = belong, NewPersonIdSP = null }; me.scheduleperson_st.Add(spst); } else { spst = me.scheduleperson_st.Single(sc => sc.ExistedIdSP == belong); } await me.SaveChangesAsync(); scheduledata sd = new scheduledata() { StillNotVisitedSD = appointment.StillNotVisited, StartSD = appointment.StartTime, FinishSD = appointment.EndTime, PatientIdSD = spst.IdSP, DoctorIdSD = appointment.DoctorId, NotesSD = appointment.Notes, StatusSD = appointment.Label }; me.scheduledata.Add(sd); await me.SaveChangesAsync(); NewId = sd.IdSD; } workingConn = true; } catch (Exception ex) { Log.WriteException(ex); workingConn = false; } }