source: FarmatikoData/FarmatikoRepo/PharmacyHeadRepository.cs@ c406ae5

Last change on this file since c406ae5 was c406ae5, checked in by DimitarSlezenkovski <dslezenkovski@…>, 2 years ago

Update Models, Repos, Services and Controllers

  • Property mode set to 100644
File size: 2.4 KB
Line 
1using FarmatikoData.FarmatikoRepoInterfaces;
2using FarmatikoData.Models;
3using System.Linq;
4
5namespace FarmatikoData.FarmatikoRepo
6{
7 public class PharmacyHeadRepository : IPharmacyHeadRepository
8 {
9 private FarmatikoDataContext _context;
10
11 public PharmacyHeadRepository(FarmatikoDataContext context)
12 {
13 _context = context;
14 }
15
16 public void Add(PharmacyHead pharmacyHead)
17 {
18 _context.PharmacyHeads.Add(pharmacyHead);
19 _context.SaveChangesAsync();
20 }
21
22 public IQueryable<PharmacyHead> GetAllPharmacies(string NameOfPharmacyHeads)
23 {
24 return _context.PharmacyHeads.Where(pharmacyHead => pharmacyHead.Name.Contains(NameOfPharmacyHeads))
25 .Take(10).Select(x => new PharmacyHead
26 {
27 MedicineLists = x.MedicineLists,
28 PharmaciesList = x.PharmaciesList,
29 Email = x.Email,
30 Name = x.Name,
31 }).OrderBy(x => x.Name);
32 }
33 //Not needed
34 public IQueryable<PharmacyHead> GetPharmacyByName(string Name)
35 {
36 return _context.PharmacyHeads.Take(10)
37 .Where(pharmacyHead => pharmacyHead.Name.Equals(Name))
38 .Select(x => new PharmacyHead
39 {
40 MedicineLists = x.MedicineLists,
41 PharmaciesList = x.PharmaciesList,
42 Email = x.Email,
43 Name = x.Name,
44 }).OrderBy(x => x.Name);
45 }
46
47 public IQueryable<MedicineList> GetPharmacyMedicines(string NameOfPharmacy)
48 {
49
50 IQueryable<MedicineList> Pharmacy = (IQueryable<MedicineList>)_context.PharmacyHeads
51 .Take(50)
52 .Where(x => x.Name.Equals(NameOfPharmacy))
53 .Select(x => new PharmacyHead
54 {
55 MedicineLists = x.MedicineLists
56 }).OrderBy(x => x.Name);
57
58 return Pharmacy;
59 }
60
61 public void Remove(PharmacyHead pharmacyHead)
62 {
63 var phead = _context.PharmacyHeads.Where(phead => phead.Name.Equals(pharmacyHead.Name)).FirstOrDefault();
64 if (phead != null)
65 {
66 _context.PharmacyHeads.Remove(phead);
67 _context.SaveChangesAsync();
68 }
69 }
70 }
71}
Note: See TracBrowser for help on using the repository browser.