Пример #1
0
        public static void Initialize(
            IPatientDbService patientDbService,
            IHttpClientFactory httpClientFactory)
        {
            HttpClient httpClient;

            httpClient = httpClientFactory.CreateClient();

            ICollection <Patient>        patients        = new List <Patient>();
            ICollection <PatientContact> patientContacts = new List <PatientContact>();

            JsonElement patientsElement = JsonDocument
                                          .Parse(GetRandomPatientData(httpClient).Result)
                                          .RootElement.GetProperty("results");

            foreach (JsonElement patientElement in patientsElement.EnumerateArray())
            {
                Patient patient = GetPatientFromJsonElement(patientElement);

                PatientContact patientContact = GetPatientContactFromJsonElement(patientElement, patient);

                patients.Add(patient);
                patientContacts.Add(patientContact);
            }

            patientDbService.AddPatientRange(patients.Cast <Patient>());
            patientDbService.AddPatientContactRange(patientContacts.Cast <PatientContact>());
        }