コード例 #1
0
        public async void ObtenerPolicies(string url)
        {
            HttpClient            httpClients = new HttpClient();
            List <PoliciesEntity> listado;

            try
            {
                HttpResponseMessage response = httpClients.GetAsync(url).Result;

                if (response.IsSuccessStatusCode)
                {
                    var JsonString = await response.Content.ReadAsStringAsync();

                    DataSet   deserialized      = JsonConvert.DeserializeObject <DataSet>(JsonString);
                    DataTable dataTablePolicies = deserialized.Tables["Policies"];

                    listado = new List <PoliciesEntity>();
                    foreach (DataRow rowPolicies in dataTablePolicies.Rows)
                    {
                        PoliciesDto policiesDto = new PoliciesDto(rowPolicies["id"].ToString(), Double.Parse(rowPolicies["amountInsured"].ToString()), rowPolicies["email"].ToString(), DateTime.Parse(rowPolicies["inceptionDate"].ToString()), Boolean.Parse(rowPolicies["installmentPayment"].ToString()), rowPolicies["clientId"].ToString());
                        listado.Add(MapperApplicationPolicies.PoliciesDtoToPoliciesEntity(policiesDto));
                    }

                    PersistirDatosRepository.PersistirDatosPolicies(listado);
                }
            }
            catch (VuelingExceptions ex)
            {
                throw ex;
            }
        }
コード例 #2
0
        public async void ObtenerClients(string url)
        {
            HttpClient           httpClients = new HttpClient();
            List <ClientsEntity> listado     = new List <ClientsEntity>();

            try
            {
                HttpResponseMessage response = httpClients.GetAsync(url).Result;

                if (response.IsSuccessStatusCode)
                {
                    var JsonString = await response.Content.ReadAsStringAsync();

                    DataSet   deserialized = JsonConvert.DeserializeObject <DataSet>(JsonString);
                    DataTable dataTable    = deserialized.Tables["Clients"];

                    foreach (DataRow row in dataTable.Rows)
                    {
                        ClientsDto clientDto = new ClientsDto(row["id"].ToString(), row["name"].ToString(), row["email"].ToString(), row["role"].ToString());
                        listado.Add(MapperApplicationClients.ClientDtoToClientEntity(clientDto));
                    }

                    PersistirDatosRepository.PersistirDatosClients(listado);
                }
            }
            catch (VuelingExceptions ex)
            {
                throw ex;
            }
        }