source: FarmatikoData/FarmatikoRepo/Repository.cs@ 5d02859

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

Add new repo, service and controller

  • Property mode set to 100644
File size: 4.4 KB
Line 
1using FarmatikoData.FarmatikoRepoInterfaces;
2using FarmatikoData.Models;
3using System.Linq;
4using System.Threading.Tasks;
5
6namespace FarmatikoData.FarmatikoRepo
7{
8 public class Repository : IRepository
9 {
10 private readonly FarmatikoDataContext _context;
11 public Repository(FarmatikoDataContext context)
12 {
13 _context = context;
14 }
15 //GET
16 public async Task<IQueryable<HealthcareWorkers>> GetAllWorkers()
17 {
18 var Workers = await Task.Run(() => _context.HealthcareWorkers.Take(10));
19 return Workers;
20 }
21
22 public async Task<IQueryable<HealthFacilities>> GetFacilities()
23 {
24 var Facilities = await Task.Run(() => _context.HealthFacilities.Take(10));
25 return Facilities;
26 }
27
28 public async Task<HealthFacilities> GetFacility(int Id)
29 {
30 var Facility = await _context.HealthFacilities.FindAsync(Id);
31 return Facility;
32 }
33
34 public async Task<Medicine> GetMedicine(int Id)
35 {
36 var Medicine = await _context.Medicines.FindAsync(Id);
37 return Medicine;
38 }
39
40 public async Task<IQueryable<Medicine>> GetMedicines()
41 {
42 var Medicines = await Task.Run(() => _context.Medicines.Take(10));
43 return Medicines;
44 }
45
46 public async Task<Pandemic> GetPandemic()
47 {
48 var Pandemic = await Task.Run(() => _context.Pandemics.FirstOrDefault());
49 return Pandemic;
50 }
51
52 public async Task<IQueryable<Pharmacy>> GetPharmacies()
53 {
54 var Pharmacies = await Task.Run(() => _context.Pharmacies.Take(10));
55 return Pharmacies;
56 }
57
58 public async Task<Pharmacy> GetPharmacy(int id)
59 {
60 var Pharmacy = await _context.Pharmacies.FindAsync(id);
61 return Pharmacy;
62 }
63
64 public async Task<HealthcareWorkers> GetWorker(int id)
65 {
66 var Worker = await _context.HealthcareWorkers.FindAsync(id);
67 return Worker;
68 }
69
70 public async Task<IQueryable<HealthFacilities>> SearchFacilities(string query)
71 {
72 var SearchQuery = await Task.Run(() => _context.HealthFacilities
73 .Where(x => x.Name.Equals(query))
74 .OrderBy(x => x.Name));
75
76 return SearchQuery;
77 }
78
79 public async Task<IQueryable<Medicine>> SearchMedicines(string query)
80 {
81 var SearchQuery = await Task.Run(() => _context.Medicines
82 .Where(x => x.Name.Equals(query))
83 .OrderBy(x => x.Name));
84
85 return SearchQuery;
86 }
87
88 public async Task<IQueryable<Pharmacy>> SearchPharmacies(string query)
89 {
90 var SearchQuery = await Task.Run(() => _context.Pharmacies
91 .Where(x => x.Name.Equals(query))
92 .OrderBy(x => x.Name));
93
94 return SearchQuery;
95 }
96
97 public async Task<IQueryable<HealthcareWorkers>> SearchWorkers(string query)
98 {
99 var SearchQuery = await Task.Run(() => _context.HealthcareWorkers
100 .Where(x => x.Name.Equals(query))
101 .OrderBy(x => x.Name));
102
103 return SearchQuery;
104 }
105
106 //POST
107
108 public async Task AddWorker(HealthcareWorkers Worker)
109 {
110 await Task.Run(() => _context.HealthcareWorkers.Add(Worker));
111 await _context.SaveChangesAsync();
112 }
113
114 public async Task AddFacility(HealthFacilities healthFacility)
115 {
116 await Task.Run(() => _context.HealthFacilities.Add(healthFacility));
117 await _context.SaveChangesAsync();
118 }
119
120 public async Task AddPharmacy(Pharmacy pharmacy)
121 {
122 await Task.Run(() => _context.Pharmacies.Add(pharmacy));
123 await _context.SaveChangesAsync();
124 }
125
126 public async Task AddPharmacyHead(PharmacyHead pharmacyHead)
127 {
128 await Task.Run(() => _context.PharmacyHeads.Add(pharmacyHead));
129 await _context.SaveChangesAsync();
130 }
131
132 public async Task AddMedicines(Medicine medicine)
133 {
134 await Task.Run(() => _context.Medicines.Add(medicine));
135 await _context.SaveChangesAsync();
136 }
137
138 public async Task AddPandemic(Pandemic pandemic)
139 {
140 await Task.Run(() => _context.Pandemics.Add(pandemic));
141 await _context.SaveChangesAsync();
142 }
143 }
144}
Note: See TracBrowser for help on using the repository browser.