Changeset 1454207


Ignore:
Timestamp:
10/01/20 03:17:09 (2 years ago)
Author:
DimitarSlezenkovski <dslezenkovski@…>
Branches:
master
Children:
6f203af
Parents:
5d02859
Message:

Change structure, Add repo, services & controllers

Files:
11 added
28 deleted
12 edited
2 moved

Legend:

Unmodified
Added
Removed
  • Farmatiko/ClientApp/src/app/admin/admin.component.ts

    r5d02859 r1454207  
    123123    this.dataService.updatePharmacyHead(req.PharmacyHead)
    124124        .subscribe(() => {
    125          
     125          this.rejectRequest(req);
    126126        },
    127127        (err: any) => console.log(err),
  • Farmatiko/Controllers/FarmatikoController.cs

    r5d02859 r1454207  
    2020        [HttpGet]
    2121        [Route("/api/workers")]
    22         public async Task<IQueryable<HealthcareWorkers>> GetWorkers()
     22        public async Task<IQueryable<HealthcareWorker>> GetWorkers()
    2323        {
    24             return await _service.GetAllWorkers();
     24            var Workers =  await _service.GetAllWorkers();
     25            return Workers;
    2526        }
    2627        [HttpGet]
    2728        [Route("/api/workers/search/{Query}")]
    28         public async Task<IQueryable<HealthcareWorkers>> SearchWorkers(string Query)
     29        public async Task<IQueryable<HealthcareWorker>> SearchWorkers(string Query)
    2930        {
    3031            return await _service.SearchWorkers(Query);
     
    3233        [HttpGet]
    3334        [Route("/api/workers/{id}")]
    34         public async Task<HealthcareWorkers> GetWorker(int Id)
     35        public async Task<HealthcareWorker> GetWorker(int Id)
    3536        {
    3637            return await _service.GetWorker(Id);
     
    4344        [HttpGet]
    4445        [Route("/api/facilities")]
    45         public async Task<IQueryable<HealthFacilities>> GetFacilities()
     46        public async Task<IQueryable<HealthFacility>> GetFacilities()
    4647        {
    4748            return await _service.GetFacilities();
     
    4950        [HttpGet]
    5051        [Route("/api/facilities/search/{Query}")]
    51         public async Task<IQueryable<HealthFacilities>> SearchFacilities(string Query)
     52        public async Task<IQueryable<HealthFacility>> SearchFacilities(string Query)
    5253        {
    5354            return await _service.SearchFacilities(Query);
     
    5556        [HttpGet]
    5657        [Route("/api/facilities/{Id}")]
    57         public async Task<HealthFacilities> GetFacility(int Id)
     58        public async Task<HealthFacility> GetFacility(int Id)
    5859        {
    5960            return await _service.GetFacility(Id);
  • Farmatiko/Controllers/PharmacyHeadController.cs

    r5d02859 r1454207  
    11using System.Linq;
     2using System.Threading.Tasks;
    23using FarmatikoData.FarmatikoRepoInterfaces;
    34using FarmatikoData.Models;
     5using FarmatikoServices.FarmatikoServiceInterfaces;
    46using Microsoft.AspNetCore.Mvc;
    57
     
    1012    public class PharmacyHeadController : Controller
    1113    {
    12         private readonly IPharmacyHeadRepository _pharmacyHeadRepository;
    13         public PharmacyHeadController(IPharmacyHeadRepository pharmacyHeadRepository)
     14        private readonly IPHService _PHService;
     15        public PharmacyHeadController(IPHService PHService)
    1416        {
    15             _pharmacyHeadRepository = pharmacyHeadRepository;
     17            _PHService = PHService;
    1618        }
     19       
     20        //GET
     21        //Mi trebaat rutite
    1722        [HttpGet]
    18         public IQueryable<PharmacyHead> GetAllPharmacies(string NameOfPharmacy)
     23        public async Task<IQueryable<PharmacyHead>> GetPharmacyHeadInfo(string Token)
    1924        {
    20             return _pharmacyHeadRepository.GetAllPharmacies(NameOfPharmacy);
     25            return await _PHService.GetPharmacyHeadInfo(Token);
    2126        }
    22         [HttpGet]
    23         public IQueryable<PharmacyHead> GetPharmacyByName(string Name)
     27        //POST
     28        [HttpPost]
     29        public async Task<int> Login(PharmacyHead pharmacyHead)
    2430        {
    25             return _pharmacyHeadRepository.GetPharmacyByName(Name);
    26         }
    27         [HttpGet]
    28         public IQueryable<MedicineList> GetPharmacyMedicines(string NameOfPharmacy)
    29         {
    30             return _pharmacyHeadRepository.GetPharmacyMedicines(NameOfPharmacy);
     31            return await _PHService.Login(pharmacyHead);
    3132        }
    3233        [HttpPost]
    33         public void Add(PharmacyHead pharmacyHead)
     34        public async Task UpdatePharmacyHead(PharmacyHead pharmacyHead)
    3435        {
    35             _pharmacyHeadRepository.Add(pharmacyHead);
     36            await _PHService.UpdatePharmacyHead(pharmacyHead);
    3637        }
    3738        [HttpPost]
    38         public void Remove(PharmacyHead pharmacyHead)
     39        public async Task<IActionResult> ClaimPharmacy(RequestPharmacyHead pharmacy)
    3940        {
    40             _pharmacyHeadRepository.Remove(pharmacyHead);
     41            await _PHService.ClaimPharmacy(pharmacy);
     42            return Ok();
    4143        }
     44       
    4245    }
    4346}
  • Farmatiko/appsettings.json

    r5d02859 r1454207  
    1010    }
    1111  },
     12  "EPPlus": {
     13    "ExcelPackage": {
     14      "LicenseContext": "NonCommercial"
     15    }
     16  },
    1217  "AllowedHosts": "*"
    1318}
  • FarmatikoData/FarmatikoDataContext.cs

    r5d02859 r1454207  
    99       
    1010
    11         public virtual DbSet<HealthFacilities> HealthFacilities { get; set; }
    12         public virtual DbSet<HealthcareWorkers> HealthcareWorkers { get; set; }
     11        public virtual DbSet<HealthFacility> HealthFacilities { get; set; }
     12        public virtual DbSet<HealthcareWorker> HealthcareWorkers { get; set; }
    1313        public virtual DbSet<Pharmacy> Pharmacies { get; set; }
    1414        public virtual DbSet<PharmacyHead> PharmacyHeads { get; set; }
     
    1616        public virtual DbSet<Medicine> Medicines { get; set; }
    1717        public virtual DbSet<MedicineList> MedicineLists { get; set; }
    18 
     18        public virtual DbSet<RequestPharmacyHead> PHRequests { get; set; }
    1919    }
    2020}
  • FarmatikoData/FarmatikoRepo/Repository.cs

    r5d02859 r1454207  
    1414        }
    1515        //GET
    16         public async Task<IQueryable<HealthcareWorkers>> GetAllWorkers()
     16        public async Task<IQueryable<HealthcareWorker>> GetAllWorkers()
    1717        {
    1818            var Workers = await Task.Run(() => _context.HealthcareWorkers.Take(10));
     
    2020        }
    2121
    22         public async Task<IQueryable<HealthFacilities>> GetFacilities()
     22        public async Task<IQueryable<HealthFacility>> GetFacilities()
    2323        {
    2424            var Facilities = await Task.Run(() => _context.HealthFacilities.Take(10));
     
    2626        }
    2727
    28         public async Task<HealthFacilities> GetFacility(int Id)
     28        public async Task<HealthFacility> GetFacility(int Id)
    2929        {
    3030            var Facility = await _context.HealthFacilities.FindAsync(Id);
     
    6262        }
    6363
    64         public async Task<HealthcareWorkers> GetWorker(int id)
     64        public async Task<HealthcareWorker> GetWorker(int id)
    6565        {
    6666            var Worker = await _context.HealthcareWorkers.FindAsync(id);
     
    6868        }
    6969
    70         public async Task<IQueryable<HealthFacilities>> SearchFacilities(string query)
     70        public async Task<IQueryable<HealthFacility>> SearchFacilities(string query)
    7171        {
    7272            var SearchQuery = await Task.Run(() => _context.HealthFacilities
     
    9595        }
    9696
    97         public async Task<IQueryable<HealthcareWorkers>> SearchWorkers(string query)
     97        public async Task<IQueryable<HealthcareWorker>> SearchWorkers(string query)
    9898        {
    9999            var SearchQuery = await Task.Run(() => _context.HealthcareWorkers
     
    103103            return SearchQuery;
    104104        }
     105        public async Task<HealthFacility> GetFacilityJSON(string healthFacility)
     106        {
     107            var Facility = await Task.Run(() => _context.HealthFacilities.Where(x => x.Name.Equals(healthFacility)).FirstOrDefault());
     108            return Facility;
     109        }
    105110
    106111        //POST
    107112
    108         public async Task AddWorker(HealthcareWorkers Worker)
     113        public async Task AddWorker(HealthcareWorker Worker)
    109114        {
    110115            await Task.Run(() => _context.HealthcareWorkers.Add(Worker));
     
    112117        }
    113118
    114         public async Task AddFacility(HealthFacilities healthFacility)
     119        public async Task AddFacility(HealthFacility healthFacility)
    115120        {
    116121            await Task.Run(() => _context.HealthFacilities.Add(healthFacility));
     
    141146            await _context.SaveChangesAsync();
    142147        }
     148
     149        public async Task UpdateFacility(HealthFacility healthFacility)
     150        {
     151            var Facility = await Task.Run(() => _context.HealthFacilities.Where(x => x.Id == healthFacility.Id).FirstOrDefault());
     152            Facility.Address = healthFacility.Address;
     153            Facility.Email = healthFacility.Email;
     154            Facility.Municipality = healthFacility.Municipality;
     155            Facility.Name = healthFacility.Name;
     156            Facility.Phone = healthFacility.Phone;
     157            Facility.Type = healthFacility.Type;
     158            await _context.SaveChangesAsync();
     159        }
     160
     161        public async Task RemoveMedicine(Medicine medicine)
     162        {
     163            await Task.Run(() => _context.Medicines.Remove(medicine));
     164            await _context.SaveChangesAsync();
     165        }
     166
     167        public async Task UpdatePandemic(Pandemic pandemic)
     168        {
     169            var Pandemic = await Task.Run(() => _context.Pandemics.Where(x => x.Id == pandemic.Id).FirstOrDefault());
     170            Pandemic.ActiveGlobal = pandemic.ActiveGlobal;
     171            Pandemic.ActiveMK = pandemic.ActiveMK;
     172            Pandemic.DeathsGlobal = pandemic.DeathsGlobal;
     173            Pandemic.DeathsMK = pandemic.DeathsMK;
     174            Pandemic.Name = pandemic.Name;
     175            Pandemic.NewMK = pandemic.NewMK;
     176            Pandemic.TotalGlobal = pandemic.TotalGlobal;
     177            Pandemic.TotalMK = pandemic.TotalMK;
     178            await _context.SaveChangesAsync();
     179        }
     180
     181        public async Task RemovePharmacy(Pharmacy pharmacy)
     182        {
     183            await Task.Run(() => _context.Pharmacies.Remove(pharmacy));
     184            await _context.SaveChangesAsync();
     185        }
     186        //ke vidime
     187        public Task UpdateWorker(HealthcareWorker worker)
     188        {
     189            throw new System.NotImplementedException();
     190        }
     191
     192        public async Task UpadatePharmacy(Pharmacy pharmacy)
     193        {
     194            var Pharmacy = await Task.Run(() => _context.Pharmacies.Where(x => x.Id == pharmacy.Id).FirstOrDefault());
     195            Pharmacy.Name = pharmacy.Name;
     196            Pharmacy.Location = pharmacy.Location;
     197            Pharmacy.WorkAllTime = pharmacy.WorkAllTime;
     198            Pharmacy.Address = pharmacy.Address;
     199            await _context.SaveChangesAsync();
     200        }
     201        //ke vidime
     202        public Task UpdateMedicine(Medicine medicine)
     203        {
     204            throw new System.NotImplementedException();
     205        }
     206
     207        public async Task RemovePharmacyHead(PharmacyHead pharmacyHead)
     208        {
     209            var PHead = await Task.Run(() => _context.PharmacyHeads.Where(x => x.Id == pharmacyHead.Id).FirstOrDefault());
     210            PHead.DeletedOn = pharmacyHead.DeletedOn;
     211            await _context.SaveChangesAsync();
     212        }
     213
    143214    }
    144215}
  • FarmatikoData/FarmatikoRepoInterfaces/IRepository.cs

    r5d02859 r1454207  
    11using FarmatikoData.Models;
     2using System;
     3using System.Collections.Generic;
    24using System.Linq;
     5using System.Text;
    36using System.Threading.Tasks;
    47
     
    811    {
    912        //GET
    10         Task<IQueryable<HealthcareWorkers>> GetAllWorkers();
    11         Task<IQueryable<HealthFacilities>> GetFacilities();
    12         Task<HealthFacilities> GetFacility(int Id);
     13        Task<IQueryable<HealthcareWorker>> GetAllWorkers();
     14        Task<IQueryable<HealthFacility>> GetFacilities();
     15        Task<HealthFacility> GetFacility(int Id);
    1316        Task<Medicine> GetMedicine(int Id);
    1417        Task<IQueryable<Medicine>> GetMedicines();
     
    1619        Task<IQueryable<Pharmacy>> GetPharmacies();
    1720        Task<Pharmacy> GetPharmacy(int id);
    18         Task<HealthcareWorkers> GetWorker(int id);
    19         Task<IQueryable<HealthFacilities>> SearchFacilities(string query);
     21        Task<HealthcareWorker> GetWorker(int id);
     22        Task<IQueryable<HealthFacility>> SearchFacilities(string query);
    2023        Task<IQueryable<Medicine>> SearchMedicines(string query);
    2124        Task<IQueryable<Pharmacy>> SearchPharmacies(string query);
    22         Task<IQueryable<HealthcareWorkers>> SearchWorkers(string query);
     25        Task<IQueryable<HealthcareWorker>> SearchWorkers(string query);
     26        Task<HealthFacility> GetFacilityJSON(string healthFacility);
     27
    2328        //POST
    24         Task AddWorker(HealthcareWorkers worker);
    25         Task AddFacility(HealthFacilities healthFacilities);
     29        Task AddWorker(HealthcareWorker Worker);
     30        Task AddFacility(HealthFacility healthFacility);
    2631        Task AddPharmacy(Pharmacy pharmacy);
    2732        Task AddPharmacyHead(PharmacyHead pharmacyHead);
    2833        Task AddMedicines(Medicine medicine);
    2934        Task AddPandemic(Pandemic pandemic);
     35        Task UpdateFacility(HealthFacility healthFacility);
     36        Task RemoveMedicine(Medicine medicine);
     37        Task UpdatePandemic(Pandemic pandemic);
     38        Task RemovePharmacy(Pharmacy pharmacy);
     39        Task UpdateWorker(HealthcareWorker worker);
     40        Task UpadatePharmacy(Pharmacy pharmacy);
     41        Task UpdateMedicine(Medicine medicine);
     42        Task RemovePharmacyHead(PharmacyHead pharmacyHead);
    3043    }
    3144}
  • FarmatikoData/Models/HealthFacility.cs

    r5d02859 r1454207  
    99namespace FarmatikoData.Models
    1010{
    11     public class HealthFacilities : BaseEntity
     11    public class HealthFacility : BaseEntity
    1212    {
    13         public HealthFacilities() { }
     13        public HealthFacility() { }
    1414        [Required]
    1515        public string Name { get; set; }
     
    2222        public string Email { get; set; }
    2323        public string Phone { get; set; }
    24         public HealthFacilities(string Name, string Municipality, string Address, string Type, string Email, string Phone)
     24        public HealthFacility(string Name, string Municipality, string Address, string Type, string Email, string Phone)
    2525        {
    2626            this.Name = Name;
  • FarmatikoData/Models/HealthcareWorker.cs

    r5d02859 r1454207  
    88namespace FarmatikoData.Models
    99{
    10     public class HealthcareWorkers : BaseEntity
     10    public class HealthcareWorker : BaseEntity
    1111    {
    12         public HealthcareWorkers() { }
     12        public HealthcareWorker() { }
    1313        [Required]
    1414        public string Name { get; set; }
     
    1616        public string Branch { get; set; }
    1717        [Required]
    18         public HealthFacilities Facility { get; set; }
     18        public HealthFacility Facility { get; set; }
    1919        public string Title { get; set; }
    20         public HealthcareWorkers(string Name, string Branch, HealthFacilities Facility, string Title)
     20        public HealthcareWorker(string Name, string Branch, HealthFacility Facility, string Title)
    2121        {
    2222            this.Name = Name;
  • FarmatikoData/Models/PharmacyHead.cs

    r5d02859 r1454207  
    1 using System;
    2 using System.Collections.Generic;
     1using System.Collections.Generic;
    32using System.ComponentModel.DataAnnotations;
    4 using System.Text;
    53using FarmatikoData.Base;
    6 using Microsoft.EntityFrameworkCore;
    74
    85namespace FarmatikoData.Models
  • FarmatikoServices/FarmatikoServiceInterfaces/IProcessJSONService.cs

    r5d02859 r1454207  
    99    public interface IProcessJSONService
    1010    {
    11         Task<HashSet<HealthFacilities>> GetProcessedHealthFacilitiesFromJSON();
    12         Task<HashSet<Pandemic>> GetProcessedPandemicsFromJSONApi();
    13         Task<HashSet<HealthcareWorkers>> GetProcessedHealthcareWorkersFromJSON();
    14         Task<HashSet<Medicine>> GetProcessedMedicinesFromJSON();
     11        Task<HealthFacility> GetProcessedHealthFacilitiesFromJSON();
     12        Task<Pandemic> GetProcessedPandemicsFromJSONApi();
     13        Task<HealthcareWorker> GetProcessedHealthcareWorkersFromJSON();
     14        Task<Medicine> GetProcessedMedicinesFromJSON();
     15        Task<Medicine> ReadPharmaciesFromExcel();
    1516    }
    1617}
  • FarmatikoServices/FarmatikoServiceInterfaces/IService.cs

    r5d02859 r1454207  
    88    {
    99        //GET
    10         Task<IQueryable<HealthcareWorkers>> GetAllWorkers();
    11         Task<IQueryable<HealthcareWorkers>> SearchWorkers(string query);
    12         Task<HealthcareWorkers> GetWorker(int id);
    13         Task<IQueryable<HealthFacilities>> GetFacilities();
    14         Task<IQueryable<HealthFacilities>> SearchFacilities(string query);
    15         Task<HealthFacilities> GetFacility(int id);
     10        Task<IQueryable<HealthcareWorker>> GetAllWorkers();
     11        Task<IQueryable<HealthcareWorker>> SearchWorkers(string query);
     12        Task<HealthcareWorker> GetWorker(int id);
     13        Task<IQueryable<HealthFacility>> GetFacilities();
     14        Task<IQueryable<HealthFacility>> SearchFacilities(string query);
     15        Task<HealthFacility> GetFacility(int id);
     16        Task<HealthFacility> GetFacilityJSON(string healthFacility);
    1617        Task<Medicine> GetMedicine(int id);
    1718        Task<IQueryable<Medicine>> SearchMedicines(string query);
     
    2223        Task<Pharmacy> GetPharmacy(int id);
    2324        //POST
    24         Task AddWorker(HealthcareWorkers worker);
    25         Task AddFacility(HealthFacilities healthFacilities);
     25        Task AddWorker(HealthcareWorker worker);
     26        Task AddFacility(HealthFacility healthFacilities);
    2627        Task AddPharmacy(Pharmacy pharmacy);
    2728        Task AddPharmacyHead(PharmacyHead pharmacyHead);
    2829        Task AddMedicines(Medicine medicine);
    2930        Task AddPandemic(Pandemic pandemic);
     31        Task UpdateFacility(HealthFacility healthFacilities);
     32        Task RemoveMedicine(Medicine medicine);
     33        Task RemovePharmacyHead(PharmacyHead pharmacyHead);
     34        Task UpdatePandemic(Pandemic pandemic);
     35        Task RemovePharmacy(Pharmacy pharmacy);
     36        Task UpdateWorker(HealthcareWorker worker);
     37        Task UpdatePharmacy(Pharmacy pharmacy);
    3038    }
    3139}
  • FarmatikoServices/Services/ProcessJSONService.cs

    r5d02859 r1454207  
    1111using RestSharp;
    1212using System.Threading.Tasks;
     13using OfficeOpenXml;
     14using System.IO;
    1315
    1416namespace FarmatikoServices.Services
     
    1618    public class ProcessJSONService : IProcessJSONService
    1719    {
    18         private IHealthFacilityRepository _healthFacilityRepository;
    19         private IPandemicRepository _pandemicRepository;
    20         private IHealthcareWorkerRepository _healthcareWorkerRepository;
    21         private IMedicineRepository _medicineRepository;
     20
    2221        private readonly ILogger _logger;
    23         public ProcessJSONService(IHealthFacilityRepository healthFacilityRepository, IPandemicRepository pandemicRepository,
    24             IHealthcareWorkerRepository healthcareWorkerRepository, IMedicineRepository medicineRepository, ILogger logger)
     22        private readonly IService _service;
     23        public ProcessJSONService(ILogger logger, IService service)
    2524        {
    2625            _logger = logger;
    27             _healthFacilityRepository = healthFacilityRepository;
    28             _pandemicRepository = pandemicRepository;
    29             _healthcareWorkerRepository = healthcareWorkerRepository;
    30             _medicineRepository = medicineRepository;
     26            _service = service;
    3127        }
    3228
    33         public async Task<HashSet<HealthFacilities>> GetProcessedHealthFacilitiesFromJSON()
     29        public async Task<Medicine> ReadPharmaciesFromExcel()
     30        {
     31            var client = new WebClient();
     32            string Path = client.DownloadString(@"C:\Users\dslez\Desktop\apteki-fzo.xlsx");
     33            using (var package = new ExcelPackage(new FileInfo(Path)))
     34            {
     35                var Sheet = package.Workbook.Worksheets[1];
     36                for (int i = 2; i < Sheet.Dimension.End.Row; ++i)
     37                {
     38                    Pharmacy pharmacy = new Pharmacy()
     39                    {
     40                        Name = Sheet.Cells[i, 2].Value.ToString(),
     41                        Address = Sheet.Cells[i, 3].Value.ToString(),
     42                        Location = Sheet.Cells[i, 4].Value.ToString(),
     43                        WorkAllTime = false
     44                    };
     45                    await _service.AddPharmacy(pharmacy);
     46                }
     47            }
     48            return null;
     49        }
     50
     51
     52        public async Task<HealthFacility> GetProcessedHealthFacilitiesFromJSON()
    3453        {
    3554            try
    3655            {
    37                 HashSet<HealthFacilities> hashSet = new HashSet<HealthFacilities>();
    3856                var client = new WebClient();
    3957                var json = client.DownloadString(@"C:\Users\dslez\Desktop\ustanovi.json");
     
    5169                    var Phone = obj[11];
    5270                    var Type = obj[5];
    53                     HealthFacilities healthFacility = new HealthFacilities(Name, Municipality, Address, Type, Email, Phone);
    54                     /*healthFacility.Name = Name;
    55                     healthFacility.Municipality = Municipality;
    56                     healthFacility.Address = Address;
    57                     healthFacility.Email = Email;
    58                     healthFacility.Phone = Phone;
    59                     healthFacility.Type = Type;*/
    60                     //hashSet.Add(healthFacility);
    61                     await Task.Run(() => _healthFacilityRepository.Add(healthFacility));
     71                    HealthFacility healthFacility = new HealthFacility(Name, Municipality, Address, Type, Email, Phone);
     72                    await Task.Run(() => _service.AddFacility(healthFacility));
    6273
    6374                }
     
    7283        }
    7384
    74         public async Task<HashSet<Pandemic>> GetProcessedPandemicsFromJSONApi()
     85        public async Task<Pandemic> GetProcessedPandemicsFromJSONApi()
    7586        {
    7687            try
     
    97108
    98109                Pandemic pandemic = new Pandemic(Name, TotalMk, ActiveMk, TotalDeathsMK, NewMK, TotalConfirmed, TotalDeaths, ActiveGlobal);
    99                 /*pandemic.TotalGlobal = TotalConfirmed;
    100                 pandemic.ActiveGlobal = TotalConfirmed - (TotalRecovered + TotalDeaths);
    101                 pandemic.DeathsGlobal = TotalDeaths;
    102                 pandemic.TotalMK = TotalMk;
    103                 pandemic.ActiveMK = TotalMk - (TotalRecoveredMK + TotalDeathsMK);
    104                 pandemic.DeathsMK = TotalDeathsMK;
    105                 pandemic.NewMK = NewMK;
    106                 pandemic.Name = "Coronavirus";*/
    107                 await Task.Run(() => _pandemicRepository.Add(pandemic));
     110                await Task.Run(() => _service.AddPandemic(pandemic));
    108111            }
    109112            catch (Exception e)
     
    114117        }
    115118
    116         public async Task<HashSet<HealthcareWorkers>> GetProcessedHealthcareWorkersFromJSON()
     119        public async Task<HealthcareWorker> GetProcessedHealthcareWorkersFromJSON()
    117120        {
    118121            try
     
    131134                    var FacilityName = obj[1];
    132135                    var Title = obj[3];
    133                     HealthFacilities facility = _healthFacilityRepository.GetByName(FacilityName);
    134                     HealthFacilities Facility = new HealthFacilities(facility.Name, facility.Municipality, facility.Address,
     136                    HealthFacility facility = await _service.GetFacilityJSON(FacilityName);
     137                    HealthFacility Facility = new HealthFacility(facility.Name, facility.Municipality, facility.Address,
    135138                                                                        facility.Type, facility.Email, facility.Phone);
    136                     HealthcareWorkers healthcareWorker = new HealthcareWorkers(Name, Branch, Facility, Title);
     139                    HealthcareWorker healthcareWorker = new HealthcareWorker(Name, Branch, Facility, Title);
    137140                    /*Facility.Name = obj[1];
    138141                    Facility.Municipality = "WorkerFacilityMunicipality";
     
    142145                    healthcareWorker.Facility = Facility;
    143146                    healthcareWorker.Title = Title;*/
    144                     await Task.Run(() => _healthcareWorkerRepository.Add(healthcareWorker));
     147                    await Task.Run(() => _service.AddWorker(healthcareWorker));
    145148                }
    146149            }
     
    152155        }
    153156
    154         public async Task<HashSet<Medicine>> GetProcessedMedicinesFromJSON()
     157        public async Task<Medicine> GetProcessedMedicinesFromJSON()
    155158        {
    156159            try
     
    180183                    medicine.Price = Price;
    181184                    medicine.Packaging = Packaging;*/
    182                     await Task.Run(() => _medicineRepository.Add(medicine));
     185                    await Task.Run(() => _service.AddMedicines(medicine));
    183186                }
    184187            }
  • FarmatikoServices/Services/Service.cs

    r5d02859 r1454207  
    1717
    1818        //GET
    19         public async Task<IQueryable<HealthcareWorkers>> GetAllWorkers()
     19        public async Task<IQueryable<HealthcareWorker>> GetAllWorkers()
    2020        {
    2121            var Workers = await _repository.GetAllWorkers();
     
    2323        }
    2424
    25         public async Task<IQueryable<HealthFacilities>> GetFacilities()
     25        public async Task<IQueryable<HealthFacility>> GetFacilities()
    2626        {
    2727            var Facilities = await _repository.GetFacilities();
     
    2929        }
    3030
    31         public async Task<HealthFacilities> GetFacility(int id)
     31        public async Task<HealthFacility> GetFacility(int id)
    3232        {
    3333            var Facility = await _repository.GetFacility(id);
     
    6565        }
    6666
    67         public async Task<HealthcareWorkers> GetWorker(int id)
     67        public async Task<HealthcareWorker> GetWorker(int id)
    6868        {
    6969            var Worker = await _repository.GetWorker(id);
     
    7171        }
    7272
    73         public async Task<IQueryable<HealthFacilities>> SearchFacilities(string query)
     73        public async Task<IQueryable<HealthFacility>> SearchFacilities(string query)
    7474        {
    7575            var SearchQuery = await _repository.SearchFacilities(query);
     
    8989        }
    9090
    91         public async Task<IQueryable<HealthcareWorkers>> SearchWorkers(string query)
     91        public async Task<IQueryable<HealthcareWorker>> SearchWorkers(string query)
    9292        {
    9393            var SearchQuery = await _repository.SearchWorkers(query);
     
    9797
    9898        //POST (ADD NEW OBJECTS)
    99         public Task AddFacility(HealthFacilities healthFacilities)
     99        //za json(Sys updateer)
     100        public async Task AddFacility(HealthFacility healthFacilities)
    100101        {
    101102            if (healthFacilities != null)
    102                 _repository.AddFacility(healthFacilities);
     103                await _repository.AddFacility(healthFacilities);
    103104            throw new Exception("Facility is null");
    104105        }
    105 
    106         public Task AddMedicines(Medicine medicine)
     106        //za json(Sys updateer)
     107        public async Task AddMedicines(Medicine medicine)
    107108        {
    108109            if (medicine != null)
    109                 _repository.AddMedicines(medicine);
     110                await _repository.AddMedicines(medicine);
    110111            throw new Exception("Medicine is null");
    111112        }
    112 
    113         public Task AddPandemic(Pandemic pandemic)
     113        //za json(Sys updateer)
     114        public async Task AddPandemic(Pandemic pandemic)
    114115        {
    115116            if (pandemic != null)
    116                 _repository.AddPandemic(pandemic);
     117                await _repository.AddPandemic(pandemic);
    117118            throw new Exception("Pandemic is null");
    118119        }
    119 
    120         public Task AddPharmacy(Pharmacy pharmacy)
     120        // Samo PharmacyHead i Admin imaat pristap
     121        public async Task AddPharmacy(Pharmacy pharmacy)
    121122        {
    122123            if (pharmacy != null)
    123                 _repository.AddPharmacy(pharmacy);
     124                await _repository.AddPharmacy(pharmacy);
    124125            throw new Exception("Pharmacy is null");
    125126        }
    126 
    127         public Task AddPharmacyHead(PharmacyHead pharmacyHead)
     127        // Ovaa kontrola ja ima samo admin
     128        public async Task AddPharmacyHead(PharmacyHead pharmacyHead)
    128129        {
    129130            if (pharmacyHead != null)
    130                 _repository.AddPharmacyHead(pharmacyHead);
     131            {
     132                var Medicines = await _repository.GetMedicines();
     133                foreach (var med in Medicines)
     134                {
     135                    MedicineList medicine = new MedicineList()
     136                    {
     137                        Medicine = med,
     138                        HasMedicine = false
     139                    };
     140                    pharmacyHead.MedicineLists.Add(medicine);
     141                }
     142                await _repository.AddPharmacyHead(pharmacyHead);
     143            }
    131144            throw new Exception("PharmacyHead is null");
    132145        }
    133 
    134         public Task AddWorker(HealthcareWorkers worker)
     146        //za json(Sys updateer)
     147        public async Task AddWorker(HealthcareWorker worker)
    135148        {
    136149            if (worker != null)
    137                 _repository.AddWorker(worker);
     150                await _repository.AddWorker(worker);
    138151            throw new Exception("Worker is null");
     152        }
     153
     154        //za json(Sys updateer)
     155        public async Task UpdateFacility(HealthFacility healthFacilities)
     156        {
     157            if (healthFacilities != null)
     158                await _repository.UpdateFacility(healthFacilities);
     159            throw new Exception("Facility is null");
     160        }
     161        //PharmacyHead
     162        public async Task RemoveMedicine(Medicine medicine)
     163        {
     164            if (medicine != null)
     165                await _repository.RemoveMedicine(medicine);
     166            throw new Exception("Medicine is null");
     167        }
     168        //PharmacyHead
     169        public async Task UpdateMedicine(Medicine medicine)
     170        {
     171            if (medicine != null)
     172                await _repository.UpdateMedicine(medicine);
     173            throw new Exception("Medicine is null");
     174        }
     175        //za json(Sys updateer)
     176        public async Task UpdatePandemic(Pandemic pandemic)
     177        {
     178            if (pandemic != null)
     179                await _repository.UpdatePandemic(pandemic);
     180            throw new Exception("Pandemic is null");
     181        }
     182        //PharmacyHead
     183        public async Task RemovePharmacy(Pharmacy pharmacy)
     184        {
     185            if (pharmacy != null)
     186                await _repository.RemovePharmacy(pharmacy);
     187            throw new Exception("Pharmacy is null");
     188        }
     189        //PharamcyHead
     190        public async Task UpdatePharmacy(Pharmacy pharmacy)
     191        {
     192            if (pharmacy != null)
     193                await _repository.UpadatePharmacy(pharmacy);
     194            throw new Exception("Pharmacy is null");
     195        }
     196        //za json(Sys updateer)
     197        public async Task UpdateWorker(HealthcareWorker worker)
     198        {
     199            if (worker != null)
     200                await _repository.UpdateWorker(worker);
     201            throw new Exception("Worker is null");
     202        }
     203
     204        public async Task RemovePharmacyHead(PharmacyHead pharmacyHead)
     205        {
     206            if (pharmacyHead != null)
     207            {
     208                pharmacyHead.DeletedOn = DateTime.UtcNow;
     209                await _repository.RemovePharmacyHead(pharmacyHead);
     210            }
     211            else throw new Exception("PharmacyHead is null.");
     212        }
     213
     214        public async Task<HealthFacility> GetFacilityJSON(string healthFacility)
     215        {
     216            if (healthFacility != null)
     217                return await _repository.GetFacilityJSON(healthFacility);
     218            return null;
    139219        }
    140220
Note: See TracChangeset for help on using the changeset viewer.