[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
|
---|
[8e74e2f] | 130 | public User MakeUser(PharmacyHead head)
|
---|
| 131 | {
|
---|
| 132 | var users = _repository.GetUsers();
|
---|
| 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 | }
|
---|
[1454207] | 143 | public async Task AddPharmacyHead(PharmacyHead pharmacyHead)
|
---|
[5d02859] | 144 | {
|
---|
| 145 | if (pharmacyHead != null)
|
---|
[1454207] | 146 | {
|
---|
[8e74e2f] | 147 | var user = MakeUser(pharmacyHead);
|
---|
| 148 | await _repository.AddUser(user);
|
---|
[1454207] | 149 | await _repository.AddPharmacyHead(pharmacyHead);
|
---|
| 150 | }
|
---|
[1db5673] | 151 | else throw new Exception("PharmacyHead is null");
|
---|
[5d02859] | 152 | }
|
---|
[afc9a9a] | 153 | //za json(Sys updater)
|
---|
[1454207] | 154 | public async Task AddWorker(HealthcareWorker worker)
|
---|
| 155 | {
|
---|
| 156 | if (worker != null)
|
---|
| 157 | await _repository.AddWorker(worker);
|
---|
[d23bf72] | 158 | else throw new Exception("Worker is null");
|
---|
[1454207] | 159 | }
|
---|
[5d02859] | 160 |
|
---|
[1454207] | 161 | //za json(Sys updateer)
|
---|
| 162 | public async Task UpdateFacility(HealthFacility healthFacilities)
|
---|
| 163 | {
|
---|
| 164 | if (healthFacilities != null)
|
---|
| 165 | await _repository.UpdateFacility(healthFacilities);
|
---|
[d23bf72] | 166 | else throw new Exception("Facility is null");
|
---|
[1454207] | 167 | }
|
---|
| 168 | //PharmacyHead
|
---|
| 169 | public async Task RemoveMedicine(Medicine medicine)
|
---|
| 170 | {
|
---|
| 171 | if (medicine != null)
|
---|
| 172 | await _repository.RemoveMedicine(medicine);
|
---|
[d23bf72] | 173 | else throw new Exception("Medicine is null");
|
---|
[1454207] | 174 | }
|
---|
| 175 | //PharmacyHead
|
---|
| 176 | public async Task UpdateMedicine(Medicine medicine)
|
---|
| 177 | {
|
---|
| 178 | if (medicine != null)
|
---|
| 179 | await _repository.UpdateMedicine(medicine);
|
---|
[d23bf72] | 180 | else throw new Exception("Medicine is null");
|
---|
[1454207] | 181 | }
|
---|
| 182 | //za json(Sys updateer)
|
---|
| 183 | public async Task UpdatePandemic(Pandemic pandemic)
|
---|
| 184 | {
|
---|
| 185 | if (pandemic != null)
|
---|
| 186 | await _repository.UpdatePandemic(pandemic);
|
---|
[d23bf72] | 187 | else throw new Exception("Pandemic is null");
|
---|
[1454207] | 188 | }
|
---|
| 189 | //PharmacyHead
|
---|
| 190 | public async Task RemovePharmacy(Pharmacy pharmacy)
|
---|
| 191 | {
|
---|
| 192 | if (pharmacy != null)
|
---|
| 193 | await _repository.RemovePharmacy(pharmacy);
|
---|
[d23bf72] | 194 | else throw new Exception("Pharmacy is null");
|
---|
[1454207] | 195 | }
|
---|
| 196 | //PharamcyHead
|
---|
| 197 | public async Task UpdatePharmacy(Pharmacy pharmacy)
|
---|
| 198 | {
|
---|
| 199 | if (pharmacy != null)
|
---|
| 200 | await _repository.UpadatePharmacy(pharmacy);
|
---|
[d23bf72] | 201 | else throw new Exception("Pharmacy is null");
|
---|
[1454207] | 202 | }
|
---|
| 203 | //za json(Sys updateer)
|
---|
| 204 | public async Task UpdateWorker(HealthcareWorker worker)
|
---|
[5d02859] | 205 | {
|
---|
| 206 | if (worker != null)
|
---|
[1454207] | 207 | await _repository.UpdateWorker(worker);
|
---|
[d23bf72] | 208 | else throw new Exception("Worker is null");
|
---|
[5d02859] | 209 | }
|
---|
| 210 |
|
---|
[6f203af] | 211 | public async Task RemovePharmacyHead(int Id)
|
---|
[1454207] | 212 | {
|
---|
[6f203af] | 213 | if (Id > 0)
|
---|
[1454207] | 214 | {
|
---|
[6f203af] | 215 | await _repository.RemovePharmacyHead(Id);
|
---|
[1454207] | 216 | }
|
---|
[d23bf72] | 217 | else throw new Exception("Index out of bounds.");
|
---|
[1454207] | 218 | }
|
---|
| 219 |
|
---|
[d23bf72] | 220 | public HealthFacility GetFacilityJSON(string healthFacility)
|
---|
[1454207] | 221 | {
|
---|
| 222 | if (healthFacility != null)
|
---|
[d23bf72] | 223 | return _repository.GetFacilityJSON(healthFacility);
|
---|
[1454207] | 224 | return null;
|
---|
| 225 | }
|
---|
| 226 |
|
---|
[5d02859] | 227 | //PUT (EDIT OBJECTS)
|
---|
| 228 |
|
---|
| 229 |
|
---|
| 230 | //DELETE
|
---|
| 231 |
|
---|
| 232 | }
|
---|
| 233 | }
|
---|