source: FarmatikoServices/Services/Service.cs@ 1db5673

Last change on this file since 1db5673 was 1db5673, checked in by DimitarSlezenkovski <dslezenkovski@…>, 4 years ago

Fix bugs, add some more

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