Changeset db484c9 for FarmatikoServices/Services
- Timestamp:
- 01/26/21 10:33:09 (4 years ago)
- Branches:
- master
- Children:
- 7d80751
- Parents:
- 8e74e2f
- Location:
- FarmatikoServices/Services
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
FarmatikoServices/Services/PHService.cs
r8e74e2f rdb484c9 1 using FarmatikoData.FarmatikoRepoInterfaces; 1 using FarmatikoData.DTOs; 2 using FarmatikoData.FarmatikoRepoInterfaces; 2 3 using FarmatikoData.Models; 3 4 using FarmatikoServices.FarmatikoServiceInterfaces; … … 57 58 58 59 59 public async Task UpdatePharmacyHead(PharmacyHead pharmacyHead)60 public async Task UpdatePharmacyHead(PharmacyHeadDto pharmacyHead) 60 61 { 61 62 if (pharmacyHead != null) … … 63 64 var phead = _iPHRepo.GetPharmacyHead(pharmacyHead.Email); 64 65 65 /*if (pharmacyHead.PharmaciesList.Count() == 0) 66 pharmacyHead.PharmaciesList = null;*/ 67 68 69 phead.PHMedicineList = _repository.GetPHMedicines(phead.Email); 70 71 if (phead.MedicineList != pharmacyHead.MedicineList) 72 { 73 phead.MedicineList = pharmacyHead.MedicineList; 74 List<PharmacyHeadMedicine> list = new List<PharmacyHeadMedicine>(); 75 if (pharmacyHead.MedicineList.Count() == 0) 76 { 77 phead.MedicineList = null; 78 int PHMId = phead.PHMedicineList.Select(x => x.Id).Single(); 79 int phId = phead.PHMedicineList.Select(x => x.PheadId).Single(); 80 int medId = phead.PHMedicineList.Select(x => x.MedicineId).Single(); 66 phead.Medicines = _repository.GetPHMedicines(phead.Email).ToList(); 67 68 List<Medicine> medicines = _repository.GetMedicines().ToList(); 69 70 List<Medicine> PHMedicines = medicines.Where(x => x.Id == phead.Medicines.Select(x => x.MedicineId).Single()).ToList(); 71 72 List<PharmacyHeadMedicine> list = new List<PharmacyHeadMedicine>(); 73 74 75 76 if (!pharmacyHead.Medicines.Equals(PHMedicines)) 77 { 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(); 81 85 _iPHRepo.DeletePHMedicine(PHMId, phId, medId); 82 86 return; 83 87 } 84 List<PharmacyHeadMedicine> PHMList = new List<PharmacyHeadMedicine>();85 if (phead.PHMedicineList == pharmacyHead.PHMedicineList)86 { 87 foreach (var med in phead.MedicineList)88 foreach (var med in pharmacyHead.Medicines) 89 { 90 91 PharmacyHeadMedicine PHMObj = phead.Medicines.Select(x => new PharmacyHeadMedicine 88 92 { 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; 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 107 104 } 108 105 106 phead.Medicines = list; 107 109 108 await _iPHRepo.UpdatePharmacyHead(phead); 110 109 } 111 else if (!phead.Equals(pharmacyHead)) 112 { 113 await _iPHRepo.UpdatePharmacyHead(pharmacyHead); 110 PharmacyHead head = new PharmacyHead() 111 { 112 Name = pharmacyHead.Name, 113 Email = pharmacyHead.Email, 114 Password = pharmacyHead.Password, 115 Pharmacies = pharmacyHead.Pharmacies, 116 Medicines = list 117 }; 118 if (!phead.Equals(head)) 119 { 120 await _iPHRepo.UpdatePharmacyHead(head); 114 121 } 115 122 else throw new Exception("Cannot update pharmacy head since there was no changes."); … … 117 124 else throw new Exception("PharmacyHead has a null value."); 118 125 } 119 public async Task<bool> Add(PharmacyHead pharmacyHead)126 public async Task<bool> Add(PharmacyHeadDto pharmacyHead) 120 127 { 121 128 if (pharmacyHead != null) 122 129 { 123 await _iPHRepo.Add(pharmacyHead); 130 PharmacyHead head = new PharmacyHead() 131 { 132 Name = pharmacyHead.Name, 133 Email = pharmacyHead.Email, 134 Password = pharmacyHead.Password, 135 Pharmacies = null, 136 Medicines = null 137 }; 138 await _iPHRepo.Add(head); 124 139 return true; 125 140 } … … 149 164 } 150 165 151 public objectGetPharmacyHead(string userName)166 public PharmacyHeadDto GetPharmacyHead(string userName) 152 167 { 153 168 if (userName != null) … … 156 171 List<PharmacyHeadMedicine> PHMedicines = _iPHRepo.GetPharmacyHeadMedicines(userName); 157 172 List<Medicine> Medicines = _repository.GetMedicines().ToList(); 158 List<Medicine> PHMedicineList = new List<Medicine>(); 159 160 161 //var meds = PHMedicines.Where(x => x.Id == Phead.Id).ToList(); 162 var pharmacies = _iPHRepo.GetPharmacies(); 163 var PheadPharms = pharmacies.Where(x => x.PheadId == Phead.Id).ToList(); 173 List<Medicine> MedicineList = new List<Medicine>(); 174 164 175 var user = _repository.GetRole(userName); 165 176 … … 167 178 if (user.UserRole.ToString().Equals("Admin")) 168 179 { 169 var Admin = new PharmacyHead() 180 List<Pharmacy> pharmacies = new List<Pharmacy>(); 181 pharmacies = Phead.Pharmacies; 182 var Admin = new PharmacyHeadDto() 170 183 { 171 184 Id = user.Id, … … 173 186 Name = user.Name, 174 187 Password = user.Password, 175 Pharmacies List = Phead.PharmaciesList188 Pharmacies = pharmacies 176 189 }; 177 190 178 191 return Admin; 179 192 } 180 181 if (PheadPharms.Count() > 0 || PheadPharms != null) 182 Phead.PharmaciesList = PheadPharms; 183 else Phead.PharmaciesList = pharmacies; 184 185 if (Phead.PHMedicineList.Count() > 0 || Phead.PHMedicineList != null) 193 else 186 194 { 187 195 foreach (var med in Medicines) 188 196 { 189 190 var PHMObj = Phead.PHMedicineList.Where(x => x.MedicineId == med.Id).SingleOrDefault(); 197 var PHMObj = Phead.Medicines.Where(x => x.MedicineId == med.Id).SingleOrDefault(); 191 198 if (PHMObj == null) 192 199 { 193 200 continue; 194 201 } 195 var phm = Phead.MedicineList;196 202 if (PHMObj.MedicineId == med.Id) 197 203 { … … 207 213 Packaging = med.Packaging 208 214 }; 209 PHMedicineList.Add(medicine);215 MedicineList.Add(medicine); 210 216 } 211 217 } 212 Phead.MedicineList = PHMedicineList; 213 } 214 else 215 { 216 Phead.MedicineList = Medicines; 217 } 218 219 PharmacyHead pharHead = new PharmacyHead() 218 } 219 220 PharmacyHeadDto pharmacyHead = new PharmacyHeadDto() 220 221 { 221 222 Id = Phead.Id, 222 Medicine List = Phead.MedicineList,223 Pharmacies List = Phead.PharmaciesList,223 Medicines = MedicineList, 224 Pharmacies = Phead.Pharmacies, 224 225 Email = Phead.Email, 225 226 Name = Phead.Name, 226 227 Password = Phead.Password 227 228 }; 228 return phar Head;229 return pharmacyHead; 229 230 } 230 231 else throw new Exception("Username is null."); -
FarmatikoServices/Services/ProcessJSONService.cs
r8e74e2f rdb484c9 174 174 HealthFacility facility = _service.GetFacilityJSON(Convert.ToString(FacilityName)); 175 175 176 if (facility != null )176 if (facility != null && facility != default) 177 177 { 178 178 HealthFacility Facility = new HealthFacility( -
FarmatikoServices/Services/Service.cs
r8e74e2f rdb484c9 130 130 public User MakeUser(PharmacyHead head) 131 131 { 132 var users = _repository.GetUsers();132 133 133 134 134 User user = new User() -
FarmatikoServices/Services/SystemService.cs
r8e74e2f rdb484c9 7 7 public interface ISystemService 8 8 { 9 9 public void ParseHTML(); 10 10 } 11 11 public class SystemService
Note:
See TracChangeset
for help on using the changeset viewer.