source: FarmatikoServices/Services/Service.cs@ d23bf72

Last change on this file since d23bf72 was d23bf72, checked in by DimitarSlezenkovski <dslezenkovski@…>, 23 months ago

Add SystemService, Auth, fix a lil bugs :)

  • Property mode set to 100644
File size: 7.2 KB
Line 
1using FarmatikoData.FarmatikoRepoInterfaces;
2using FarmatikoData.Models;
3using FarmatikoServices.FarmatikoServiceInterfaces;
4using System;
5using System.Collections.Generic;
6using System.Linq;
7using System.Threading.Tasks;
8
9namespace 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.GetMedicines();
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 // Ovaa kontrola ja ima samo admin
129 public async Task AddPharmacyHead(PharmacyHead pharmacyHead)
130 {
131 if (pharmacyHead != null)
132 {
133 var Medicines = await _repository.GetMedicines();
134 foreach (var med in Medicines)
135 {
136 MedicineList medicine = new MedicineList()
137 {
138 Medicine = med,
139 HasMedicine = false
140 };
141 pharmacyHead.MedicineLists.Add(medicine);
142 }
143 await _repository.AddPharmacyHead(pharmacyHead);
144 }
145 throw new Exception("PharmacyHead is null");
146 }
147 //za json(Sys updateer)
148 public async Task AddWorker(HealthcareWorker worker)
149 {
150 if (worker != null)
151 await _repository.AddWorker(worker);
152 else throw new Exception("Worker is null");
153 }
154
155 //za json(Sys updateer)
156 public async Task UpdateFacility(HealthFacility healthFacilities)
157 {
158 if (healthFacilities != null)
159 await _repository.UpdateFacility(healthFacilities);
160 else throw new Exception("Facility is null");
161 }
162 //PharmacyHead
163 public async Task RemoveMedicine(Medicine medicine)
164 {
165 if (medicine != null)
166 await _repository.RemoveMedicine(medicine);
167 else throw new Exception("Medicine is null");
168 }
169 //PharmacyHead
170 public async Task UpdateMedicine(Medicine medicine)
171 {
172 if (medicine != null)
173 await _repository.UpdateMedicine(medicine);
174 else throw new Exception("Medicine is null");
175 }
176 //za json(Sys updateer)
177 public async Task UpdatePandemic(Pandemic pandemic)
178 {
179 if (pandemic != null)
180 await _repository.UpdatePandemic(pandemic);
181 else throw new Exception("Pandemic is null");
182 }
183 //PharmacyHead
184 public async Task RemovePharmacy(Pharmacy pharmacy)
185 {
186 if (pharmacy != null)
187 await _repository.RemovePharmacy(pharmacy);
188 else throw new Exception("Pharmacy is null");
189 }
190 //PharamcyHead
191 public async Task UpdatePharmacy(Pharmacy pharmacy)
192 {
193 if (pharmacy != null)
194 await _repository.UpadatePharmacy(pharmacy);
195 else throw new Exception("Pharmacy is null");
196 }
197 //za json(Sys updateer)
198 public async Task UpdateWorker(HealthcareWorker worker)
199 {
200 if (worker != null)
201 await _repository.UpdateWorker(worker);
202 else throw new Exception("Worker is null");
203 }
204
205 public async Task RemovePharmacyHead(int Id)
206 {
207 if (Id > 0)
208 {
209 await _repository.RemovePharmacyHead(Id);
210 }
211 else throw new Exception("Index out of bounds.");
212 }
213
214 public HealthFacility GetFacilityJSON(string healthFacility)
215 {
216 if (healthFacility != null)
217 return _repository.GetFacilityJSON(healthFacility);
218 return null;
219 }
220
221 //PUT (EDIT OBJECTS)
222
223
224 //DELETE
225
226 }
227}
Note: See TracBrowser for help on using the repository browser.