Changeset 1454207 for FarmatikoServices/Services/ProcessJSONService.cs
- Timestamp:
- 10/01/20 03:17:09 (5 years ago)
- Branches:
- master
- Children:
- 6f203af
- Parents:
- 5d02859
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
FarmatikoServices/Services/ProcessJSONService.cs
r5d02859 r1454207 11 11 using RestSharp; 12 12 using System.Threading.Tasks; 13 using OfficeOpenXml; 14 using System.IO; 13 15 14 16 namespace FarmatikoServices.Services … … 16 18 public class ProcessJSONService : IProcessJSONService 17 19 { 18 private IHealthFacilityRepository _healthFacilityRepository; 19 private IPandemicRepository _pandemicRepository; 20 private IHealthcareWorkerRepository _healthcareWorkerRepository; 21 private IMedicineRepository _medicineRepository; 20 22 21 private readonly ILogger _logger; 23 p ublic ProcessJSONService(IHealthFacilityRepository healthFacilityRepository, IPandemicRepository pandemicRepository,24 IHealthcareWorkerRepository healthcareWorkerRepository, IMedicineRepository medicineRepository, ILogger logger)22 private readonly IService _service; 23 public ProcessJSONService(ILogger logger, IService service) 25 24 { 26 25 _logger = logger; 27 _healthFacilityRepository = healthFacilityRepository; 28 _pandemicRepository = pandemicRepository; 29 _healthcareWorkerRepository = healthcareWorkerRepository; 30 _medicineRepository = medicineRepository; 26 _service = service; 31 27 } 32 28 33 public async Task<HashSet<HealthFacilities>> GetProcessedHealthFacilitiesFromJSON() 29 public async Task<Medicine> ReadPharmaciesFromExcel() 30 { 31 var client = new WebClient(); 32 string Path = client.DownloadString(@"C:\Users\dslez\Desktop\apteki-fzo.xlsx"); 33 using (var package = new ExcelPackage(new FileInfo(Path))) 34 { 35 var Sheet = package.Workbook.Worksheets[1]; 36 for (int i = 2; i < Sheet.Dimension.End.Row; ++i) 37 { 38 Pharmacy pharmacy = new Pharmacy() 39 { 40 Name = Sheet.Cells[i, 2].Value.ToString(), 41 Address = Sheet.Cells[i, 3].Value.ToString(), 42 Location = Sheet.Cells[i, 4].Value.ToString(), 43 WorkAllTime = false 44 }; 45 await _service.AddPharmacy(pharmacy); 46 } 47 } 48 return null; 49 } 50 51 52 public async Task<HealthFacility> GetProcessedHealthFacilitiesFromJSON() 34 53 { 35 54 try 36 55 { 37 HashSet<HealthFacilities> hashSet = new HashSet<HealthFacilities>();38 56 var client = new WebClient(); 39 57 var json = client.DownloadString(@"C:\Users\dslez\Desktop\ustanovi.json"); … … 51 69 var Phone = obj[11]; 52 70 var Type = obj[5]; 53 HealthFacilities healthFacility = new HealthFacilities(Name, Municipality, Address, Type, Email, Phone); 54 /*healthFacility.Name = Name; 55 healthFacility.Municipality = Municipality; 56 healthFacility.Address = Address; 57 healthFacility.Email = Email; 58 healthFacility.Phone = Phone; 59 healthFacility.Type = Type;*/ 60 //hashSet.Add(healthFacility); 61 await Task.Run(() => _healthFacilityRepository.Add(healthFacility)); 71 HealthFacility healthFacility = new HealthFacility(Name, Municipality, Address, Type, Email, Phone); 72 await Task.Run(() => _service.AddFacility(healthFacility)); 62 73 63 74 } … … 72 83 } 73 84 74 public async Task< HashSet<Pandemic>> GetProcessedPandemicsFromJSONApi()85 public async Task<Pandemic> GetProcessedPandemicsFromJSONApi() 75 86 { 76 87 try … … 97 108 98 109 Pandemic pandemic = new Pandemic(Name, TotalMk, ActiveMk, TotalDeathsMK, NewMK, TotalConfirmed, TotalDeaths, ActiveGlobal); 99 /*pandemic.TotalGlobal = TotalConfirmed; 100 pandemic.ActiveGlobal = TotalConfirmed - (TotalRecovered + TotalDeaths); 101 pandemic.DeathsGlobal = TotalDeaths; 102 pandemic.TotalMK = TotalMk; 103 pandemic.ActiveMK = TotalMk - (TotalRecoveredMK + TotalDeathsMK); 104 pandemic.DeathsMK = TotalDeathsMK; 105 pandemic.NewMK = NewMK; 106 pandemic.Name = "Coronavirus";*/ 107 await Task.Run(() => _pandemicRepository.Add(pandemic)); 110 await Task.Run(() => _service.AddPandemic(pandemic)); 108 111 } 109 112 catch (Exception e) … … 114 117 } 115 118 116 public async Task<H ashSet<HealthcareWorkers>> GetProcessedHealthcareWorkersFromJSON()119 public async Task<HealthcareWorker> GetProcessedHealthcareWorkersFromJSON() 117 120 { 118 121 try … … 131 134 var FacilityName = obj[1]; 132 135 var Title = obj[3]; 133 HealthFacilit ies facility = _healthFacilityRepository.GetByName(FacilityName);134 HealthFacilit ies Facility = new HealthFacilities(facility.Name, facility.Municipality, facility.Address,136 HealthFacility facility = await _service.GetFacilityJSON(FacilityName); 137 HealthFacility Facility = new HealthFacility(facility.Name, facility.Municipality, facility.Address, 135 138 facility.Type, facility.Email, facility.Phone); 136 HealthcareWorker s healthcareWorker = new HealthcareWorkers(Name, Branch, Facility, Title);139 HealthcareWorker healthcareWorker = new HealthcareWorker(Name, Branch, Facility, Title); 137 140 /*Facility.Name = obj[1]; 138 141 Facility.Municipality = "WorkerFacilityMunicipality"; … … 142 145 healthcareWorker.Facility = Facility; 143 146 healthcareWorker.Title = Title;*/ 144 await Task.Run(() => _ healthcareWorkerRepository.Add(healthcareWorker));147 await Task.Run(() => _service.AddWorker(healthcareWorker)); 145 148 } 146 149 } … … 152 155 } 153 156 154 public async Task< HashSet<Medicine>> GetProcessedMedicinesFromJSON()157 public async Task<Medicine> GetProcessedMedicinesFromJSON() 155 158 { 156 159 try … … 180 183 medicine.Price = Price; 181 184 medicine.Packaging = Packaging;*/ 182 await Task.Run(() => _ medicineRepository.Add(medicine));185 await Task.Run(() => _service.AddMedicines(medicine)); 183 186 } 184 187 }
Note:
See TracChangeset
for help on using the changeset viewer.