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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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            }
Note: See TracChangeset for help on using the changeset viewer.