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