Changeset e0cdea2 for FarmatikoData/FarmatikoRepo
- Timestamp:
- 02/08/21 16:39:25 (4 years ago)
- Branches:
- master
- Children:
- 8eb1e21, dae4cde
- Parents:
- 0a694bb
- Location:
- FarmatikoData/FarmatikoRepo
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
FarmatikoData/FarmatikoRepo/AdminRepo.cs
r0a694bb re0cdea2 20 20 public async Task<IEnumerable<RequestPharmacyHead>> GetClaimingRequests() 21 21 { 22 var reqs = await _context.PHRequests.OrderBy(x => x.Head.Name).ToListAsync(); 22 var reqs = await _context.PHRequests.Select(x => new RequestPharmacyHead 23 { 24 Head = x.Head, 25 Pharmacy = x.Pharmacy 26 }).OrderBy(x => x.Head.Name).ToListAsync(); 23 27 return reqs; 24 28 } … … 35 39 } 36 40 //POST 37 public async void RemoveClaimRequest(int Id)41 public void RemoveClaimRequest(RequestPharmacyHead request) 38 42 { 39 var req = _context.PHRequests.Where(x => x.Id == Id).FirstOrDefault(); 43 var req = _context.PHRequests.Select(x => new RequestPharmacyHead { Head = x.Head, Pharmacy = x.Pharmacy, Id = x.Id}) 44 .Where(x => x.Head.Email.Equals(request.Head.Email)).FirstOrDefault(); 40 45 _context.PHRequests.Remove(req); 41 await _context.SaveChangesAsync();46 _context.SaveChanges(); 42 47 } 43 48 } -
FarmatikoData/FarmatikoRepo/PHRepo.cs
r0a694bb re0cdea2 41 41 public async Task UpdatePharmacyHead(PharmacyHead pharmacyHead) 42 42 { 43 var Phead = await _context.PharmacyHeads.Where(x => x.Email == pharmacyHead.Email).FirstOrDefaultAsync();44 var EditedPHead = await _context.PharmacyHeads. AsNoTracking<PharmacyHead>().Where(x => x.Email == pharmacyHead.Email).FirstOrDefaultAsync();43 var user = await _context.Users.Where(x => x.Email == pharmacyHead.Email).FirstOrDefaultAsync(); 44 var EditedPHead = await _context.PharmacyHeads.Where(x => x.Email.Equals(pharmacyHead.Email)).FirstOrDefaultAsync(); 45 45 46 if (!EditedPHead.Email.Equals(pharmacyHead.Email)) 46 /*if (!EditedPHead.Email.Equals(pharmacyHead.Email) && !user.Email.Equals(pharmacyHead.Email)) 47 { 47 48 EditedPHead.Email = pharmacyHead.Email; 49 user.Email = pharmacyHead.Email; 50 }*/ 48 51 49 if (!EditedPHead.Name.Equals(pharmacyHead.Name)) 52 if (!EditedPHead.Name.Equals(pharmacyHead.Name) || !user.Name.Equals(pharmacyHead.Name)) 53 { 50 54 EditedPHead.Name = pharmacyHead.Name; 55 user.Name = pharmacyHead.Name; 56 } 51 57 52 if (!EditedPHead.Password.Equals(pharmacyHead.Password)) 58 if (!EditedPHead.Password.Equals(pharmacyHead.Password) || !user.Password.Equals(pharmacyHead.Password)) 59 { 53 60 EditedPHead.Password = pharmacyHead.Password; 61 user.Password = pharmacyHead.Password; 62 } 63 /*if (EditedPHead.Pharmacies != null) 64 { 65 if (EditedPHead.Pharmacies.Count() > 0) 66 if (!EditedPHead.Pharmacies.Equals(pharmacyHead.Pharmacies)) 67 EditedPHead.Pharmacies = pharmacyHead.Pharmacies; 68 } 69 if (EditedPHead.Medicines != null) 70 { 71 if (EditedPHead.Medicines.Count() > 0) 72 { 73 if (!EditedPHead.Medicines.Equals(pharmacyHead.Medicines)) 74 EditedPHead.Medicines = pharmacyHead.Medicines; 75 76 } 77 78 }*/ 54 79 55 if (!EditedPHead.Pharmacies.Equals(pharmacyHead.Pharmacies)) 56 EditedPHead.Pharmacies = pharmacyHead.Pharmacies; 57 58 if (!EditedPHead.Medicines.Equals(pharmacyHead.Medicines)) 59 EditedPHead.Medicines = pharmacyHead.Medicines; 60 61 await _context.SaveChangesAsync(); 80 _context.SaveChanges(); 62 81 } 63 82 public async Task ClaimPharmacy(RequestPharmacyHead pharmacy) 64 83 { 84 var phead = _context.PharmacyHeads.Where(x => x.Email.Equals(pharmacy.Head.Email)).FirstOrDefault(); 85 pharmacy.Head = phead; 65 86 await _context.PHRequests.AddAsync(pharmacy); 66 87 await _context.SaveChangesAsync(); -
FarmatikoData/FarmatikoRepo/Repository.cs
r0a694bb re0cdea2 19 19 public async Task<IEnumerable<HealthcareWorker>> GetAllWorkers() 20 20 { 21 var Workers = await _context.HealthcareWorkers.Take(5).ToListAsync(); 21 var Workers = await _context.HealthcareWorkers.Select(x => new HealthcareWorker 22 { 23 Id = x.Id, 24 Name = x.Name, 25 Branch = x.Branch, 26 Facility = x.Facility, 27 Title = x.Title 28 }).Take(5).ToListAsync(); 22 29 return Workers; 23 30 } … … 54 61 Packaging = x.Packaging 55 62 56 }).Take( 3).ToListAsync();63 }).Take(5).ToListAsync(); 57 64 return Medicines; 58 65 } … … 92 99 { 93 100 var SearchQuery = await _context.HealthFacilities 94 .Where(x => x.Name.ToLowerInvariant().Contains(query.ToLowerInvariant())) 101 .Where(x => x.Name.ToLower().Contains(query.ToLower()) 102 || x.Municipality.ToLower().Contains(query.ToLower()) 103 || x.Type.ToLower().Contains(query.ToLower())).Take(5) 95 104 .OrderBy(x => x.Name).ToListAsync(); 96 105 … … 101 110 { 102 111 var SearchQuery = await _context.Medicines 103 .Where(x => x.Name.ToLowerInvariant().Contains(query.ToLowerInvariant())) 112 .Where(x => x.Name.ToLower().Contains(query.ToLower()) 113 || x.Form.ToLower().Contains(query.ToLower()) 114 || x.Strength.ToLower().Contains(query.ToLower()) 115 || x.Packaging.ToLower().Contains(query.ToLower())).Take(20) 104 116 .OrderBy(x => x.Name).ToListAsync(); 105 117 … … 110 122 { 111 123 var SearchQuery = await _context.Pharmacies 112 .Where(x => x.Name.ToLowerInvariant().Contains(query.ToLowerInvariant())) 124 .Where(x => x.Name.ToLower().Contains(query.ToLower()) 125 || x.PharmacyHead.Name.ToLower().Contains(query.ToLower())).Take(5) 113 126 .OrderBy(x => x.Name).ToListAsync(); 114 127 … … 118 131 public async Task<IEnumerable<HealthcareWorker>> SearchWorkers(string query) 119 132 { 120 var SearchQuery = await _context.HealthcareWorkers 121 .Where(x => x.Name.ToLowerInvariant().Contains(query.ToLowerInvariant())) 133 var SearchQuery = await _context.HealthcareWorkers.Include(x => x.Facility) 134 .Where(x => x.Name.ToLower().Contains(query.ToLower()) 135 || x.Facility.Name.ToLower().Contains(query.ToLower())).Take(20) 122 136 .OrderBy(x => x.Name).ToListAsync(); 123 137 … … 146 160 public async Task AddPharmacy(Pharmacy pharmacy) 147 161 { 148 await _context.Pharmacies.AddAsync(pharmacy); 149 _context.SaveChanges(); 162 pharmacy.Id = 0; 163 if (pharmacy.Id == 0) 164 { 165 var phars = _context.Pharmacies.Select(x => new Pharmacy 166 { 167 Name = x.Name, 168 Location = x.Location, 169 Address = x.Address 170 }).ToList(); 171 var pharms = phars.Where(x => x.Name.Equals(pharmacy.Name) && x.Location.Equals(pharmacy.Location) && x.Address.Equals(pharmacy.Address)).ToList(); 172 if (pharms is null || pharms.Count() == 0) 173 { 174 await _context.Pharmacies.AddAsync(pharmacy); 175 _context.SaveChanges(); 176 } 177 178 } 150 179 } 151 180 … … 242 271 { 243 272 var PHead = await _context.PharmacyHeads.Where(x => x.Id == Id).FirstOrDefaultAsync(); 244 PHead.DeletedOn = DateTime.UtcNow; 245 await _context.SaveChangesAsync(); 273 var user = await _context.Users.Where(x => x.Email.Equals(PHead.Email)).FirstOrDefaultAsync(); 274 _context.PharmacyHeads.Remove(PHead); 275 _context.Users.Remove(user); 276 _context.SaveChanges(); 246 277 } 247 278 … … 290 321 return phmeds; 291 322 } 292 293 public async Task<bool> AddUser(User user)323 324 /*public async Task<bool> AddUser(User user) 294 325 { 295 326 if (user.Id == 0) … … 303 334 }).ToListAsync(); 304 335 var usr = users.Where(x => x.Email.Equals(user.Email)).ToList(); 305 if (usr != null ||usr.Count() > 0)336 if (usr != null && usr.Count() > 0) 306 337 { 307 338 return true; … … 315 346 } 316 347 return false; 317 } 348 }*/ 318 349 319 350 public async Task<List<PharmacyHeadMedicine>> GetAllPHMedicines() … … 329 360 return list; 330 361 } 362 363 public ICollection<PharmacyHeadMedicine> GetPHMedicines() 364 { 365 var meds = _context.PharmacyHeadMedicines.Select(x => new PharmacyHeadMedicine 366 { 367 PheadId = x.PheadId, 368 Head = x.Head, 369 MedicineId = x.MedicineId, 370 Medicine = x.Medicine 371 }).ToList(); 372 return meds; 373 } 331 374 } 332 375 }
Note:
See TracChangeset
for help on using the changeset viewer.