Changeset 8e74e2f for FarmatikoServices/Services
- Timestamp:
- 11/16/20 03:55:10 (4 years ago)
- Branches:
- master
- Children:
- db484c9
- Parents:
- 8b13eb2
- Location:
- FarmatikoServices/Services
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
FarmatikoServices/Services/PHService.cs
r8b13eb2 r8e74e2f 5 5 using System.Collections.Generic; 6 6 using System.Linq; 7 using System.Text;8 7 using System.Threading.Tasks; 9 8 … … 64 63 var phead = _iPHRepo.GetPharmacyHead(pharmacyHead.Email); 65 64 66 if (pharmacyHead.PharmaciesList.Count() == 0)67 pharmacyHead.PharmaciesList = null; 65 /*if (pharmacyHead.PharmaciesList.Count() == 0) 66 pharmacyHead.PharmaciesList = null;*/ 68 67 69 68 70 69 phead.PHMedicineList = _repository.GetPHMedicines(phead.Email); 71 70 72 if (phead.MedicineList != pharmacyHead.MedicineList || phead != pharmacyHead)71 if (phead.MedicineList != pharmacyHead.MedicineList) 73 72 { 74 73 phead.MedicineList = pharmacyHead.MedicineList; … … 83 82 return; 84 83 } 85 foreach (var med in phead.MedicineList)86 {87 med.Id++;88 var PHMObj = phead.PHMedicineList.Select(x => new PharmacyHeadMedicine84 List<PharmacyHeadMedicine> PHMList = new List<PharmacyHeadMedicine>(); 85 if (phead.PHMedicineList == pharmacyHead.PHMedicineList) 86 { 87 foreach (var med in phead.MedicineList) 89 88 { 90 PheadId = x.PheadId, 91 Head = x.Head, 92 MedicineId = x.MedicineId, 93 Medicine = x.Medicine 94 }).Where(x => x.MedicineId == med.Id).Single(); 95 list.Add(PHMObj); 89 //list = phead.PHMedicineList.ToList(); 90 91 var PHMObj = phead.PHMedicineList.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.MedicineId == med.Id).Single(); 99 if (PHMObj == null || PHMObj == default) 100 break; 101 if (PHMObj.MedicineId == med.Id) 102 list.Add(PHMObj); 103 104 } 105 106 phead.PHMedicineList = list; 96 107 } 97 108 98 phead.PHMedicineList = list;99 100 109 await _iPHRepo.UpdatePharmacyHead(phead); 110 } 111 else if (!phead.Equals(pharmacyHead)) 112 { 113 await _iPHRepo.UpdatePharmacyHead(pharmacyHead); 101 114 } 102 115 else throw new Exception("Cannot update pharmacy head since there was no changes."); … … 154 167 if (user.UserRole.ToString().Equals("Admin")) 155 168 { 156 var Admin = new 169 var Admin = new PharmacyHead() 157 170 { 158 171 Id = user.Id, 159 172 Email = user.Email, 160 173 Name = user.Name, 161 Passwd = user.Password, 162 MedicineList = PHMedicines, 174 Password = user.Password, 163 175 PharmaciesList = Phead.PharmaciesList 164 176 }; … … 167 179 } 168 180 169 if (PheadPharms.Count() > 0 )170 Phead. MedicineList = PHMedicineList;181 if (PheadPharms.Count() > 0 || PheadPharms != null) 182 Phead.PharmaciesList = PheadPharms; 171 183 else Phead.PharmaciesList = pharmacies; 172 184 173 if (Phead.PHMedicineList.Count() > 0 )185 if (Phead.PHMedicineList.Count() > 0 || Phead.PHMedicineList != null) 174 186 { 175 187 foreach (var med in Medicines) 176 188 { 177 var PHMObj = Phead.PHMedicineList.Select(x => new PharmacyHeadMedicine 189 190 var PHMObj = Phead.PHMedicineList.Where(x => x.MedicineId == med.Id).SingleOrDefault(); 191 if (PHMObj == null) 178 192 { 179 PheadId = x.PheadId, 180 Head = x.Head, 181 MedicineId = x.MedicineId, 182 Medicine = x.Medicine 183 }).Where(x => x.MedicineId == med.Id).SingleOrDefault(); 184 if (PHMObj == null || PHMObj == default) 185 break; 193 continue; 194 } 195 var phm = Phead.MedicineList; 186 196 if (PHMObj.MedicineId == med.Id) 187 197 { 188 Medicine medicine = new Medicine(med.Name, med.Strength, med.Form, med.WayOfIssuing, med.Manufacturer, med.Price, med.Packaging); 198 var medicine = new Medicine() 199 { 200 Id = med.Id, 201 Name = med.Name, 202 Strength = med.Strength, 203 Form = med.Form, 204 WayOfIssuing = med.WayOfIssuing, 205 Manufacturer = med.Manufacturer, 206 Price = med.Price, 207 Packaging = med.Packaging 208 }; 189 209 PHMedicineList.Add(medicine); 190 210 } -
FarmatikoServices/Services/Service.cs
r8b13eb2 r8e74e2f 128 128 129 129 // Ovaa kontrola ja ima samo admin 130 public User MakeUser(PharmacyHead head) 131 { 132 var users = _repository.GetUsers(); 133 134 User user = new User() 135 { 136 Name = head.Name, 137 Password = head.Password, 138 Email = head.Email, 139 UserRole = User.Role.PharmacyHead 140 }; 141 return user; 142 } 130 143 public async Task AddPharmacyHead(PharmacyHead pharmacyHead) 131 144 { 132 145 if (pharmacyHead != null) 133 146 { 134 /*var Medicines = await _repository.GetMedicinesAsync(); 135 foreach (var med in Medicines) 136 { 137 pharmacyHead.MedicineList.Add(med); 138 }*/ 139 147 var user = MakeUser(pharmacyHead); 148 await _repository.AddUser(user); 140 149 await _repository.AddPharmacyHead(pharmacyHead); 141 150 }
Note:
See TracChangeset
for help on using the changeset viewer.