Changeset 1db5673 for FarmatikoServices/Services
- Timestamp:
- 11/14/20 12:27:30 (4 years ago)
- Branches:
- master
- Children:
- 68454c6
- Parents:
- ad60966
- Location:
- FarmatikoServices/Services
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
FarmatikoServices/Services/PHService.cs
rad60966 r1db5673 13 13 { 14 14 private readonly IPHRepo _iPHRepo; 15 public PHService(IPHRepo iPHRepo) 15 private readonly IRepository _repository; 16 public PHService(IPHRepo iPHRepo, IRepository repository) 16 17 { 17 18 _iPHRepo = iPHRepo; 19 _repository = repository; 18 20 } 19 21 … … 55 57 56 58 59 57 60 public async Task UpdatePharmacyHead(PharmacyHead pharmacyHead) 58 61 { 59 62 if (pharmacyHead != null) 60 await _iPHRepo.UpdatePharmacyHead(pharmacyHead); 63 { 64 var phead = _iPHRepo.GetPharmacyHead(pharmacyHead.Email); 65 66 if (pharmacyHead.PharmaciesList.Count() == 0) 67 pharmacyHead.PharmaciesList = null; 68 if (pharmacyHead.MedicineList.Count() == 0) 69 pharmacyHead.MedicineList = null; 70 71 phead.PHMedicineList = _repository.GetPHMedicines(phead.Email); 72 73 if (phead.MedicineList != pharmacyHead.MedicineList || phead != pharmacyHead) 74 { 75 phead.MedicineList = pharmacyHead.MedicineList; 76 List<PharmacyHeadMedicine> list = new List<PharmacyHeadMedicine>(); 77 78 foreach (var med in phead.MedicineList) 79 { 80 med.Id++; 81 var PHMObj = phead.PHMedicineList.Select(x => new PharmacyHeadMedicine 82 { 83 PheadId = x.PheadId, 84 Head = x.Head, 85 MedicineId = x.MedicineId, 86 Medicine = x.Medicine 87 }).Where(x => x.MedicineId == med.Id).Single(); 88 list.Add(PHMObj); 89 } 90 91 phead.PHMedicineList = list; 92 93 await _iPHRepo.UpdatePharmacyHead(phead); 94 } 95 else throw new Exception("Cannot update pharmacy head since there was no changes."); 96 } 61 97 else throw new Exception("PharmacyHead has a null value."); 62 98 } … … 93 129 } 94 130 95 public PharmacyHeadGetPharmacyHead(string userName)131 public object GetPharmacyHead(string userName) 96 132 { 97 133 if (userName != null) 98 134 { 99 return _iPHRepo.GetPharmacyHeadByUserName(userName); 100 } 101 return default; 135 var Phead = _iPHRepo.GetPharmacyHeadByUserName(userName); 136 List<PharmacyHeadMedicine> PHMedicines = _iPHRepo.GetPharmacyHeadMedicines(userName); 137 List<Medicine> Medicines = _repository.GetMedicines().ToList(); 138 List<Medicine> PHMedicineList = new List<Medicine>(); 139 140 141 //var meds = PHMedicines.Where(x => x.Id == Phead.Id).ToList(); 142 var pharmacies = _iPHRepo.GetPharmacies(); 143 var PheadPharms = pharmacies.Where(x => x.PheadId == Phead.Id).ToList(); 144 var user = _repository.GetRole(userName); 145 146 147 if (user.UserRole.ToString().Equals("Admin")) 148 { 149 var Admin = new 150 { 151 Id = user.Id, 152 Email = user.Email, 153 Name = user.Name, 154 Passwd = user.Password, 155 MedicineList = PHMedicines, 156 PharmaciesList = Phead.PharmaciesList 157 }; 158 159 return Admin; 160 } 161 162 if (PheadPharms.Count() > 0) 163 Phead.MedicineList = PHMedicineList; 164 else Phead.PharmaciesList = pharmacies; 165 166 if (Phead.PHMedicineList.Count() > 0) 167 { 168 foreach (var med in Medicines) 169 { 170 var PHMObj = Phead.PHMedicineList.Select(x => new PharmacyHeadMedicine 171 { 172 PheadId = x.PheadId, 173 Head = x.Head, 174 MedicineId = x.MedicineId, 175 Medicine = x.Medicine 176 }).Where(x => x.MedicineId == med.Id).SingleOrDefault(); 177 if (PHMObj == null || PHMObj == default) 178 break; 179 if (PHMObj.MedicineId == med.Id) 180 { 181 Medicine medicine = new Medicine(med.Name, med.Strength, med.Form, med.WayOfIssuing, med.Manufacturer, med.Price, med.Packaging); 182 PHMedicineList.Add(medicine); 183 } 184 } 185 Phead.MedicineList = PHMedicineList; 186 } 187 else 188 { 189 Phead.MedicineList = Medicines; 190 } 191 192 PharmacyHead pharHead = new PharmacyHead() 193 { 194 Id = Phead.Id, 195 MedicineList = Phead.MedicineList, 196 PharmaciesList = Phead.PharmaciesList, 197 Email = Phead.Email, 198 Name = Phead.Name, 199 Password = Phead.Password 200 }; 201 return pharHead; 202 } 203 else throw new Exception("Username is null."); 102 204 } 103 205 } -
FarmatikoServices/Services/ProcessJSONService.cs
rad60966 r1db5673 58 58 string url1 = "http://data.gov.mk/dataset/d84c31d9-e749-4b17-9faf-a5b4db3e7a70/resource/ce446f5c-e541-46f6-9e8c-67568059cbc6/download/registar-na-apteki-vnatre-vo-mreza-na-fzo-12.08.2020.xlsx"; 59 59 string url2 = "http://data.gov.mk/dataset/d84c31d9-e749-4b17-9faf-a5b4db3e7a70/resource/a16379b4-ec81-4de7-994d-0ee503d71b55/download/registar-na-apteki-nadvor-od-mreza-na-fzo-12.08.2020.xlsx"; 60 int count = 0;61 60 Uri uri1 = new Uri(url1); 62 61 Uri uri2 = new Uri(url2); -
FarmatikoServices/Services/Service.cs
rad60966 r1db5673 44 44 public async Task<IEnumerable<Medicine>> GetMedicines() 45 45 { 46 var Medicines = await _repository.GetMedicines ();46 var Medicines = await _repository.GetMedicinesAsync(); 47 47 return Medicines; 48 48 } … … 126 126 else throw new Exception("Pharmacy is null"); 127 127 } 128 128 129 // Ovaa kontrola ja ima samo admin 129 130 public async Task AddPharmacyHead(PharmacyHead pharmacyHead) … … 131 132 if (pharmacyHead != null) 132 133 { 133 var Medicines = await _repository.GetMedicines ();134 var Medicines = await _repository.GetMedicinesAsync(); 134 135 foreach (var med in Medicines) 135 136 { 136 MedicineList medicine = new MedicineList() 137 { 138 Medicine = med, 139 HasMedicine = false 140 }; 141 pharmacyHead.MedicineLists.Add(medicine); 137 pharmacyHead.MedicineList.Add(med); 142 138 } 139 143 140 await _repository.AddPharmacyHead(pharmacyHead); 144 141 } 145 throw new Exception("PharmacyHead is null");142 else throw new Exception("PharmacyHead is null"); 146 143 } 147 144 //za json(Sys updater)
Note:
See TracChangeset
for help on using the changeset viewer.