[a55ef91] | 1 | using FarmatikoData.FarmatikoRepoInterfaces;
|
---|
| 2 | using FarmatikoData.Models;
|
---|
| 3 | using System.Collections.Generic;
|
---|
| 4 | using Newtonsoft.Json;
|
---|
| 5 | using Newtonsoft.Json.Linq;
|
---|
| 6 | using System;
|
---|
| 7 | using Microsoft.Extensions.Logging;
|
---|
| 8 | using System.Net;
|
---|
| 9 | using System.Linq;
|
---|
| 10 | using FarmatikoServices.FarmatikoServiceInterfaces;
|
---|
| 11 | using RestSharp;
|
---|
| 12 |
|
---|
| 13 | namespace FarmatikoServices.Services
|
---|
| 14 | {
|
---|
| 15 | public class ProcessJSONService : IProcessJSONService
|
---|
| 16 | {
|
---|
| 17 | private IHealthFacilityRepository _healthFacilityRepository;
|
---|
| 18 | //private readonly ILogger _logger;
|
---|
| 19 | public ProcessJSONService(IHealthFacilityRepository healthFacilityRepository)
|
---|
| 20 | {
|
---|
| 21 | //_logger = logger;
|
---|
| 22 | _healthFacilityRepository = healthFacilityRepository;
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | public List<HealthFacilities> GetProcessedHealthFacilitiesFromJSON()
|
---|
| 26 | {
|
---|
| 27 | try
|
---|
| 28 | {
|
---|
| 29 | var client = new WebClient();
|
---|
| 30 | var json = client.DownloadString(@"C:\Users\dslez\Desktop\ustanovi.json");
|
---|
| 31 |
|
---|
| 32 | var jsonResponse = JObject.Parse(json);
|
---|
| 33 | var records = JArray.Parse(jsonResponse.GetValue("records").ToString());
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 | foreach(var rec in records)
|
---|
| 37 | {
|
---|
| 38 | dynamic obj = JsonConvert.DeserializeObject(rec.ToString());
|
---|
| 39 | var Name = obj[2];
|
---|
| 40 | var Municipality = obj[6];
|
---|
| 41 | var Address = obj[9];
|
---|
| 42 | var Email = obj[10];
|
---|
| 43 | var Phone = obj[11];
|
---|
| 44 | var Type = obj[5];
|
---|
| 45 | HealthFacilities healthFacility = new HealthFacilities();
|
---|
| 46 | healthFacility.Name = Name;
|
---|
| 47 | healthFacility.Municipality = Municipality;
|
---|
| 48 | healthFacility.Address = Address;
|
---|
| 49 | healthFacility.Email = Email;
|
---|
| 50 | healthFacility.Phone = Phone;
|
---|
| 51 | healthFacility.Type = Type;
|
---|
| 52 | var obje = healthFacility;
|
---|
| 53 | _healthFacilityRepository.Add(healthFacility);
|
---|
| 54 |
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 |
|
---|
| 58 |
|
---|
| 59 | /*var client1 = new RestClient("https://api.covid19api.com/summary");
|
---|
| 60 | var response = client1.Execute(new RestRequest());
|
---|
| 61 | string original = response.Content;
|
---|
| 62 | var jsonResponse = JObject.Parse(original);
|
---|
| 63 | var global = JObject.Parse(jsonResponse.GetValue("Global").ToString());
|
---|
| 64 | var total = Int32.Parse(global.GetValue("TotalConfirmed").ToString());
|
---|
| 65 | Pandemic pandemic = new Pandemic();
|
---|
| 66 | pandemic.TotalGlobal = total;*/
|
---|
| 67 |
|
---|
| 68 | }
|
---|
| 69 | catch (Exception e)
|
---|
| 70 | {
|
---|
| 71 | //_logger.LogError(e.Message);
|
---|
| 72 | Console.WriteLine(e.Message);
|
---|
| 73 | throw e;
|
---|
| 74 | return null;
|
---|
| 75 | }
|
---|
| 76 | return null;
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | }
|
---|
| 80 | }
|
---|