Changeset 0a694bb for FarmatikoServices/Services/Service.cs
- Timestamp:
- 02/07/21 16:25:56 (4 years ago)
- Branches:
- master
- Children:
- e0cdea2
- Parents:
- ac51326
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.