Changeset f554983 for FarmatikoServices/Services
- Timestamp:
- 02/14/21 17:54:35 (4 years ago)
- Branches:
- master
- Children:
- 472dd7e
- Parents:
- 6e6f04b
- Location:
- FarmatikoServices/Services
- Files:
-
- 4 added
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
FarmatikoServices/Services/PHService.cs
r6e6f04b rf554983 83 83 PHMedicines.Add(medicine); 84 84 } 85 86 if (!pharmacyHead.Medicines.Equals(PHMedicines)) 87 { 88 /* 89 * USELESS 90 * if (pharmacyHead.Medicines.Count() == 0) 85 foreach(var phMed in PHMedicines) 86 { 87 if (!pharmacyHead.Medicines.Contains(phMed)) 91 88 { 92 phead.Medicines = null; 93 int PHMId = phead.Medicines.Select(x => x.Id).Single(); 94 int phId = phead.Medicines.Select(x => x.PheadId).Single(); 95 int medId = phead.Medicines.Select(x => x.MedicineId).Single(); 96 _iPHRepo.DeletePHMedicine(PHMId, phId, medId); 97 return; 98 }*/ 99 if (phead.Medicines != null && phead.Medicines.Count() > 0) 100 { 101 foreach (var med in pharmacyHead.Medicines) 102 { 103 Medicine medicine = new Medicine() 89 /* 90 * USELESS 91 * if (pharmacyHead.Medicines.Count() == 0) 92 { 93 phead.Medicines = null; 94 int PHMId = phead.Medicines.Select(x => x.Id).Single(); 95 int phId = phead.Medicines.Select(x => x.PheadId).Single(); 96 int medId = phead.Medicines.Select(x => x.MedicineId).Single(); 97 _iPHRepo.DeletePHMedicine(PHMId, phId, medId); 98 return; 99 }*/ 100 if (phead.Medicines != null && phead.Medicines.Count() > 0) 101 { 102 foreach (var med in pharmacyHead.Medicines) 104 103 { 105 Name = med.Name, 106 Form = med.Form, 107 Manufacturer = med.Manufacturer, 108 Medicines = med.Medicines, 109 Packaging = med.Packaging, 110 Price = med.Price, 111 Strength = med.Strength, 112 WayOfIssuing = med.WayOfIssuing 113 }; 114 115 PharmacyHeadMedicine phm = new PharmacyHeadMedicine() 104 Medicine medicine = new Medicine() 105 { 106 Name = med.Name, 107 Form = med.Form, 108 Manufacturer = med.Manufacturer, 109 Medicines = med.Medicines, 110 Packaging = med.Packaging, 111 Price = med.Price, 112 Strength = med.Strength, 113 WayOfIssuing = med.WayOfIssuing 114 }; 115 116 PharmacyHeadMedicine phm = new PharmacyHeadMedicine() 117 { 118 PheadId = phead.Id, 119 Head = phead, 120 MedicineId = med.Id, 121 Medicine = medicine 122 }; 123 124 bool ifExists = phead.Medicines.Contains(phm); 125 if (!ifExists) 126 list.Add(phm); 127 128 } 129 } 130 else 131 { 132 foreach (var med in pharmacyHead.Medicines) 116 133 { 117 PheadId = phead.Id, 118 Head = phead, 119 MedicineId = med.Id, 120 Medicine = medicine 121 }; 122 123 bool ifExists = phead.Medicines.Contains(phm); 124 if (!ifExists) 125 list.Add(phm); 126 134 PharmacyHead head1 = new PharmacyHead() 135 { 136 Id = pharmacyHead.Id, 137 Name = pharmacyHead.Name, 138 Email = pharmacyHead.Email, 139 Password = pharmacyHead.Password 140 }; 141 PharmacyHeadMedicine phmed = new PharmacyHeadMedicine() 142 { 143 Head = head1, 144 Medicine = med 145 }; 146 list.Add(phmed); 147 } 127 148 } 149 150 151 phead.Medicines = list; 152 153 await _iPHRepo.UpdatePharmacyHead(phead); 154 128 155 } 129 else130 {131 foreach (var med in pharmacyHead.Medicines)132 {133 PharmacyHead head1 = new PharmacyHead()134 {135 Id = pharmacyHead.Id,136 Name = pharmacyHead.Name,137 Email = pharmacyHead.Email,138 Password = pharmacyHead.Password139 };140 PharmacyHeadMedicine phMed = new PharmacyHeadMedicine()141 {142 Head = head1,143 Medicine = med144 };145 list.Add(phMed);146 }147 }148 149 150 phead.Medicines = list;151 152 await _iPHRepo.UpdatePharmacyHead(phead);153 154 156 } 157 155 158 } 156 159 PharmacyHead head = new PharmacyHead() -
FarmatikoServices/Services/ProcessJSONService.cs
r6e6f04b rf554983 13 13 using GemBox.Spreadsheet; 14 14 using System.Text; 15 using FarmatikoData.FarmatikoRepoInterfaces; 15 16 16 17 namespace FarmatikoServices.Services … … 20 21 21 22 private readonly ILogger _logger; 23 private readonly IUpdateDataRepo _repo; 22 24 private readonly IService _service; 23 public ProcessJSONService(ILogger logger, I Service service)25 public ProcessJSONService(ILogger logger, IUpdateDataRepo repo, IService service) 24 26 { 25 27 _logger = logger; 28 _repo = repo; 26 29 _service = service; 27 30 } … … 77 80 bool Success = ReadPharmaciesFromExcel(pathToSave1); 78 81 _logger.LogInformation(Success.ToString() + "1"); 79 /* Success = await ReadPharmaciesFromExcel(pathToSave2); 80 _logger.LogInformation(Success.ToString() + "2");*/82 83 81 84 } 82 85 catch (Exception e) … … 88 91 89 92 //Healthfacilities 90 public asyncvoid GetProcessedHealthFacilitiesFromJSON()93 public void GetProcessedHealthFacilitiesFromJSON() 91 94 { 92 95 try … … 115 118 healthFacility.Email = Convert.ToString(Email); 116 119 healthFacility.Phone = Convert.ToString(Phone); 117 await_service.AddFacility(healthFacility);118 119 } 120 120 _service.AddFacility(healthFacility); 121 122 } 123 121 124 } 122 125 catch (Exception e) … … 126 129 } 127 130 } 128 //Pandemics 129 public async void GetProcessedPandemicsFromJSONApi() 130 { 131 try 132 { 133 var Date = DateTime.UtcNow.ToString("yyyy-MM-dd"); 134 var client = new RestClient($"https://api.covid19tracking.narrativa.com/api/{Date}/country/north_macedonia"); 135 var response = client.Execute(new RestRequest()); 136 string original = response.Content; 137 var jsonResponsePandemic = JObject.Parse(original); 138 var global = JObject.Parse(jsonResponsePandemic.GetValue("total").ToString()); 139 var TotalConfirmed = long.Parse(global.GetValue("today_confirmed").ToString()); 140 var TotalDeaths = long.Parse(global.GetValue("today_deaths").ToString()); 141 var TotalRecovered = long.Parse(global.GetValue("today_new_recovered").ToString()); 142 143 var mk = JObject.Parse(jsonResponsePandemic.GetValue("dates").ToString()); 144 145 var date = JObject.Parse(mk.GetValue(Date).ToString()); 146 var country = JObject.Parse(date.GetValue("countries").ToString()); 147 var mkd = JObject.Parse(country.GetValue("North Macedonia").ToString()); 148 dynamic objP = mkd; 149 var TotalMk = Int32.Parse(objP.GetValue("today_confirmed").ToString()); 150 var TotalDeathsMK = Int32.Parse(objP.GetValue("today_deaths").ToString()); 151 var TotalRecoveredMK = Int32.Parse(objP.GetValue("today_recovered").ToString()); 152 var NewMK = Int32.Parse(objP.GetValue("today_new_confirmed").ToString()); 153 154 var Name = "Coronavirus"; 155 var ActiveMk = TotalMk - (TotalRecoveredMK + TotalDeathsMK); 156 var ActiveGlobal = TotalConfirmed - (TotalRecovered + TotalDeaths); 157 158 Pandemic pandemic = new Pandemic(Name, TotalMk, ActiveMk, TotalDeathsMK, NewMK, TotalConfirmed, TotalDeaths, ActiveGlobal); 159 await _service.AddPandemic(pandemic); 160 } 161 catch (Exception e) 162 { 163 _logger.LogInformation(e.Message); 164 } 165 } 131 166 132 //Healthcare workers 167 public asyncvoid GetProcessedHealthcareWorkersFromJSON()133 public void GetProcessedHealthcareWorkersFromJSON() 168 134 { 169 135 try … … 183 149 var Title = Convert.ToString(obj[3]); 184 150 185 HealthFacility facility = _ service.GetFacilityJSON(Convert.ToString(FacilityName));151 HealthFacility facility = _repo.GetFacilityJSON(Convert.ToString(FacilityName)); 186 152 187 153 if (facility != null && facility != default) … … 196 162 ); 197 163 HealthcareWorker healthcareWorker = new HealthcareWorker(Name, Branch, Facility, Title); 198 await_service.AddWorker(healthcareWorker);164 _service.AddWorker(healthcareWorker); 199 165 } 200 166 else … … 209 175 ); 210 176 HealthcareWorker healthcareWorker = new HealthcareWorker(Name, Branch, Facility, Title); 211 await_service.AddWorker(healthcareWorker);177 _service.AddWorker(healthcareWorker); 212 178 } 213 179 214 180 215 181 } 182 216 183 } 217 184 catch (Exception e) … … 221 188 } 222 189 //Medicines 223 public asyncvoid GetProcessedMedicinesFromJSON()190 public void GetProcessedMedicinesFromJSON() 224 191 { 225 192 try … … 244 211 Medicine medicine = new Medicine(Convert.ToString(Name), Convert.ToString(Strength), Convert.ToString(Form), Convert.ToString(WayOfIssuing), Convert.ToString(Manufacturer), Price, Convert.ToString(Packaging)); 245 212 246 await_service.AddMedicines(medicine);213 _service.AddMedicines(medicine); 247 214 } 248 215 } -
FarmatikoServices/Services/Service.cs
r6e6f04b rf554983 144 144 var Pharmacies = await _repository.GetPharmacies(); 145 145 List<PharmacyDTO> pharmacies = new List<PharmacyDTO>(); 146 147 foreach (var pharm in Pharmacies)146 147 foreach (var pharm in Pharmacies) 148 148 { 149 149 PharmacyDTO pharmacyDTO = new PharmacyDTO() … … 222 222 List<PharmacyDTO> pharmacies = new List<PharmacyDTO>(); 223 223 var heads = await _phrepo.GetPharmacyHeadInfo(); 224 224 225 225 foreach (var pharm in SearchQuery) 226 226 { … … 232 232 WorkAllTime = pharm.WorkAllTime 233 233 }; 234 235 foreach (var head in heads.ToList())234 235 foreach (var head in heads.ToList()) 236 236 { 237 237 if (head.Pharmacies.Contains(pharm)) … … 241 241 } 242 242 } 243 243 244 244 pharmacies.Add(pharmacyDTO); 245 245 } … … 256 256 //POST (ADD NEW OBJECTS) 257 257 //za json(Sys updateer) 258 public async Task AddFacility(HealthFacility healthFacilities) 259 { 260 if (healthFacilities != null) 261 await _repository.AddFacility(healthFacilities); 258 public async Task AddFacility(HealthFacility healthFacility) 259 { 260 if (healthFacility != null) 261 { 262 var facilities = await _repository.GetFacilities(); 263 if (!facilities.Contains(healthFacility)) 264 { 265 await _repository.AddFacility(healthFacility); 266 } 267 else throw new Exception("The facility already exists."); 268 } 262 269 else throw new Exception("Facility is null"); 263 270 } … … 266 273 { 267 274 if (medicine != null) 268 await _repository.AddMedicines(medicine); 275 { 276 var medicines = await _repository.GetMedicinesAsync(); 277 if (!medicines.Contains(medicine)) 278 await _repository.AddMedicines(medicine); 279 else throw new Exception("Medicine already exists."); 280 } 269 281 else throw new Exception("Medicine is null"); 270 282 } … … 277 289 } 278 290 // Samo PharmacyHead i Admin imaat pristap 279 public void AddPharmacy(Pharmacy pharmacy)291 public async void AddPharmacy(Pharmacy pharmacy) 280 292 { 281 293 if (pharmacy != null) 282 _repository.AddPharmacy(pharmacy); 294 { 295 var pharmacies = await _repository.GetPharmacies(); 296 if (!pharmacies.Contains(pharmacy)) 297 await _repository.AddPharmacy(pharmacy); 298 else throw new Exception("Pharmacy already exists."); 299 } 283 300 else throw new Exception("Pharmacy is null"); 284 301 } 285 302 286 303 // Ovaa kontrola ja ima samo admin 287 304 288 305 public async Task<bool> AddPharmacyHead(PharmacyHeadDto pharmacyHead) 289 306 { … … 324 341 { 325 342 if (worker != null) 326 await _repository.AddWorker(worker); 343 { 344 var workers = await _repository.GetAllWorkers(); 345 if (!workers.Contains(worker)) 346 await _repository.AddWorker(worker); 347 else throw new Exception("Worker already exists."); 348 } 327 349 else throw new Exception("Worker is null"); 328 350 }
Note:
See TracChangeset
for help on using the changeset viewer.