Changeset 1454207 for FarmatikoServices
- Timestamp:
- 10/01/20 03:17:09 (4 years ago)
- Branches:
- master
- Children:
- 6f203af
- Parents:
- 5d02859
- Location:
- FarmatikoServices
- Files:
-
- 4 added
- 14 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
FarmatikoServices/FarmatikoServiceInterfaces/IProcessJSONService.cs
r5d02859 r1454207 9 9 public interface IProcessJSONService 10 10 { 11 Task<HashSet<HealthFacilities>> GetProcessedHealthFacilitiesFromJSON(); 12 Task<HashSet<Pandemic>> GetProcessedPandemicsFromJSONApi(); 13 Task<HashSet<HealthcareWorkers>> GetProcessedHealthcareWorkersFromJSON(); 14 Task<HashSet<Medicine>> GetProcessedMedicinesFromJSON(); 11 Task<HealthFacility> GetProcessedHealthFacilitiesFromJSON(); 12 Task<Pandemic> GetProcessedPandemicsFromJSONApi(); 13 Task<HealthcareWorker> GetProcessedHealthcareWorkersFromJSON(); 14 Task<Medicine> GetProcessedMedicinesFromJSON(); 15 Task<Medicine> ReadPharmaciesFromExcel(); 15 16 } 16 17 } -
FarmatikoServices/FarmatikoServiceInterfaces/IService.cs
r5d02859 r1454207 8 8 { 9 9 //GET 10 Task<IQueryable<HealthcareWorkers>> GetAllWorkers(); 11 Task<IQueryable<HealthcareWorkers>> SearchWorkers(string query); 12 Task<HealthcareWorkers> GetWorker(int id); 13 Task<IQueryable<HealthFacilities>> GetFacilities(); 14 Task<IQueryable<HealthFacilities>> SearchFacilities(string query); 15 Task<HealthFacilities> GetFacility(int id); 10 Task<IQueryable<HealthcareWorker>> GetAllWorkers(); 11 Task<IQueryable<HealthcareWorker>> SearchWorkers(string query); 12 Task<HealthcareWorker> GetWorker(int id); 13 Task<IQueryable<HealthFacility>> GetFacilities(); 14 Task<IQueryable<HealthFacility>> SearchFacilities(string query); 15 Task<HealthFacility> GetFacility(int id); 16 Task<HealthFacility> GetFacilityJSON(string healthFacility); 16 17 Task<Medicine> GetMedicine(int id); 17 18 Task<IQueryable<Medicine>> SearchMedicines(string query); … … 22 23 Task<Pharmacy> GetPharmacy(int id); 23 24 //POST 24 Task AddWorker(HealthcareWorker sworker);25 Task AddFacility(HealthFacilit ieshealthFacilities);25 Task AddWorker(HealthcareWorker worker); 26 Task AddFacility(HealthFacility healthFacilities); 26 27 Task AddPharmacy(Pharmacy pharmacy); 27 28 Task AddPharmacyHead(PharmacyHead pharmacyHead); 28 29 Task AddMedicines(Medicine medicine); 29 30 Task AddPandemic(Pandemic pandemic); 31 Task UpdateFacility(HealthFacility healthFacilities); 32 Task RemoveMedicine(Medicine medicine); 33 Task RemovePharmacyHead(PharmacyHead pharmacyHead); 34 Task UpdatePandemic(Pandemic pandemic); 35 Task RemovePharmacy(Pharmacy pharmacy); 36 Task UpdateWorker(HealthcareWorker worker); 37 Task UpdatePharmacy(Pharmacy pharmacy); 30 38 } 31 39 } -
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 } -
FarmatikoServices/Services/Service.cs
r5d02859 r1454207 17 17 18 18 //GET 19 public async Task<IQueryable<HealthcareWorker s>> GetAllWorkers()19 public async Task<IQueryable<HealthcareWorker>> GetAllWorkers() 20 20 { 21 21 var Workers = await _repository.GetAllWorkers(); … … 23 23 } 24 24 25 public async Task<IQueryable<HealthFacilit ies>> GetFacilities()25 public async Task<IQueryable<HealthFacility>> GetFacilities() 26 26 { 27 27 var Facilities = await _repository.GetFacilities(); … … 29 29 } 30 30 31 public async Task<HealthFacilit ies> GetFacility(int id)31 public async Task<HealthFacility> GetFacility(int id) 32 32 { 33 33 var Facility = await _repository.GetFacility(id); … … 65 65 } 66 66 67 public async Task<HealthcareWorker s> GetWorker(int id)67 public async Task<HealthcareWorker> GetWorker(int id) 68 68 { 69 69 var Worker = await _repository.GetWorker(id); … … 71 71 } 72 72 73 public async Task<IQueryable<HealthFacilit ies>> SearchFacilities(string query)73 public async Task<IQueryable<HealthFacility>> SearchFacilities(string query) 74 74 { 75 75 var SearchQuery = await _repository.SearchFacilities(query); … … 89 89 } 90 90 91 public async Task<IQueryable<HealthcareWorker s>> SearchWorkers(string query)91 public async Task<IQueryable<HealthcareWorker>> SearchWorkers(string query) 92 92 { 93 93 var SearchQuery = await _repository.SearchWorkers(query); … … 97 97 98 98 //POST (ADD NEW OBJECTS) 99 public Task AddFacility(HealthFacilities healthFacilities) 99 //za json(Sys updateer) 100 public async Task AddFacility(HealthFacility healthFacilities) 100 101 { 101 102 if (healthFacilities != null) 102 _repository.AddFacility(healthFacilities);103 await _repository.AddFacility(healthFacilities); 103 104 throw new Exception("Facility is null"); 104 105 } 105 106 public Task AddMedicines(Medicine medicine)106 //za json(Sys updateer) 107 public async Task AddMedicines(Medicine medicine) 107 108 { 108 109 if (medicine != null) 109 _repository.AddMedicines(medicine);110 await _repository.AddMedicines(medicine); 110 111 throw new Exception("Medicine is null"); 111 112 } 112 113 public Task AddPandemic(Pandemic pandemic)113 //za json(Sys updateer) 114 public async Task AddPandemic(Pandemic pandemic) 114 115 { 115 116 if (pandemic != null) 116 _repository.AddPandemic(pandemic);117 await _repository.AddPandemic(pandemic); 117 118 throw new Exception("Pandemic is null"); 118 119 } 119 120 public Task AddPharmacy(Pharmacy pharmacy)120 // Samo PharmacyHead i Admin imaat pristap 121 public async Task AddPharmacy(Pharmacy pharmacy) 121 122 { 122 123 if (pharmacy != null) 123 _repository.AddPharmacy(pharmacy);124 await _repository.AddPharmacy(pharmacy); 124 125 throw new Exception("Pharmacy is null"); 125 126 } 126 127 public Task AddPharmacyHead(PharmacyHead pharmacyHead)127 // Ovaa kontrola ja ima samo admin 128 public async Task AddPharmacyHead(PharmacyHead pharmacyHead) 128 129 { 129 130 if (pharmacyHead != null) 130 _repository.AddPharmacyHead(pharmacyHead); 131 { 132 var Medicines = await _repository.GetMedicines(); 133 foreach (var med in Medicines) 134 { 135 MedicineList medicine = new MedicineList() 136 { 137 Medicine = med, 138 HasMedicine = false 139 }; 140 pharmacyHead.MedicineLists.Add(medicine); 141 } 142 await _repository.AddPharmacyHead(pharmacyHead); 143 } 131 144 throw new Exception("PharmacyHead is null"); 132 145 } 133 134 public Task AddWorker(HealthcareWorkersworker)146 //za json(Sys updateer) 147 public async Task AddWorker(HealthcareWorker worker) 135 148 { 136 149 if (worker != null) 137 _repository.AddWorker(worker);150 await _repository.AddWorker(worker); 138 151 throw new Exception("Worker is null"); 152 } 153 154 //za json(Sys updateer) 155 public async Task UpdateFacility(HealthFacility healthFacilities) 156 { 157 if (healthFacilities != null) 158 await _repository.UpdateFacility(healthFacilities); 159 throw new Exception("Facility is null"); 160 } 161 //PharmacyHead 162 public async Task RemoveMedicine(Medicine medicine) 163 { 164 if (medicine != null) 165 await _repository.RemoveMedicine(medicine); 166 throw new Exception("Medicine is null"); 167 } 168 //PharmacyHead 169 public async Task UpdateMedicine(Medicine medicine) 170 { 171 if (medicine != null) 172 await _repository.UpdateMedicine(medicine); 173 throw new Exception("Medicine is null"); 174 } 175 //za json(Sys updateer) 176 public async Task UpdatePandemic(Pandemic pandemic) 177 { 178 if (pandemic != null) 179 await _repository.UpdatePandemic(pandemic); 180 throw new Exception("Pandemic is null"); 181 } 182 //PharmacyHead 183 public async Task RemovePharmacy(Pharmacy pharmacy) 184 { 185 if (pharmacy != null) 186 await _repository.RemovePharmacy(pharmacy); 187 throw new Exception("Pharmacy is null"); 188 } 189 //PharamcyHead 190 public async Task UpdatePharmacy(Pharmacy pharmacy) 191 { 192 if (pharmacy != null) 193 await _repository.UpadatePharmacy(pharmacy); 194 throw new Exception("Pharmacy is null"); 195 } 196 //za json(Sys updateer) 197 public async Task UpdateWorker(HealthcareWorker worker) 198 { 199 if (worker != null) 200 await _repository.UpdateWorker(worker); 201 throw new Exception("Worker is null"); 202 } 203 204 public async Task RemovePharmacyHead(PharmacyHead pharmacyHead) 205 { 206 if (pharmacyHead != null) 207 { 208 pharmacyHead.DeletedOn = DateTime.UtcNow; 209 await _repository.RemovePharmacyHead(pharmacyHead); 210 } 211 else throw new Exception("PharmacyHead is null."); 212 } 213 214 public async Task<HealthFacility> GetFacilityJSON(string healthFacility) 215 { 216 if (healthFacility != null) 217 return await _repository.GetFacilityJSON(healthFacility); 218 return null; 139 219 } 140 220
Note:
See TracChangeset
for help on using the changeset viewer.