[5d02859] | 1 | using FarmatikoData.FarmatikoRepoInterfaces;
|
---|
| 2 | using FarmatikoData.Models;
|
---|
| 3 | using FarmatikoServices.FarmatikoServiceInterfaces;
|
---|
| 4 | using System;
|
---|
[6f203af] | 5 | using System.Collections.Generic;
|
---|
[5d02859] | 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
|
---|
[6f203af] | 20 | public async Task<IEnumerable<HealthcareWorker>> GetAllWorkers()
|
---|
[5d02859] | 21 | {
|
---|
| 22 | var Workers = await _repository.GetAllWorkers();
|
---|
| 23 | return Workers;
|
---|
| 24 | }
|
---|
| 25 |
|
---|
[6f203af] | 26 | public async Task<IEnumerable<HealthFacility>> GetFacilities()
|
---|
[5d02859] | 27 | {
|
---|
| 28 | var Facilities = await _repository.GetFacilities();
|
---|
| 29 | return Facilities;
|
---|
| 30 | }
|
---|
| 31 |
|
---|
[1454207] | 32 | public async Task<HealthFacility> GetFacility(int id)
|
---|
[5d02859] | 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 |
|
---|
[6f203af] | 44 | public async Task<IEnumerable<Medicine>> GetMedicines()
|
---|
[5d02859] | 45 | {
|
---|
[1db5673] | 46 | var Medicines = await _repository.GetMedicinesAsync();
|
---|
[5d02859] | 47 | return Medicines;
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | public async Task<Pandemic> GetPandemic()
|
---|
| 51 | {
|
---|
| 52 | var Pandemic = await _repository.GetPandemic();
|
---|
| 53 | return Pandemic;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
[6f203af] | 56 | public async Task<IEnumerable<Pharmacy>> GetPharmacies()
|
---|
[5d02859] | 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 |
|
---|
[1454207] | 68 | public async Task<HealthcareWorker> GetWorker(int id)
|
---|
[5d02859] | 69 | {
|
---|
| 70 | var Worker = await _repository.GetWorker(id);
|
---|
| 71 | return Worker;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
[6f203af] | 74 | public async Task<IEnumerable<HealthFacility>> SearchFacilities(string query)
|
---|
[5d02859] | 75 | {
|
---|
| 76 | var SearchQuery = await _repository.SearchFacilities(query);
|
---|
| 77 | return SearchQuery;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[6f203af] | 80 | public async Task<IEnumerable<Medicine>> SearchMedicines(string query)
|
---|
[5d02859] | 81 | {
|
---|
| 82 | var SearchQuery = await _repository.SearchMedicines(query);
|
---|
| 83 | return SearchQuery;
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[6f203af] | 86 | public async Task<IEnumerable<Pharmacy>> SearchPharmacies(string query)
|
---|
[5d02859] | 87 | {
|
---|
| 88 | var SearchQuery = await _repository.SearchPharmacies(query);
|
---|
| 89 | return SearchQuery;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
[6f203af] | 92 | public async Task<IEnumerable<HealthcareWorker>> SearchWorkers(string query)
|
---|
[5d02859] | 93 | {
|
---|
| 94 | var SearchQuery = await _repository.SearchWorkers(query);
|
---|
| 95 | return SearchQuery;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 |
|
---|
| 99 | //POST (ADD NEW OBJECTS)
|
---|
[1454207] | 100 | //za json(Sys updateer)
|
---|
| 101 | public async Task AddFacility(HealthFacility healthFacilities)
|
---|
[5d02859] | 102 | {
|
---|
| 103 | if (healthFacilities != null)
|
---|
[1454207] | 104 | await _repository.AddFacility(healthFacilities);
|
---|
[d23bf72] | 105 | else throw new Exception("Facility is null");
|
---|
[5d02859] | 106 | }
|
---|
[1454207] | 107 | //za json(Sys updateer)
|
---|
| 108 | public async Task AddMedicines(Medicine medicine)
|
---|
[5d02859] | 109 | {
|
---|
| 110 | if (medicine != null)
|
---|
[1454207] | 111 | await _repository.AddMedicines(medicine);
|
---|
[d23bf72] | 112 | else throw new Exception("Medicine is null");
|
---|
[5d02859] | 113 | }
|
---|
[1454207] | 114 | //za json(Sys updateer)
|
---|
| 115 | public async Task AddPandemic(Pandemic pandemic)
|
---|
[5d02859] | 116 | {
|
---|
| 117 | if (pandemic != null)
|
---|
[1454207] | 118 | await _repository.AddPandemic(pandemic);
|
---|
[d23bf72] | 119 | else throw new Exception("Pandemic is null");
|
---|
[5d02859] | 120 | }
|
---|
[1454207] | 121 | // Samo PharmacyHead i Admin imaat pristap
|
---|
| 122 | public async Task AddPharmacy(Pharmacy pharmacy)
|
---|
[5d02859] | 123 | {
|
---|
| 124 | if (pharmacy != null)
|
---|
[1454207] | 125 | await _repository.AddPharmacy(pharmacy);
|
---|
[d23bf72] | 126 | else throw new Exception("Pharmacy is null");
|
---|
[5d02859] | 127 | }
|
---|
[1db5673] | 128 |
|
---|
[1454207] | 129 | // Ovaa kontrola ja ima samo admin
|
---|
| 130 | public async Task AddPharmacyHead(PharmacyHead pharmacyHead)
|
---|
[5d02859] | 131 | {
|
---|
| 132 | if (pharmacyHead != null)
|
---|
[1454207] | 133 | {
|
---|
[1db5673] | 134 | var Medicines = await _repository.GetMedicinesAsync();
|
---|
[1454207] | 135 | foreach (var med in Medicines)
|
---|
| 136 | {
|
---|
[1db5673] | 137 | pharmacyHead.MedicineList.Add(med);
|
---|
[1454207] | 138 | }
|
---|
[1db5673] | 139 |
|
---|
[1454207] | 140 | await _repository.AddPharmacyHead(pharmacyHead);
|
---|
| 141 | }
|
---|
[1db5673] | 142 | else throw new Exception("PharmacyHead is null");
|
---|
[5d02859] | 143 | }
|
---|
[afc9a9a] | 144 | //za json(Sys updater)
|
---|
[1454207] | 145 | public async Task AddWorker(HealthcareWorker worker)
|
---|
| 146 | {
|
---|
| 147 | if (worker != null)
|
---|
| 148 | await _repository.AddWorker(worker);
|
---|
[d23bf72] | 149 | else throw new Exception("Worker is null");
|
---|
[1454207] | 150 | }
|
---|
[5d02859] | 151 |
|
---|
[1454207] | 152 | //za json(Sys updateer)
|
---|
| 153 | public async Task UpdateFacility(HealthFacility healthFacilities)
|
---|
| 154 | {
|
---|
| 155 | if (healthFacilities != null)
|
---|
| 156 | await _repository.UpdateFacility(healthFacilities);
|
---|
[d23bf72] | 157 | else throw new Exception("Facility is null");
|
---|
[1454207] | 158 | }
|
---|
| 159 | //PharmacyHead
|
---|
| 160 | public async Task RemoveMedicine(Medicine medicine)
|
---|
| 161 | {
|
---|
| 162 | if (medicine != null)
|
---|
| 163 | await _repository.RemoveMedicine(medicine);
|
---|
[d23bf72] | 164 | else throw new Exception("Medicine is null");
|
---|
[1454207] | 165 | }
|
---|
| 166 | //PharmacyHead
|
---|
| 167 | public async Task UpdateMedicine(Medicine medicine)
|
---|
| 168 | {
|
---|
| 169 | if (medicine != null)
|
---|
| 170 | await _repository.UpdateMedicine(medicine);
|
---|
[d23bf72] | 171 | else throw new Exception("Medicine is null");
|
---|
[1454207] | 172 | }
|
---|
| 173 | //za json(Sys updateer)
|
---|
| 174 | public async Task UpdatePandemic(Pandemic pandemic)
|
---|
| 175 | {
|
---|
| 176 | if (pandemic != null)
|
---|
| 177 | await _repository.UpdatePandemic(pandemic);
|
---|
[d23bf72] | 178 | else throw new Exception("Pandemic is null");
|
---|
[1454207] | 179 | }
|
---|
| 180 | //PharmacyHead
|
---|
| 181 | public async Task RemovePharmacy(Pharmacy pharmacy)
|
---|
| 182 | {
|
---|
| 183 | if (pharmacy != null)
|
---|
| 184 | await _repository.RemovePharmacy(pharmacy);
|
---|
[d23bf72] | 185 | else throw new Exception("Pharmacy is null");
|
---|
[1454207] | 186 | }
|
---|
| 187 | //PharamcyHead
|
---|
| 188 | public async Task UpdatePharmacy(Pharmacy pharmacy)
|
---|
| 189 | {
|
---|
| 190 | if (pharmacy != null)
|
---|
| 191 | await _repository.UpadatePharmacy(pharmacy);
|
---|
[d23bf72] | 192 | else throw new Exception("Pharmacy is null");
|
---|
[1454207] | 193 | }
|
---|
| 194 | //za json(Sys updateer)
|
---|
| 195 | public async Task UpdateWorker(HealthcareWorker worker)
|
---|
[5d02859] | 196 | {
|
---|
| 197 | if (worker != null)
|
---|
[1454207] | 198 | await _repository.UpdateWorker(worker);
|
---|
[d23bf72] | 199 | else throw new Exception("Worker is null");
|
---|
[5d02859] | 200 | }
|
---|
| 201 |
|
---|
[6f203af] | 202 | public async Task RemovePharmacyHead(int Id)
|
---|
[1454207] | 203 | {
|
---|
[6f203af] | 204 | if (Id > 0)
|
---|
[1454207] | 205 | {
|
---|
[6f203af] | 206 | await _repository.RemovePharmacyHead(Id);
|
---|
[1454207] | 207 | }
|
---|
[d23bf72] | 208 | else throw new Exception("Index out of bounds.");
|
---|
[1454207] | 209 | }
|
---|
| 210 |
|
---|
[d23bf72] | 211 | public HealthFacility GetFacilityJSON(string healthFacility)
|
---|
[1454207] | 212 | {
|
---|
| 213 | if (healthFacility != null)
|
---|
[d23bf72] | 214 | return _repository.GetFacilityJSON(healthFacility);
|
---|
[1454207] | 215 | return null;
|
---|
| 216 | }
|
---|
| 217 |
|
---|
[5d02859] | 218 | //PUT (EDIT OBJECTS)
|
---|
| 219 |
|
---|
| 220 |
|
---|
| 221 | //DELETE
|
---|
| 222 |
|
---|
| 223 | }
|
---|
| 224 | }
|
---|