Changeset 63d885e for FarmatikoServices


Ignore:
Timestamp:
08/07/20 11:01:25 (4 years ago)
Author:
Mile Jankuloski <mile.jankuloski@…>
Branches:
master
Children:
5d02859
Parents:
ee137aa (diff), c406ae5 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of https://develop.finki.ukim.mk/git/farmatiko

Location:
FarmatikoServices
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • FarmatikoServices/FarmatikoServiceInterfaces/IHealthFacilityService.cs

    ree137aa r63d885e  
    11using FarmatikoData.Models;
    22using System.Linq;
     3using System.Threading.Tasks;
    34
    45namespace FarmatikoData
     
    67    public interface IHealthFacilityService
    78    {
    8         IQueryable<HealthFacilities> GetAll();
     9        Task<IQueryable<HealthFacilities>> GetAll();
    910        void Add(HealthFacilities healthFacility);
    1011        void Remove(HealthFacilities healthFacility);
  • FarmatikoServices/FarmatikoServiceInterfaces/IHealthcareWorkerService.cs

    ree137aa r63d885e  
    11using FarmatikoData.Models;
    22using System.Linq;
     3using System.Threading.Tasks;
    34
    45namespace FarmatikoServices.FarmatikoServiceInterfaces
     
    67    public interface IHealthcareWorkerService
    78    {
    8         IQueryable<HealthcareWorkers> GetAll();
     9        Task<IQueryable<HealthcareWorkers>> GetAll();
    910        void Add(HealthcareWorkers healthcareWorker);
    1011        void Remove(HealthcareWorkers healthcareWorker);
  • FarmatikoServices/FarmatikoServiceInterfaces/IMedicineListService.cs

    ree137aa r63d885e  
    22using System.Collections.Generic;
    33using System.Linq;
     4using System.Threading.Tasks;
    45
    56namespace FarmatikoServices.FarmatikoServiceInterfaces
     
    78    public interface IMedicineListService
    89    {
    9         IQueryable<MedicineList> GetAll();
     10        Task<IQueryable<MedicineList>> GetAll();
    1011        //SetHasMedicine(MedicineList medicineList, bool HasMedicine);
    11         ICollection<MedicineList> GetByName(string Name);
    12         ICollection<MedicineList> GetByManufacturer(string Manufacturer);
     12        Task<ICollection<MedicineList>> GetByName(string Name);
     13        Task<ICollection<MedicineList>> GetByManufacturer(string Manufacturer);
    1314        void Add(MedicineList medicineList);
    1415        void Remove(MedicineList medicineList);
  • FarmatikoServices/FarmatikoServiceInterfaces/IMedicineService.cs

    ree137aa r63d885e  
    11using FarmatikoData.Models;
    22using System.Linq;
     3using System.Threading.Tasks;
    34
    45namespace FarmatikoServices.FarmatikoServiceInterfaces
     
    67    public interface IMedicineService
    78    {
    8         IQueryable<Medicine> GetAll();
     9        Task<IQueryable<Medicine>> GetAll();
    910        void Add(Medicine medicine);
    10         void Remove(string Medicine);
    11         IQueryable<Medicine> GetByName(string Name);
    12         IQueryable<Medicine> GetByManufacturer(string Manufacturer);
     11        void Remove(Medicine Medicine);
     12        Task<IQueryable<Medicine>> GetByName(string Name);
     13        Task<IQueryable<Medicine>> GetByManufacturer(string Manufacturer);
    1314    }
    1415}
  • FarmatikoServices/FarmatikoServiceInterfaces/IPandemicService.cs

    ree137aa r63d885e  
    11using FarmatikoData.Models;
    22using System.Linq;
     3using System.Threading.Tasks;
    34
    45namespace FarmatikoServices.FarmatikoServiceInterfaces
     
    78    {
    89        void Add(Pandemic pandemic);
    9         IQueryable<Pandemic> GetAll();
     10        Task<IQueryable<Pandemic>> GetAll();
    1011        void Remove(Pandemic pandemic);
    1112    }
  • FarmatikoServices/FarmatikoServiceInterfaces/IPharmacyHeadService.cs

    ree137aa r63d885e  
    11using FarmatikoData.Models;
    22using System.Linq;
     3using System.Threading.Tasks;
    34
    45namespace FarmatikoServices.FarmatikoServiceInterfaces
     
    78    {
    89        void Add(PharmacyHead pharmacyHead);
    9         void Remove(PharmacyHead pharmacyHead, string Name);
    10         IQueryable<PharmacyHead> GetAllPharmacies(string NameOfPharmacyHead);
     10        void Remove(PharmacyHead pharmacyHead);
     11        Task<IQueryable<PharmacyHead>> GetAllPharmacies(string NameOfPharmacyHead);
    1112        //Not actually needed
    12         IQueryable<PharmacyHead> GetPharmacyByName(string Name);
    13         IQueryable<MedicineList> GetPharmacyMedicines(string NameOfPharmacy);
     13        Task<IQueryable<PharmacyHead>> GetPharmacyByName(string Name);
     14        Task<IQueryable<MedicineList>> GetPharmacyMedicines(string NameOfPharmacy);
    1415    }
    1516}
  • FarmatikoServices/FarmatikoServiceInterfaces/IPharmacyService.cs

    ree137aa r63d885e  
    22using System.Collections.Generic;
    33using System.Linq;
     4using System.Threading.Tasks;
    45
    56namespace FarmatikoServices.FarmatikoServiceInterfaces
     
    89    {
    910        void Add(Pharmacy pharmacy);
    10         ICollection<Pharmacy> GetPharmacies();
    11         IQueryable<Pharmacy> GetAll();
     11        Task<ICollection<Pharmacy>> GetPharmacies();
     12        Task<IQueryable<Pharmacy>> GetAll();
    1213        void Remove(Pharmacy pharmacy);
    13         void UpdatePharmacy(Pharmacy pharmacy, string Name);
     14        void UpdatePharmacy(Pharmacy pharmacy);
    1415    }
    1516}
  • FarmatikoServices/FarmatikoServiceInterfaces/IProcessJSONService.cs

    ree137aa r63d885e  
    33using System.Collections.Generic;
    44using System.Text;
     5using System.Threading.Tasks;
    56
    67namespace FarmatikoServices.FarmatikoServiceInterfaces
     
    89    public interface IProcessJSONService
    910    {
    10         List<HealthFacilities> GetProcessedHealthFacilitiesFromJSON();
     11        Task<HashSet<HealthFacilities>> GetProcessedHealthFacilitiesFromJSON();
     12        Task<HashSet<Pandemic>> GetProcessedPandemicsFromJSONApi();
     13        Task<HashSet<HealthcareWorkers>> GetProcessedHealthcareWorkersFromJSON();
     14        Task<HashSet<Medicine>> GetProcessedMedicinesFromJSON();
    1115    }
    1216}
  • FarmatikoServices/Services/HealthFacilityService.cs

    ree137aa r63d885e  
    44using System;
    55using System.Linq;
     6using System.Threading.Tasks;
    67
    78namespace FarmatikoServices
     
    1617        }
    1718
    18         public void Add(HealthFacilities healthFacility)
     19        public async void Add(HealthFacilities healthFacility)
    1920        {
    20             try
    21             {
    22                 if (healthFacility != null)
    23                     _healthFacilityRepository.Add(healthFacility);
    24             }
    25             catch (Exception e)
    26             {
    27                 e = new Exception("Can't Add health facility is null");
    28                 throw e;
    29             }
     21            if (healthFacility != null)
     22                await Task.Run(() => _healthFacilityRepository.Add(healthFacility));
     23            else throw new Exception("Can't add, health facility is null");
    3024        }
    3125
    32         public IQueryable<HealthFacilities> GetAll()
     26        public async Task<IQueryable<HealthFacilities>> GetAll()
    3327        {
    34             return _healthFacilityRepository.GetAll();
     28            return await Task.Run(() => _healthFacilityRepository.GetAll());
    3529        }
    3630
    37         public void Remove(HealthFacilities healthFacility)
     31        public async void Remove(HealthFacilities healthFacility)
    3832        {
    39             try
    40             {
    41                 if (healthFacility != null)
    42                     _healthFacilityRepository.Remove(healthFacility);
    43             }
    44             catch(Exception e)
    45             {
    46                 e = new Exception("Can't Remove health facility is null");
    47                 throw e;
    48             }
     33            if (healthFacility != null)
     34                await Task.Run(() => _healthFacilityRepository.Remove(healthFacility));
     35            else throw new Exception("Can't Remove health facility is null");
     36
    4937        }
    5038    }
  • FarmatikoServices/Services/HealthcareWorkerService.cs

    ree137aa r63d885e  
    44using System;
    55using System.Linq;
     6using System.Threading.Tasks;
    67
    78namespace FarmatikoServices.Services
     
    1415            _healthcareWorkerRepo = healthcareWorkerRepo;
    1516        }
    16         public void Add(HealthcareWorkers healthcareWorker)
     17        public async void Add(HealthcareWorkers healthcareWorker)
    1718        {
    18             try
    19             {
    20                 if (healthcareWorker != null)
    21                     _healthcareWorkerRepo.Add(healthcareWorker);
    22             }
    23             catch (Exception e)
    24             {
    25                 e = new Exception("Can't Add healthcare worker is null");
    26                 throw e;
    27             }
     19            if (healthcareWorker != null)
     20                await Task.Run(() => _healthcareWorkerRepo.Add(healthcareWorker));
     21            else throw new Exception("Can't add, healthcare worker is null");
    2822        }
    2923
    30         public IQueryable<HealthcareWorkers> GetAll()
     24        public async Task<IQueryable<HealthcareWorkers>> GetAll()
    3125        {
    32             return _healthcareWorkerRepo.GetAll();
     26            var healthCareWorkers = await Task.Run(() => _healthcareWorkerRepo.GetAll());
     27            if (healthCareWorkers != null)
     28                return healthCareWorkers;
     29            return null;
    3330        }
    3431
    35         public void Remove(HealthcareWorkers healthcareWorker)
     32        public async void Remove(HealthcareWorkers healthcareWorker)
    3633        {
    37             try
    38             {
    39                 if (healthcareWorker != null)
    40                     _healthcareWorkerRepo.Remove(healthcareWorker);
    41             }
    42             catch (Exception e)
    43             {
    44                 e = new Exception("Can't Remove healthcare worker is null");
    45                 throw e;
    46             }
     34            if (healthcareWorker != null)
     35                await Task.Run(() => _healthcareWorkerRepo.Remove(healthcareWorker));
     36            else throw new Exception("Can't Remove healthcare worker is null");
    4737        }
    4838    }
  • FarmatikoServices/Services/MedicineListService.cs

    ree137aa r63d885e  
    55using System.Collections.Generic;
    66using System.Linq;
     7using System.Threading.Tasks;
    78
    89namespace FarmatikoServices.Services
     
    1617        }
    1718
    18         public void Add(MedicineList medicineList)
     19        public async void Add(MedicineList medicineList)
    1920        {
    20             try
    21             {
    22                 if (medicineList != null)
    23                     _medicineListRepository.Add(medicineList);
    24             }
    25             catch (Exception e)
    26             {
    27                 e = new Exception("Can't add the medicine list is null.");
    28                 throw e;
    29             }
     21            if (medicineList != null)
     22                await Task.Run(() => _medicineListRepository.Add(medicineList));
     23            else throw new Exception("Can't add, the medicine list is null.");
    3024        }
    3125
    32         public IQueryable<MedicineList> GetAll()
     26        public async Task<IQueryable<MedicineList>> GetAll()
    3327        {
    34             return _medicineListRepository.GetAll();
     28            return await Task.Run(() => _medicineListRepository.GetAll());
    3529        }
    3630
    37         public ICollection<MedicineList> GetByManufacturer(string Manufacturer)
     31        public async Task<ICollection<MedicineList>> GetByManufacturer(string Manufacturer)
    3832        {
    39             try
    40             {
    41                 if (Manufacturer != null)
    42                 {
    43 
    44                     return _medicineListRepository.GetByManufacturer(Manufacturer);
    45                 }
    46             }
    47             catch (Exception e)
    48             {
    49                 e = new Exception("Can't get name of manufacturer is null");
    50                 throw e;
    51             }
    52             return null;
     33            if (Manufacturer != null)
     34                return await Task.Run(() => _medicineListRepository.GetByManufacturer(Manufacturer));
     35            else throw new Exception("Can't get, name of manufacturer is null");
    5336        }
    5437
    55         public ICollection<MedicineList> GetByName(string Name)
     38        public async Task<ICollection<MedicineList>> GetByName(string Name)
    5639        {
    57             try
    58             {
    59                 if (Name != null)
    60                 {
    61                     return _medicineListRepository.GetByName(Name);
    62                 }
    63             }
    64             catch (Exception e)
    65             {
    66                 e = new Exception("Can't get name is null");
    67                 throw e;
    68             }
    69             return null;
     40            if (Name != null)
     41                return await Task.Run(() => _medicineListRepository.GetByName(Name));
     42            else throw new Exception("Can't get, name is null");
    7043        }
    7144
    72         public void Remove(MedicineList medicineList)
     45        public async void Remove(MedicineList medicineList)
    7346        {
    74             try
    75             {
    76                 if (medicineList != null)
    77                     _medicineListRepository.Remove(medicineList);
    78             }
    79             catch (Exception e)
    80             {
    81                 e = new Exception("Can't remove the medicine list is null.");
    82                 throw e;
    83             }
     47            if (medicineList != null)
     48                await Task.Run(() => _medicineListRepository.Remove(medicineList));
     49            else throw new Exception("Can't remove, the medicine list is null.");
    8450        }
    8551    }
  • FarmatikoServices/Services/MedicineService.cs

    ree137aa r63d885e  
    55using System.Collections.Generic;
    66using System.Linq;
     7using System.Threading.Tasks;
    78
    89namespace FarmatikoServices.Services
     
    1617        }
    1718
    18         public void Add(Medicine medicine)
     19        public async void Add(Medicine medicine)
    1920        {
    20             try
    21             {
    22                 if (medicine != null)
    23                     _medicineRepository.Add(medicine);
    24             }
    25             catch (Exception e)
    26             {
    27                 e = new Exception("Can't Add medicine is null");
    28                 throw e;
    29             }
     21            if (medicine != null)
     22                await Task.Run(() => _medicineRepository.Add(medicine));
     23            else throw new Exception("Can't Add medicine is null");
    3024        }
    3125
    32         public IQueryable<Medicine> GetAll()
     26        public async Task<IQueryable<Medicine>> GetAll()
    3327        {
    34             return _medicineRepository.GetAll();
     28            return await Task.Run(() => _medicineRepository.GetAll());
    3529        }
    3630
    37         public IQueryable<Medicine> GetByManufacturer(string Manufacturer)
     31        public async Task<IQueryable<Medicine>> GetByManufacturer(string Manufacturer)
    3832        {
    39             try
    40             {
    41                 if (Manufacturer != null)
    42                     return _medicineRepository.GetByManufacturer(Manufacturer);
    43             }
    44             catch (Exception e)
    45             {
    46                 e = new Exception("Can't get, name of manufacturer is null");
    47                 throw e;
    48             }
    49            
    50             return null;
     33            if (Manufacturer != null)
     34                return await Task.Run(() => _medicineRepository.GetByManufacturer(Manufacturer));
     35            else throw new Exception("Can't get, name of manufacturer is null");
    5136        }
    5237
    53         public IQueryable<Medicine> GetByName(string Name)
     38        public async Task<IQueryable<Medicine>> GetByName(string Name)
    5439        {
    55             try
    56             {
    57                 if (Name != null)
    58                     return _medicineRepository.GetByName(Name);
    59             }
    60             catch (Exception e)
    61             {
    62                 e = new Exception("Can't get, name is null");
    63             }
    64            
    65             return null;
     40            if (Name != null)
     41                return await Task.Run(() => _medicineRepository.GetByName(Name));
     42            else throw new Exception("Can't get, name is null");
    6643        }
    6744
    68         public void Remove(string Medicine)
     45        public async void Remove(Medicine Medicine)
    6946        {
    70             try
    71             {
    72                 if (Medicine != null)
    73                     _medicineRepository.Remove(Medicine);
    74             }
    75             catch (Exception e)
    76             {
    77                 e = new Exception("Can't Add medicine is null");
    78                 throw e;
    79             }
     47            if (Medicine != null)
     48                await Task.Run(() => _medicineRepository.Remove(Medicine));
     49            else throw new Exception("Can't Add medicine is null");
    8050        }
    8151    }
  • FarmatikoServices/Services/PandemicService.cs

    ree137aa r63d885e  
    44using System;
    55using System.Linq;
     6using System.Threading.Tasks;
    67
    78namespace FarmatikoServices.Services
     
    1516        }
    1617
    17         public void Add(Pandemic pandemic)
     18        public async void Add(Pandemic pandemic)
    1819        {
    19             try
    20             {
    21                 if (pandemic != null)
    22                 {
    23                     _pandemicRepository.Add(pandemic);
    24                 }
    25             }
    26             catch (Exception e)
    27             {
    28                 e = new Exception("Can't add pandemic is null.");
    29                 throw e;
    30             }
     20            if (pandemic != null)
     21                await Task.Run(() => _pandemicRepository.Add(pandemic));
     22            else throw new Exception("Can't add pandemic is null.");
    3123        }
    3224
    33         public IQueryable<Pandemic> GetAll()
     25        public async Task<IQueryable<Pandemic>> GetAll()
    3426        {
    35             return _pandemicRepository.GetAll();
     27            return await Task.Run(() => _pandemicRepository.GetAll());
    3628        }
    3729
    38         public void Remove(Pandemic pandemic)
     30        public async void Remove(Pandemic pandemic)
    3931        {
    40             try
    41             {
    42                 if (pandemic != null)
    43                     _pandemicRepository.Remove(pandemic);
    44             }
    45             catch (Exception e)
    46             {
    47                 e = new Exception("Can't remove, pandemic is null.");
    48             }
     32            if (pandemic != null)
     33                await Task.Run(() => _pandemicRepository.Remove(pandemic));
     34            else throw new Exception("Can't remove, pandemic is null.");
    4935        }
    5036    }
  • FarmatikoServices/Services/PharmacyHeadService.cs

    ree137aa r63d885e  
    44using System;
    55using System.Linq;
     6using System.Threading.Tasks;
    67
    78namespace FarmatikoServices.Services
     
    1516        }
    1617
    17         public void Add(PharmacyHead pharmacyHead)
     18        public async void Add(PharmacyHead pharmacyHead)
    1819        {
    19             try
    20             {
    21                 if (pharmacyHead != null)
    22                 {
    23                     _pharmacyHeadRepository.Add(pharmacyHead);
    24                 }
    25             }
    26             catch (Exception e)
    27             {
    28                 e = new Exception("Can't add, pharmacy head is null.");
    29             }
    30 
     20            if (pharmacyHead != null)
     21                await Task.Run(() => _pharmacyHeadRepository.Add(pharmacyHead));
     22            else throw new Exception("Can't add, pharmacy head is null.");
    3123        }
    3224
    33         public IQueryable<PharmacyHead> GetAllPharmacies(string NameOfPharmacyHead)
     25        public async Task<IQueryable<PharmacyHead>> GetAllPharmacies(string NameOfPharmacyHead)
    3426        {
    3527            if (NameOfPharmacyHead != null)
    3628            {
    37                 IQueryable<PharmacyHead> Pharmacy = _pharmacyHeadRepository.GetAllPharmacies(NameOfPharmacyHead);
    38                 if (Pharmacy != null)
    39                     return Pharmacy;
     29                IQueryable<PharmacyHead> pharmacies = await Task.Run(() => _pharmacyHeadRepository.GetAllPharmacies(NameOfPharmacyHead));
     30                if (pharmacies != null)
     31                    return pharmacies;
    4032            }
    4133            return null;
    4234        }
    4335
    44         public IQueryable<PharmacyHead> GetPharmacyByName(string Name)
     36        public async Task<IQueryable<PharmacyHead>> GetPharmacyByName(string Name)
    4537        {
    4638            if (Name != null)
    4739            {
    48                 IQueryable<PharmacyHead> PharmacyHead = _pharmacyHeadRepository.GetPharmacyByName(Name);
     40                IQueryable<PharmacyHead> PharmacyHead = await Task.Run(() => _pharmacyHeadRepository.GetPharmacyByName(Name));
    4941                if (PharmacyHead != null)
    5042                    return PharmacyHead;
     
    5345        }
    5446
    55         public IQueryable<MedicineList> GetPharmacyMedicines(string NameOfPharmacy)
     47        public async Task<IQueryable<MedicineList>> GetPharmacyMedicines(string NameOfPharmacy)
    5648        {
    5749            if (NameOfPharmacy != null)
    5850            {
    59                 IQueryable<MedicineList> Medicines = _pharmacyHeadRepository.GetPharmacyMedicines(NameOfPharmacy);
     51                IQueryable<MedicineList> Medicines = await Task.Run(() => _pharmacyHeadRepository.GetPharmacyMedicines(NameOfPharmacy));
    6052                if (Medicines != null)
    6153                    return Medicines;
     
    6456        }
    6557
    66         public void Remove(PharmacyHead pharmacyHead, string Name)
     58        public async void Remove(PharmacyHead pharmacyHead)
    6759        {
    68             try
    69             {
    70                 if (Name != null)
    71                 {
    72                     _pharmacyHeadRepository.Remove(pharmacyHead, Name);
    73                 }
    74             }
    75             catch (Exception e)
    76             {
    77                 e = new Exception("Can't remove, name of pharmacy head is null.");
    78             }
    79 
     60            if (pharmacyHead != null)
     61                await Task.Run(() => _pharmacyHeadRepository.Remove(pharmacyHead));
     62            else throw new Exception("Can't remove, name of pharmacy head is null.");
    8063        }
    8164    }
  • FarmatikoServices/Services/PharmacyService.cs

    ree137aa r63d885e  
    55using System.Collections.Generic;
    66using System.Linq;
     7using System.Threading.Tasks;
    78
    89namespace FarmatikoServices.Services
     
    1516            _pharmacyRepository = pharmacyRepository;
    1617        }
    17         public void Add(Pharmacy pharmacy)
     18        public async void Add(Pharmacy pharmacy)
    1819        {
    19             try
    20             {
    21                 if (pharmacy != null)
    22                 {
    23                     _pharmacyRepository.Add(pharmacy);
    24                 }
    25             }
    26             catch (Exception e)
    27             {
    28                 e = new Exception("Can't add, pharmacy has null value.");
    29                 throw e;
    30             }
    31            
     20            if (pharmacy != null)
     21                await Task.Run(() => _pharmacyRepository.Add(pharmacy));
     22            else throw new Exception("Can't add, pharmacy has null value.");
    3223        }
    3324
    34         public IQueryable<Pharmacy> GetAll()
     25        public async Task<IQueryable<Pharmacy>> GetAll()
    3526        {
    36             return _pharmacyRepository.GetAll();
     27            return await Task.Run(() => _pharmacyRepository.GetAll());
    3728        }
    3829
    39         public ICollection<Pharmacy> GetPharmacies()
     30        public async Task<ICollection<Pharmacy>> GetPharmacies()
    4031        {
    41             return _pharmacyRepository.GetPharmacies();
     32            return await Task.Run(() => _pharmacyRepository.GetPharmacies());
    4233        }
    4334
    44         public void Remove(Pharmacy pharmacy)
     35        public async void Remove(Pharmacy pharmacy)
    4536        {
    46             try
    47             {
    48                 if (pharmacy != null)
    49                     _pharmacyRepository.Remove(pharmacy);
    50             }
    51             catch (Exception e)
    52             {
    53                 e = new Exception("Can't remove, pharmacy has null value.");
    54                 throw e;
    55             }
     37            if (pharmacy != null)
     38                await Task.Run(() => _pharmacyRepository.Remove(pharmacy));
     39            else throw new Exception("Can't remove, pharmacy has null value.");
    5640        }
    5741
    58         public void UpdatePharmacy(Pharmacy pharmacy, string Name)
     42        public async void UpdatePharmacy(Pharmacy pharmacy)
    5943        {
    60             try
    61             {
    62                 if (pharmacy != null && Name != null)
    63                 {
    64                     _pharmacyRepository.UpdatePharmacy(pharmacy, Name);
    65                 }
    66             }
    67             catch (Exception e)
    68             {
    69                 e = new Exception("Can not update pharmacy, has null value.");
    70                 throw e;
    71             }
    72            
     44            if (pharmacy != null)
     45                await Task.Run(() => _pharmacyRepository.UpdatePharmacy(pharmacy));
     46            else throw new Exception("Can not update pharmacy, has null value.");
    7347        }
    7448    }
  • FarmatikoServices/Services/ProcessJSONService.cs

    ree137aa r63d885e  
    1010using FarmatikoServices.FarmatikoServiceInterfaces;
    1111using RestSharp;
     12using System.Threading.Tasks;
    1213
    1314namespace FarmatikoServices.Services
     
    1516    public class ProcessJSONService : IProcessJSONService
    1617    {
    17         //private IHealthFacilityRepository _healthFacilityRepository;
     18        private IHealthFacilityRepository _healthFacilityRepository;
    1819        private IPandemicRepository _pandemicRepository;
    19         //private IHealthcareWorkerRepository _healthcareWorkerRepository;
    20         //private IMedicineRepository _medicineRepository;
    21         //private readonly ILogger _logger;
    22         public ProcessJSONService(/*IHealthFacilityRepository healthFacilityRepository, */IPandemicRepository pandemicRepository/*,
    23             IHealthcareWorkerRepository healthcareWorkerRepository, IMedicineRepository medicineRepository*/)
     20        private IHealthcareWorkerRepository _healthcareWorkerRepository;
     21        private IMedicineRepository _medicineRepository;
     22        private readonly ILogger _logger;
     23        public ProcessJSONService(IHealthFacilityRepository healthFacilityRepository, IPandemicRepository pandemicRepository,
     24            IHealthcareWorkerRepository healthcareWorkerRepository, IMedicineRepository medicineRepository, ILogger logger)
    2425        {
    25             //_logger = logger;
    26             //_healthFacilityRepository = healthFacilityRepository;
     26            _logger = logger;
     27            _healthFacilityRepository = healthFacilityRepository;
    2728            _pandemicRepository = pandemicRepository;
    28             //_healthcareWorkerRepository = healthcareWorkerRepository;
    29             //_medicineRepository = medicineRepository;
     29            _healthcareWorkerRepository = healthcareWorkerRepository;
     30            _medicineRepository = medicineRepository;
    3031        }
    31        
    32         public List<HealthFacilities> GetProcessedHealthFacilitiesFromJSON()
     32
     33        public async Task<HashSet<HealthFacilities>> GetProcessedHealthFacilitiesFromJSON()
    3334        {
    3435            try
    3536            {
    36                 /*var client = new WebClient();
    37                 var json = client.DownloadString(@"C:\Users\Miki\Desktop\ustanovi.json");
     37                HashSet<HealthFacilities> hashSet = new HashSet<HealthFacilities>();
     38                var client = new WebClient();
     39                var json = client.DownloadString(@"C:\Users\dslez\Desktop\ustanovi.json");
    3840
    3941                var jsonResponse = JObject.Parse(json);
    4042                var records = JArray.Parse(jsonResponse.GetValue("records").ToString());
    4143
    42                 foreach(var rec in records)
     44                foreach (var rec in records)
    4345                {
    4446                    dynamic obj = JsonConvert.DeserializeObject(rec.ToString());
     
    4951                    var Phone = obj[11];
    5052                    var Type = obj[5];
    51                     HealthFacilities healthFacility = new HealthFacilities();
    52                     healthFacility.Name = Name;
     53                    HealthFacilities healthFacility = new HealthFacilities(Name, Municipality, Address, Type, Email, Phone);
     54                    /*healthFacility.Name = Name;
    5355                    healthFacility.Municipality = Municipality;
    5456                    healthFacility.Address = Address;
    5557                    healthFacility.Email = Email;
    5658                    healthFacility.Phone = Phone;
    57                     healthFacility.Type = Type;
    58                     _healthFacilityRepository.Add(healthFacility);
    59                    
    60                 }*/
     59                    healthFacility.Type = Type;*/
     60                    //hashSet.Add(healthFacility);
     61                    await Task.Run(() => _healthFacilityRepository.Add(healthFacility));
    6162
     63                }
    6264
     65            }
     66            catch (Exception e)
     67            {
     68                _logger.LogInformation(e.Message);
     69                throw new Exception("Cannot process health facilities from JSON.");
     70            }
     71            return null;
     72        }
    6373
    64                 var client1 = new RestClient("https://api.covid19api.com/summary");
    65                 var response = client1.Execute(new RestRequest());
     74        public async Task<HashSet<Pandemic>> GetProcessedPandemicsFromJSONApi()
     75        {
     76            try
     77            {
     78                var client = new RestClient("https://api.covid19api.com/summary");
     79                var response = client.Execute(new RestRequest());
    6680                string original = response.Content;
    6781                var jsonResponsePandemic = JObject.Parse(original);
     
    7892                var NewMK = Int32.Parse(objP.GetValue("NewConfirmed").ToString());
    7993
    80                 Pandemic pandemic = new Pandemic();
    81                 pandemic.TotalGlobal = TotalConfirmed;
     94                var Name = "Coronavirus";
     95                var ActiveMk = TotalMk - (TotalRecoveredMK + TotalDeathsMK);
     96                var ActiveGlobal = TotalConfirmed - (TotalRecovered + TotalDeaths);
     97
     98                Pandemic pandemic = new Pandemic(Name, TotalMk, ActiveMk, TotalDeathsMK, NewMK, TotalConfirmed, TotalDeaths, ActiveGlobal);
     99                /*pandemic.TotalGlobal = TotalConfirmed;
    82100                pandemic.ActiveGlobal = TotalConfirmed - (TotalRecovered + TotalDeaths);
    83101                pandemic.DeathsGlobal = TotalDeaths;
     
    86104                pandemic.DeathsMK = TotalDeathsMK;
    87105                pandemic.NewMK = NewMK;
    88                 pandemic.Name = "Coronavirus";
    89                 _pandemicRepository.Add(pandemic);
     106                pandemic.Name = "Coronavirus";*/
     107                await Task.Run(() => _pandemicRepository.Add(pandemic));
     108            }
     109            catch (Exception e)
     110            {
     111                _logger.LogInformation(e.Message);
     112            }
     113            return null;
     114        }
    90115
    91 
    92 
    93                 /*var jsonW = client.DownloadString(@"C:\Users\Miki\Desktop\rabotnici.json");
     116        public async Task<HashSet<HealthcareWorkers>> GetProcessedHealthcareWorkersFromJSON()
     117        {
     118            try
     119            {
     120                var client = new WebClient();
     121                var jsonW = client.DownloadString(@"C:\Users\dslez\Desktop\rabotnici.json");
    94122
    95123                var jsonResponseW = JObject.Parse(jsonW);
     
    101129                    var Name = obj[4];
    102130                    var Branch = obj[2];
    103                     HealthFacilities facility = new HealthFacilities();
    104                     facility.Name = obj[1];
    105                     facility.Municipality = "WorkerFacilityMunicipality";
    106                     facility.Address = "WorkerFacilityAddress";
     131                    var FacilityName = obj[1];
    107132                    var Title = obj[3];
    108                     HealthcareWorkers healthcareWorker = new HealthcareWorkers();
    109                     healthcareWorker.Name = Name;
     133                    HealthFacilities facility = _healthFacilityRepository.GetByName(FacilityName);
     134                    HealthFacilities Facility = new HealthFacilities(facility.Name, facility.Municipality, facility.Address,
     135                                                                        facility.Type, facility.Email, facility.Phone);
     136                    HealthcareWorkers healthcareWorker = new HealthcareWorkers(Name, Branch, Facility, Title);
     137                    /*Facility.Name = obj[1];
     138                    Facility.Municipality = "WorkerFacilityMunicipality";
     139                    Facility.Address = "WorkerFacilityAddress";*/
     140                    /*healthcareWorker.Name = Name;
    110141                    healthcareWorker.Branch = Branch;
    111                     healthcareWorker.Facility = facility;
    112                     healthcareWorker.Title = Title;
    113                     _healthcareWorkerRepository.Add(healthcareWorker);
     142                    healthcareWorker.Facility = Facility;
     143                    healthcareWorker.Title = Title;*/
     144                    await Task.Run(() => _healthcareWorkerRepository.Add(healthcareWorker));
    114145                }
     146            }
     147            catch (Exception e)
     148            {
     149                _logger.LogInformation(e.Message);
     150            }
     151            return null;
     152        }
    115153
    116 
    117 
    118                 var jsonM = client.DownloadString(@"C:\Users\Miki\Desktop\lekovi.json");
     154        public async Task<HashSet<Medicine>> GetProcessedMedicinesFromJSON()
     155        {
     156            try
     157            {
     158                var client = new WebClient();
     159                var jsonM = client.DownloadString(@"C:\Users\dslez\Desktop\lekovi.json");
    119160
    120161                var jsonResponseM = JObject.Parse(jsonM);
     
    131172                    var Price = float.Parse(obj[17]);
    132173                    var Packaging = obj[8];
    133                     Medicine medicine = new Medicine();
    134                     medicine.Name = Name;
     174                    Medicine medicine = new Medicine(Name, Strength, Form, WayOfIssuing, Manufacturer, Price, Packaging);
     175                    /*medicine.Name = Name;
    135176                    medicine.Strength = Strength;
    136177                    medicine.Form = Form;
     
    138179                    medicine.Manufacturer = Manufacturer;
    139180                    medicine.Price = Price;
    140                     medicine.Packaging = Packaging;
    141                     _medicineRepository.Add(medicine);
    142                 }*/
    143 
    144 
     181                    medicine.Packaging = Packaging;*/
     182                    await Task.Run(() => _medicineRepository.Add(medicine));
     183                }
    145184            }
    146185            catch (Exception e)
    147186            {
    148                 //_logger.LogError(e.Message);
    149                 Console.WriteLine(e.Message);
    150                 throw e;
    151                 return null;
     187                _logger.LogInformation(e.Message);
    152188            }
    153189            return null;
    154190        }
    155 
    156191    }
    157192}
Note: See TracChangeset for help on using the changeset viewer.