Changeset 0a694bb for FarmatikoServices
- Timestamp:
- 02/07/21 16:25:56 (4 years ago)
- Branches:
- master
- Children:
- e0cdea2
- Parents:
- ac51326
- Location:
- FarmatikoServices
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
FarmatikoServices/FarmatikoServiceInterfaces/IService.cs
rac51326 r0a694bb 28 28 Task AddFacility(HealthFacility healthFacilities); 29 29 Task AddPharmacy(Pharmacy pharmacy); 30 Task AddPharmacyHead(PharmacyHeadpharmacyHead);30 Task<bool> AddPharmacyHead(PharmacyHeadDto pharmacyHead); 31 31 Task AddMedicines(Medicine medicine); 32 32 Task AddPandemic(Pandemic pandemic); -
FarmatikoServices/Services/PHService.cs
rac51326 r0a694bb 73 73 74 74 75 76 if (!pharmacyHead.Medicines.Equals(PHMedicines)) 77 { 78 //phead.Medicines = pharmacyHead.Medicines; 79 if (pharmacyHead.Medicines.Count() == 0) 75 if (pharmacyHead.Medicines != null || pharmacyHead.Medicines.Count() > 0) 76 if (!pharmacyHead.Medicines.Equals(PHMedicines)) 80 77 { 81 phead.Medicines = null; 82 int PHMId = phead.Medicines.Select(x => x.Id).Single(); 83 int phId = phead.Medicines.Select(x => x.PheadId).Single(); 84 int medId = phead.Medicines.Select(x => x.MedicineId).Single(); 85 _iPHRepo.DeletePHMedicine(PHMId, phId, medId); 86 return; 78 //phead.Medicines = pharmacyHead.Medicines; 79 if (pharmacyHead.Medicines.Count() == 0) 80 { 81 phead.Medicines = null; 82 int PHMId = phead.Medicines.Select(x => x.Id).Single(); 83 int phId = phead.Medicines.Select(x => x.PheadId).Single(); 84 int medId = phead.Medicines.Select(x => x.MedicineId).Single(); 85 _iPHRepo.DeletePHMedicine(PHMId, phId, medId); 86 return; 87 } 88 foreach (var med in pharmacyHead.Medicines) 89 { 90 91 PharmacyHeadMedicine PHMObj = phead.Medicines.Select(x => new PharmacyHeadMedicine 92 { 93 Id = x.Id, 94 PheadId = x.PheadId, 95 Head = x.Head, 96 MedicineId = x.MedicineId, 97 Medicine = x.Medicine 98 }).Where(x => !x.Medicine.Equals(med)).Single(); 99 if (PHMObj == null || PHMObj == default) 100 break; 101 if (PHMObj.MedicineId == med.Id) 102 list.Add(PHMObj); 103 104 } 105 106 phead.Medicines = list; 107 108 await _iPHRepo.UpdatePharmacyHead(phead); 109 87 110 } 88 foreach (var med in pharmacyHead.Medicines) 89 { 90 91 PharmacyHeadMedicine PHMObj = phead.Medicines.Select(x => new PharmacyHeadMedicine 92 { 93 Id = x.Id, 94 PheadId = x.PheadId, 95 Head = x.Head, 96 MedicineId = x.MedicineId, 97 Medicine = x.Medicine 98 }).Where(x => !x.Medicine.Equals(med)).Single(); 99 if (PHMObj == null || PHMObj == default) 100 break; 101 if (PHMObj.MedicineId == med.Id) 102 list.Add(PHMObj); 103 104 } 105 106 phead.Medicines = list; 107 108 await _iPHRepo.UpdatePharmacyHead(phead); 111 112 if (pharmacyHead.Pharmacies != null || pharmacyHead.Pharmacies.Count() > 0) 113 { 114 phead.Pharmacies = pharmacyHead.Pharmacies; 109 115 } 110 116 PharmacyHead head = new PharmacyHead() … … 112 118 Name = pharmacyHead.Name, 113 119 Email = pharmacyHead.Email, 114 Password = pharmacyHead.Password, 115 Pharmacies = pharmacyHead.Pharmacies, 116 Medicines = list 120 Password = pharmacyHead.Password 117 121 }; 118 122 if (!phead.Equals(head)) -
FarmatikoServices/Services/Service.cs
rac51326 r0a694bb 48 48 List<MedicineDTO> list = new List<MedicineDTO>(); 49 49 var listPHMedicines = await _repository.GetAllPHMedicines(); 50 foreach(var med in Medicines) 51 { 52 var heads = listPHMedicines.Where(x => x.MedicineId == med.Id).Select(x => x.Head).ToList(); 53 List<string> headNames = new List<string>(); 50 List<string> headNames = new List<string>(); 51 List<PharmacyHead> heads = new List<PharmacyHead>(); 52 foreach (var med in Medicines) 53 { 54 var meds = listPHMedicines.Where(x => x.MedicineId == med.Id).ToList(); 55 if (meds != null) 56 { 57 heads = meds.Select(x => x.Head).ToList(); 58 } 54 59 headNames = heads.Select(x => x.Name).ToList(); 55 60 MedicineDTO medicine = new MedicineDTO() … … 89 94 Location = pharm.Location, 90 95 Address = pharm.Address, 91 WorkAllTime = pharm.WorkAllTime, 92 HeadName = pharm.PharmacyHead.Name?? "" 96 WorkAllTime = pharm.WorkAllTime 93 97 }; 98 if (pharm.PharmacyHead != null) 99 { 100 pharmacyDTO.HeadName = pharm.PharmacyHead.Name; 101 } 102 94 103 pharmacies.Add(pharmacyDTO); 95 104 } … … 165 174 166 175 // Ovaa kontrola ja ima samo admin 167 public User MakeUser(PharmacyHead head) 168 { 169 170 176 public async Task<User> MakeUser(PharmacyHead head) 177 { 171 178 User user = new User() 172 179 { … … 176 183 UserRole = User.Role.PharmacyHead 177 184 }; 185 bool Success = await _repository.AddUser(user); 186 if (!Success) 187 return null; 178 188 return user; 179 189 } 180 public async Task AddPharmacyHead(PharmacyHeadpharmacyHead)190 public async Task<bool> AddPharmacyHead(PharmacyHeadDto pharmacyHead) 181 191 { 182 192 if (pharmacyHead != null) 183 193 { 184 var user = MakeUser(pharmacyHead); 185 await _repository.AddUser(user); 186 await _repository.AddPharmacyHead(pharmacyHead); 194 var phead = new PharmacyHead() 195 { 196 Name = pharmacyHead.Name, 197 Email = pharmacyHead.Email, 198 Password = pharmacyHead.Password 199 }; 200 var user = await MakeUser(phead); 201 if (user is null) 202 { 203 return false; 204 } 205 var users = _repository.GetUsers(); 206 var thisUser = users.Where(usr => usr.Value.Email.Equals(user.Email)).Select(x => x.Value).FirstOrDefault(); 207 User user1 = new User() 208 { 209 Name = thisUser.Name, 210 Password = thisUser.Password, 211 Email = thisUser.Email, 212 UserRole = thisUser.UserRole 213 }; 214 phead.User = user1; 215 await _repository.AddPharmacyHead(phead); 216 return true; 187 217 } 188 else throw new Exception("PharmacyHead is null");218 else throw new Exception("PharmacyHeadDto is null"); 189 219 } 190 220 //za json(Sys updater)
Note:
See TracChangeset
for help on using the changeset viewer.