public static void Import() { string clientId = AppSettings.ClientId; string clientSecret = AppSettings.ClientSecret; string locale = AppSettings.Locale; var client = new DpApi(clientId, clientSecret, (Locale)locale); var facilities = client.GetFacilities(); foreach (var facility in facilities) { Console.WriteLine($"IMPORTING FACILITY: {facility.Name}\n"); var foreignFacility = CreateOrUpdateFacility(facility); var dpDoctors = client.GetDoctors(facility.Id, true); foreach (var doctor in dpDoctors) { Console.WriteLine($"-> {doctor.Name} {doctor.Surname} (ID:{doctor.Id})"); var foreignDoctor = CreateOrUpdateDoctor(doctor); var specializations = client.GetDoctor(facility.Id, doctor.Id).Specializations; Console.WriteLine("---> IMPORTING SPECIZALIZATIONS"); ImportSpecializations(specializations, foreignDoctor); var addresses = client.GetAddresses(facility.Id, doctor.Id); Console.WriteLine("---> IMPORTING ADDRESSES"); ImportAddresses(foreignFacility, foreignDoctor, addresses); var doctorServices = client.GetDoctorServices(facility.Id, doctor.Id); Console.WriteLine("---> IMPORTING DOCTOR SERVICES"); ImportDoctorServices(foreignDoctor, doctorServices); ClearLeftOverDoctorServices(foreignDoctor, doctorServices); Console.WriteLine(""); } } db.SaveChanges(); }
static void Main(string[] args) { string clientId = AppSettings.ClientId; string clientSecret = AppSettings.ClientSecret; string locale = AppSettings.Locale; bool shouldExit = false; HospitalContext myDb = new HospitalContext(); var facilityRepo = new ForeignFacilityRepository(myDb); var doctorRepo = new ForeignDoctorRepository(myDb); var addressRepo = new ForeignAddressRepository(myDb); var specializationRepo = new ForeignSpecializationRepository(myDb); var doctorServiceRepo = new ForeignDoctorServiceRepository(myDb); var client = new DpApi(clientId, clientSecret, (Locale)locale); var facilities = client.GetFacilities(); foreach (var facility in facilities) { Console.WriteLine($"IMPORTING FACILITY: {facility.Name}\n"); var foreignFacility = new ForeignFacility() { Id = facility.Id, Name = facility.Name }; facilityRepo.InsertOrUpdate(foreignFacility); var dpDoctors = new List <DPDoctor>(client.GetDoctors(facility.Id, true)); Console.WriteLine("DOCTORS:"); foreach (var dpDoctor in dpDoctors) { Console.WriteLine($"-> {dpDoctor.Name} {dpDoctor.Surname} (ID:{dpDoctor.Id})"); var foreignDoctor = new ForeignDoctor() { Id = dpDoctor.Id, Name = dpDoctor.Name, Surname = dpDoctor.Surname }; var tempDoctor = client.GetDoctor(facility.Id, dpDoctor.Id); Console.WriteLine("---> IMPORTING SPECIZALIZATIONS"); ImportSpecializations(specializationRepo, tempDoctor, foreignDoctor); var addresses = client.GetAddresses(facility.Id, dpDoctor.Id); Console.WriteLine("---> IMPORTING ADDRESSES"); ImportAddresses(addressRepo, dpDoctor, foreignFacility, foreignDoctor, addresses); var doctorServices = client.GetDoctorServices(facility.Id, dpDoctor.Id); Console.WriteLine("---> IMPORTING DOCTOR SERVICES"); ImportDoctorServices(doctorServiceRepo, dpDoctor, foreignDoctor, doctorServices); doctorRepo.InsertOrUpdate(foreignDoctor); Console.WriteLine(); } } doctorRepo.Save(); Console.WriteLine("DONE"); if (shouldExit == false) { Console.ReadLine(); } }