public static void InitData() { using (ClinicModelContainer container = new ClinicModelContainer()) { if (container.Doctors.Count() == 0) { container.DoctorTypes.AddRange(InitDoctorTypes()); container.Specials.AddRange(InitSpecials()); container.Categories.AddRange(InitCategories()); container.SaveChanges(); container.Doctors.AddRange(InitDoctors(container.Specials.ToList(), container.DoctorTypes.ToList(), container.Categories.ToList())); container.SaveChanges(); container.SexSet.AddRange(InitSexes()); container.AddressSet.AddRange(InitAddresses()); container.SaveChanges(); container.PatientCards.AddRange(InitPatientCards(container.AddressSet.ToList(), container.SexSet.ToList())); container.SaveChanges(); container.CardPages.AddRange(InitCardPages(container.PatientCards.ToList(), container.Doctors.ToList())); container.SaveChanges(); container.Sites.AddRange(InitSites()); container.SaveChanges(); container.SiteAddresses.AddRange(InitSiteAddresses(container.Sites.ToList(), container.AddressSet.ToList())); container.SaveChanges(); container.Surgeries.AddRange(InitSurgeries()); container.SiteDoctors.AddRange(InitSiteDoctors(container.Sites.ToList(), container.Doctors.ToList())); container.SaveChanges(); } } }
public void UpdateScheduleIfNeeded() { using (ClinicModelContainer container = new ClinicModelContainer()) { var schedules = container.DistrictSchedules.ToList(); var currentMonth = DateTime.Now.Month; if (schedules.Count() == 0 || currentMonth - schedules.Last().ReceiptDate.Month >= 1) { var surgeries = container.Surgeries.ToList(); var sites = container.Sites.ToList(); sites.ForEach(site => { var doctors = site.SiteDoctors; for (int i = DateTime.Now.Day; i < DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month); i++) { for (int k = 9; k <= 15; k++) { var reciepeDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, i, k, 0, 0); var doctor = doctors.First(); var surgey = surgeries[site.SiteId - 1]; schedules.Add(new DistrictSchedule() { SurgeryId = surgey.SurgeryId, Surgery = surgey, DoctorId = doctor.Doctor.DoctorId, Doctor = doctor.Doctor, ReceiptDate = reciepeDate, }); } } }); container.DistrictSchedules.AddRange(schedules); container.SaveChanges(); } } }
public static void SeedData() { using (var context = new ClinicModelContainer()) { var psychologists = context.Psychologists.ToList(); var clients = context.Clients.ToList(); var sessions = context.Sessions.ToList(); context.Sessions.RemoveRange(sessions); context.Clients.RemoveRange(clients); context.Psychologists.RemoveRange(psychologists); context.SaveChanges(); var addedPsychologists = new List <Psychologist>(); var addedClients = new List <Client>(); var addedSessions = new List <Session>(); var psychologistCount = _random.Next(20, 60); for (var i = 0; i < psychologistCount; i++) { var psychologist = new Psychologist { Id = Guid.NewGuid(), Email = GenerateEmail(), Name = GenerateNames(_random.Next(10, 25)) }; var clientsCount = _random.Next(1, 6); for (var j = 0; j < clientsCount; j++) { var sessionsCount = _random.Next(1, 6); var client = new Client { Id = Guid.NewGuid(), Email = GenerateEmail(), Name = GenerateNames(_random.Next(10, 25)), PsychologistId = psychologist.Id }; for (var k = 0; k < sessionsCount; k++) { var coeff = _random.Next(0, 2) % 2 == 0 ? 1 : -1; var diff = _random.Next(1, 25); var session = new Session { Id = Guid.NewGuid(), BookedDate = DateTime.Now.AddDays(coeff * diff).AddHours(coeff * diff), ClientId = client.Id, PsychologistId = psychologist.Id, Type = _random.Next(1, 6) % 2 == 0 ? Type.Audio : Type.Video }; addedSessions.Add(session); } addedClients.Add(client); } addedPsychologists.Add(psychologist); } context.Psychologists.AddRange(addedPsychologists); context.Clients.AddRange(addedClients); context.Sessions.AddRange(addedSessions); context.SaveChanges(); } }
public bool SaveChanges() => _context.SaveChanges() > 0;