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