[5d02859] | 1 | using FarmatikoData.FarmatikoRepoInterfaces;
|
---|
| 2 | using FarmatikoData.Models;
|
---|
[6f203af] | 3 | using Microsoft.EntityFrameworkCore;
|
---|
| 4 | using System;
|
---|
| 5 | using System.Collections.Generic;
|
---|
[5d02859] | 6 | using System.Linq;
|
---|
| 7 | using System.Threading.Tasks;
|
---|
| 8 |
|
---|
| 9 | namespace FarmatikoData.FarmatikoRepo
|
---|
| 10 | {
|
---|
| 11 | public class Repository : IRepository
|
---|
| 12 | {
|
---|
| 13 | private readonly FarmatikoDataContext _context;
|
---|
| 14 | public Repository(FarmatikoDataContext context)
|
---|
| 15 | {
|
---|
| 16 | _context = context;
|
---|
| 17 | }
|
---|
| 18 | //GET
|
---|
[6f203af] | 19 | public async Task<IEnumerable<HealthcareWorker>> GetAllWorkers()
|
---|
[5d02859] | 20 | {
|
---|
| 21 | var Workers = await Task.Run(() => _context.HealthcareWorkers.Take(10));
|
---|
| 22 | return Workers;
|
---|
| 23 | }
|
---|
| 24 |
|
---|
[6f203af] | 25 | public async Task<IEnumerable<HealthFacility>> GetFacilities()
|
---|
[5d02859] | 26 | {
|
---|
| 27 | var Facilities = await Task.Run(() => _context.HealthFacilities.Take(10));
|
---|
| 28 | return Facilities;
|
---|
| 29 | }
|
---|
| 30 |
|
---|
[1454207] | 31 | public async Task<HealthFacility> GetFacility(int Id)
|
---|
[5d02859] | 32 | {
|
---|
| 33 | var Facility = await _context.HealthFacilities.FindAsync(Id);
|
---|
| 34 | return Facility;
|
---|
| 35 | }
|
---|
| 36 |
|
---|
| 37 | public async Task<Medicine> GetMedicine(int Id)
|
---|
| 38 | {
|
---|
| 39 | var Medicine = await _context.Medicines.FindAsync(Id);
|
---|
| 40 | return Medicine;
|
---|
| 41 | }
|
---|
| 42 |
|
---|
[6f203af] | 43 | public async Task<IEnumerable<Medicine>> GetMedicines()
|
---|
[5d02859] | 44 | {
|
---|
| 45 | var Medicines = await Task.Run(() => _context.Medicines.Take(10));
|
---|
| 46 | return Medicines;
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | public async Task<Pandemic> GetPandemic()
|
---|
| 50 | {
|
---|
| 51 | var Pandemic = await Task.Run(() => _context.Pandemics.FirstOrDefault());
|
---|
| 52 | return Pandemic;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
[6f203af] | 55 | public async Task<IEnumerable<Pharmacy>> GetPharmacies()
|
---|
[5d02859] | 56 | {
|
---|
| 57 | var Pharmacies = await Task.Run(() => _context.Pharmacies.Take(10));
|
---|
| 58 | return Pharmacies;
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | public async Task<Pharmacy> GetPharmacy(int id)
|
---|
| 62 | {
|
---|
| 63 | var Pharmacy = await _context.Pharmacies.FindAsync(id);
|
---|
| 64 | return Pharmacy;
|
---|
| 65 | }
|
---|
| 66 |
|
---|
[1454207] | 67 | public async Task<HealthcareWorker> GetWorker(int id)
|
---|
[5d02859] | 68 | {
|
---|
| 69 | var Worker = await _context.HealthcareWorkers.FindAsync(id);
|
---|
| 70 | return Worker;
|
---|
| 71 | }
|
---|
| 72 |
|
---|
[6f203af] | 73 | public async Task<IEnumerable<HealthFacility>> SearchFacilities(string query)
|
---|
[5d02859] | 74 | {
|
---|
| 75 | var SearchQuery = await Task.Run(() => _context.HealthFacilities
|
---|
| 76 | .Where(x => x.Name.Equals(query))
|
---|
| 77 | .OrderBy(x => x.Name));
|
---|
| 78 |
|
---|
| 79 | return SearchQuery;
|
---|
| 80 | }
|
---|
| 81 |
|
---|
[6f203af] | 82 | public async Task<IEnumerable<Medicine>> SearchMedicines(string query)
|
---|
[5d02859] | 83 | {
|
---|
| 84 | var SearchQuery = await Task.Run(() => _context.Medicines
|
---|
| 85 | .Where(x => x.Name.Equals(query))
|
---|
| 86 | .OrderBy(x => x.Name));
|
---|
| 87 |
|
---|
| 88 | return SearchQuery;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
[6f203af] | 91 | public async Task<IEnumerable<Pharmacy>> SearchPharmacies(string query)
|
---|
[5d02859] | 92 | {
|
---|
| 93 | var SearchQuery = await Task.Run(() => _context.Pharmacies
|
---|
| 94 | .Where(x => x.Name.Equals(query))
|
---|
| 95 | .OrderBy(x => x.Name));
|
---|
| 96 |
|
---|
| 97 | return SearchQuery;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
[6f203af] | 100 | public async Task<IEnumerable<HealthcareWorker>> SearchWorkers(string query)
|
---|
[5d02859] | 101 | {
|
---|
| 102 | var SearchQuery = await Task.Run(() => _context.HealthcareWorkers
|
---|
| 103 | .Where(x => x.Name.Equals(query))
|
---|
| 104 | .OrderBy(x => x.Name));
|
---|
| 105 |
|
---|
| 106 | return SearchQuery;
|
---|
| 107 | }
|
---|
[1454207] | 108 | public async Task<HealthFacility> GetFacilityJSON(string healthFacility)
|
---|
| 109 | {
|
---|
| 110 | var Facility = await Task.Run(() => _context.HealthFacilities.Where(x => x.Name.Equals(healthFacility)).FirstOrDefault());
|
---|
| 111 | return Facility;
|
---|
| 112 | }
|
---|
[5d02859] | 113 |
|
---|
| 114 | //POST
|
---|
| 115 |
|
---|
[1454207] | 116 | public async Task AddWorker(HealthcareWorker Worker)
|
---|
[5d02859] | 117 | {
|
---|
| 118 | await Task.Run(() => _context.HealthcareWorkers.Add(Worker));
|
---|
| 119 | await _context.SaveChangesAsync();
|
---|
| 120 | }
|
---|
| 121 |
|
---|
[1454207] | 122 | public async Task AddFacility(HealthFacility healthFacility)
|
---|
[5d02859] | 123 | {
|
---|
| 124 | await Task.Run(() => _context.HealthFacilities.Add(healthFacility));
|
---|
| 125 | await _context.SaveChangesAsync();
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 | public async Task AddPharmacy(Pharmacy pharmacy)
|
---|
| 129 | {
|
---|
| 130 | await Task.Run(() => _context.Pharmacies.Add(pharmacy));
|
---|
| 131 | await _context.SaveChangesAsync();
|
---|
| 132 | }
|
---|
| 133 |
|
---|
| 134 | public async Task AddPharmacyHead(PharmacyHead pharmacyHead)
|
---|
| 135 | {
|
---|
| 136 | await Task.Run(() => _context.PharmacyHeads.Add(pharmacyHead));
|
---|
| 137 | await _context.SaveChangesAsync();
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | public async Task AddMedicines(Medicine medicine)
|
---|
| 141 | {
|
---|
| 142 | await Task.Run(() => _context.Medicines.Add(medicine));
|
---|
| 143 | await _context.SaveChangesAsync();
|
---|
| 144 | }
|
---|
| 145 |
|
---|
| 146 | public async Task AddPandemic(Pandemic pandemic)
|
---|
| 147 | {
|
---|
| 148 | await Task.Run(() => _context.Pandemics.Add(pandemic));
|
---|
| 149 | await _context.SaveChangesAsync();
|
---|
| 150 | }
|
---|
[1454207] | 151 |
|
---|
| 152 | public async Task UpdateFacility(HealthFacility healthFacility)
|
---|
| 153 | {
|
---|
| 154 | var Facility = await Task.Run(() => _context.HealthFacilities.Where(x => x.Id == healthFacility.Id).FirstOrDefault());
|
---|
| 155 | Facility.Address = healthFacility.Address;
|
---|
| 156 | Facility.Email = healthFacility.Email;
|
---|
| 157 | Facility.Municipality = healthFacility.Municipality;
|
---|
| 158 | Facility.Name = healthFacility.Name;
|
---|
| 159 | Facility.Phone = healthFacility.Phone;
|
---|
| 160 | Facility.Type = healthFacility.Type;
|
---|
| 161 | await _context.SaveChangesAsync();
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | public async Task RemoveMedicine(Medicine medicine)
|
---|
| 165 | {
|
---|
| 166 | await Task.Run(() => _context.Medicines.Remove(medicine));
|
---|
| 167 | await _context.SaveChangesAsync();
|
---|
| 168 | }
|
---|
| 169 |
|
---|
| 170 | public async Task UpdatePandemic(Pandemic pandemic)
|
---|
| 171 | {
|
---|
| 172 | var Pandemic = await Task.Run(() => _context.Pandemics.Where(x => x.Id == pandemic.Id).FirstOrDefault());
|
---|
| 173 | Pandemic.ActiveGlobal = pandemic.ActiveGlobal;
|
---|
| 174 | Pandemic.ActiveMK = pandemic.ActiveMK;
|
---|
| 175 | Pandemic.DeathsGlobal = pandemic.DeathsGlobal;
|
---|
| 176 | Pandemic.DeathsMK = pandemic.DeathsMK;
|
---|
| 177 | Pandemic.Name = pandemic.Name;
|
---|
| 178 | Pandemic.NewMK = pandemic.NewMK;
|
---|
| 179 | Pandemic.TotalGlobal = pandemic.TotalGlobal;
|
---|
| 180 | Pandemic.TotalMK = pandemic.TotalMK;
|
---|
| 181 | await _context.SaveChangesAsync();
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | public async Task RemovePharmacy(Pharmacy pharmacy)
|
---|
| 185 | {
|
---|
| 186 | await Task.Run(() => _context.Pharmacies.Remove(pharmacy));
|
---|
| 187 | await _context.SaveChangesAsync();
|
---|
| 188 | }
|
---|
[6f203af] | 189 | //not impl
|
---|
[1454207] | 190 | public Task UpdateWorker(HealthcareWorker worker)
|
---|
| 191 | {
|
---|
| 192 | throw new System.NotImplementedException();
|
---|
| 193 | }
|
---|
| 194 |
|
---|
| 195 | public async Task UpadatePharmacy(Pharmacy pharmacy)
|
---|
| 196 | {
|
---|
| 197 | var Pharmacy = await Task.Run(() => _context.Pharmacies.Where(x => x.Id == pharmacy.Id).FirstOrDefault());
|
---|
| 198 | Pharmacy.Name = pharmacy.Name;
|
---|
| 199 | Pharmacy.Location = pharmacy.Location;
|
---|
| 200 | Pharmacy.WorkAllTime = pharmacy.WorkAllTime;
|
---|
| 201 | Pharmacy.Address = pharmacy.Address;
|
---|
| 202 | await _context.SaveChangesAsync();
|
---|
| 203 | }
|
---|
| 204 | //ke vidime
|
---|
| 205 | public Task UpdateMedicine(Medicine medicine)
|
---|
| 206 | {
|
---|
| 207 | throw new System.NotImplementedException();
|
---|
| 208 | }
|
---|
| 209 |
|
---|
[6f203af] | 210 | public async Task RemovePharmacyHead(int Id)
|
---|
[1454207] | 211 | {
|
---|
[6f203af] | 212 | var PHead = await _context.PharmacyHeads.Where(x => x.Id == Id).FirstOrDefaultAsync();
|
---|
| 213 | PHead.DeletedOn = DateTime.UtcNow;
|
---|
[1454207] | 214 | await _context.SaveChangesAsync();
|
---|
| 215 | }
|
---|
| 216 |
|
---|
[5d02859] | 217 | }
|
---|
| 218 | }
|
---|