Changeset e0cdea2 for FarmatikoData/FarmatikoRepo/Repository.cs
- Timestamp:
- 02/08/21 16:39:25 (4 years ago)
- Branches:
- master
- Children:
- 8eb1e21, dae4cde
- Parents:
- 0a694bb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.