1 | using FarmatikoData.FarmatikoRepoInterfaces;
|
---|
2 | using FarmatikoData.Models;
|
---|
3 | using FarmatikoServices.FarmatikoServiceInterfaces;
|
---|
4 | using System;
|
---|
5 | using System.Linq;
|
---|
6 | using System.Threading.Tasks;
|
---|
7 |
|
---|
8 | namespace FarmatikoServices.Services
|
---|
9 | {
|
---|
10 | public class Service : IService
|
---|
11 | {
|
---|
12 | private readonly IRepository _repository;
|
---|
13 | public Service(IRepository repository)
|
---|
14 | {
|
---|
15 | _repository = repository;
|
---|
16 | }
|
---|
17 |
|
---|
18 | //GET
|
---|
19 | public async Task<IQueryable<HealthcareWorker>> GetAllWorkers()
|
---|
20 | {
|
---|
21 | var Workers = await _repository.GetAllWorkers();
|
---|
22 | return Workers;
|
---|
23 | }
|
---|
24 |
|
---|
25 | public async Task<IQueryable<HealthFacility>> GetFacilities()
|
---|
26 | {
|
---|
27 | var Facilities = await _repository.GetFacilities();
|
---|
28 | return Facilities;
|
---|
29 | }
|
---|
30 |
|
---|
31 | public async Task<HealthFacility> GetFacility(int id)
|
---|
32 | {
|
---|
33 | var Facility = await _repository.GetFacility(id);
|
---|
34 | return Facility;
|
---|
35 | }
|
---|
36 |
|
---|
37 | public async Task<Medicine> GetMedicine(int id)
|
---|
38 | {
|
---|
39 | var Medicine = await _repository.GetMedicine(id);
|
---|
40 | return Medicine;
|
---|
41 | }
|
---|
42 |
|
---|
43 | public async Task<IQueryable<Medicine>> GetMedicines()
|
---|
44 | {
|
---|
45 | var Medicines = await _repository.GetMedicines();
|
---|
46 | return Medicines;
|
---|
47 | }
|
---|
48 |
|
---|
49 | public async Task<Pandemic> GetPandemic()
|
---|
50 | {
|
---|
51 | var Pandemic = await _repository.GetPandemic();
|
---|
52 | return Pandemic;
|
---|
53 | }
|
---|
54 |
|
---|
55 | public async Task<IQueryable<Pharmacy>> GetPharmacies()
|
---|
56 | {
|
---|
57 | var Pharmacies = await _repository.GetPharmacies();
|
---|
58 | return Pharmacies;
|
---|
59 | }
|
---|
60 |
|
---|
61 | public async Task<Pharmacy> GetPharmacy(int id)
|
---|
62 | {
|
---|
63 | var Pharmacy = await _repository.GetPharmacy(id);
|
---|
64 | return Pharmacy;
|
---|
65 | }
|
---|
66 |
|
---|
67 | public async Task<HealthcareWorker> GetWorker(int id)
|
---|
68 | {
|
---|
69 | var Worker = await _repository.GetWorker(id);
|
---|
70 | return Worker;
|
---|
71 | }
|
---|
72 |
|
---|
73 | public async Task<IQueryable<HealthFacility>> SearchFacilities(string query)
|
---|
74 | {
|
---|
75 | var SearchQuery = await _repository.SearchFacilities(query);
|
---|
76 | return SearchQuery;
|
---|
77 | }
|
---|
78 |
|
---|
79 | public async Task<IQueryable<Medicine>> SearchMedicines(string query)
|
---|
80 | {
|
---|
81 | var SearchQuery = await _repository.SearchMedicines(query);
|
---|
82 | return SearchQuery;
|
---|
83 | }
|
---|
84 |
|
---|
85 | public async Task<IQueryable<Pharmacy>> SearchPharmacies(string query)
|
---|
86 | {
|
---|
87 | var SearchQuery = await _repository.SearchPharmacies(query);
|
---|
88 | return SearchQuery;
|
---|
89 | }
|
---|
90 |
|
---|
91 | public async Task<IQueryable<HealthcareWorker>> SearchWorkers(string query)
|
---|
92 | {
|
---|
93 | var SearchQuery = await _repository.SearchWorkers(query);
|
---|
94 | return SearchQuery;
|
---|
95 | }
|
---|
96 |
|
---|
97 |
|
---|
98 | //POST (ADD NEW OBJECTS)
|
---|
99 | //za json(Sys updateer)
|
---|
100 | public async Task AddFacility(HealthFacility healthFacilities)
|
---|
101 | {
|
---|
102 | if (healthFacilities != null)
|
---|
103 | await _repository.AddFacility(healthFacilities);
|
---|
104 | throw new Exception("Facility is null");
|
---|
105 | }
|
---|
106 | //za json(Sys updateer)
|
---|
107 | public async Task AddMedicines(Medicine medicine)
|
---|
108 | {
|
---|
109 | if (medicine != null)
|
---|
110 | await _repository.AddMedicines(medicine);
|
---|
111 | throw new Exception("Medicine is null");
|
---|
112 | }
|
---|
113 | //za json(Sys updateer)
|
---|
114 | public async Task AddPandemic(Pandemic pandemic)
|
---|
115 | {
|
---|
116 | if (pandemic != null)
|
---|
117 | await _repository.AddPandemic(pandemic);
|
---|
118 | throw new Exception("Pandemic is null");
|
---|
119 | }
|
---|
120 | // Samo PharmacyHead i Admin imaat pristap
|
---|
121 | public async Task AddPharmacy(Pharmacy pharmacy)
|
---|
122 | {
|
---|
123 | if (pharmacy != null)
|
---|
124 | await _repository.AddPharmacy(pharmacy);
|
---|
125 | throw new Exception("Pharmacy is null");
|
---|
126 | }
|
---|
127 | // Ovaa kontrola ja ima samo admin
|
---|
128 | public async Task AddPharmacyHead(PharmacyHead pharmacyHead)
|
---|
129 | {
|
---|
130 | if (pharmacyHead != null)
|
---|
131 | {
|
---|
132 | var Medicines = await _repository.GetMedicines();
|
---|
133 | foreach (var med in Medicines)
|
---|
134 | {
|
---|
135 | MedicineList medicine = new MedicineList()
|
---|
136 | {
|
---|
137 | Medicine = med,
|
---|
138 | HasMedicine = false
|
---|
139 | };
|
---|
140 | pharmacyHead.MedicineLists.Add(medicine);
|
---|
141 | }
|
---|
142 | await _repository.AddPharmacyHead(pharmacyHead);
|
---|
143 | }
|
---|
144 | throw new Exception("PharmacyHead is null");
|
---|
145 | }
|
---|
146 | //za json(Sys updateer)
|
---|
147 | public async Task AddWorker(HealthcareWorker worker)
|
---|
148 | {
|
---|
149 | if (worker != null)
|
---|
150 | await _repository.AddWorker(worker);
|
---|
151 | throw new Exception("Worker is null");
|
---|
152 | }
|
---|
153 |
|
---|
154 | //za json(Sys updateer)
|
---|
155 | public async Task UpdateFacility(HealthFacility healthFacilities)
|
---|
156 | {
|
---|
157 | if (healthFacilities != null)
|
---|
158 | await _repository.UpdateFacility(healthFacilities);
|
---|
159 | throw new Exception("Facility is null");
|
---|
160 | }
|
---|
161 | //PharmacyHead
|
---|
162 | public async Task RemoveMedicine(Medicine medicine)
|
---|
163 | {
|
---|
164 | if (medicine != null)
|
---|
165 | await _repository.RemoveMedicine(medicine);
|
---|
166 | throw new Exception("Medicine is null");
|
---|
167 | }
|
---|
168 | //PharmacyHead
|
---|
169 | public async Task UpdateMedicine(Medicine medicine)
|
---|
170 | {
|
---|
171 | if (medicine != null)
|
---|
172 | await _repository.UpdateMedicine(medicine);
|
---|
173 | throw new Exception("Medicine is null");
|
---|
174 | }
|
---|
175 | //za json(Sys updateer)
|
---|
176 | public async Task UpdatePandemic(Pandemic pandemic)
|
---|
177 | {
|
---|
178 | if (pandemic != null)
|
---|
179 | await _repository.UpdatePandemic(pandemic);
|
---|
180 | throw new Exception("Pandemic is null");
|
---|
181 | }
|
---|
182 | //PharmacyHead
|
---|
183 | public async Task RemovePharmacy(Pharmacy pharmacy)
|
---|
184 | {
|
---|
185 | if (pharmacy != null)
|
---|
186 | await _repository.RemovePharmacy(pharmacy);
|
---|
187 | throw new Exception("Pharmacy is null");
|
---|
188 | }
|
---|
189 | //PharamcyHead
|
---|
190 | public async Task UpdatePharmacy(Pharmacy pharmacy)
|
---|
191 | {
|
---|
192 | if (pharmacy != null)
|
---|
193 | await _repository.UpadatePharmacy(pharmacy);
|
---|
194 | throw new Exception("Pharmacy is null");
|
---|
195 | }
|
---|
196 | //za json(Sys updateer)
|
---|
197 | public async Task UpdateWorker(HealthcareWorker worker)
|
---|
198 | {
|
---|
199 | if (worker != null)
|
---|
200 | await _repository.UpdateWorker(worker);
|
---|
201 | throw new Exception("Worker is null");
|
---|
202 | }
|
---|
203 |
|
---|
204 | public async Task RemovePharmacyHead(PharmacyHead pharmacyHead)
|
---|
205 | {
|
---|
206 | if (pharmacyHead != null)
|
---|
207 | {
|
---|
208 | pharmacyHead.DeletedOn = DateTime.UtcNow;
|
---|
209 | await _repository.RemovePharmacyHead(pharmacyHead);
|
---|
210 | }
|
---|
211 | else throw new Exception("PharmacyHead is null.");
|
---|
212 | }
|
---|
213 |
|
---|
214 | public async Task<HealthFacility> GetFacilityJSON(string healthFacility)
|
---|
215 | {
|
---|
216 | if (healthFacility != null)
|
---|
217 | return await _repository.GetFacilityJSON(healthFacility);
|
---|
218 | return null;
|
---|
219 | }
|
---|
220 |
|
---|
221 | //PUT (EDIT OBJECTS)
|
---|
222 |
|
---|
223 |
|
---|
224 | //DELETE
|
---|
225 |
|
---|
226 | }
|
---|
227 | }
|
---|