Changeset d23bf72


Ignore:
Timestamp:
11/05/20 06:57:35 (3 years ago)
Author:
DimitarSlezenkovski <dslezenkovski@…>
Branches:
master
Children:
afc9a9a
Parents:
1f4846d
Message:

Add SystemService, Auth, fix a lil bugs :)

Files:
12 added
1 deleted
31 edited
2 moved

Legend:

Unmodified
Added
Removed
  • Farmatiko.sln

    r1f4846d rd23bf72  
    88Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FarmatikoData", "FarmatikoData\FarmatikoData.csproj", "{5BC55BDD-A064-4CE7-8606-D2FF42699EBF}"
    99EndProject
    10 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FarmatikoServices", "FarmatikoServices\FarmatikoServices.csproj", "{D207CD1B-4C31-4414-9EF4-DC18F219CBF6}"
     10Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FarmatikoServices", "FarmatikoServices\FarmatikoServices.csproj", "{D207CD1B-4C31-4414-9EF4-DC18F219CBF6}"
    1111EndProject
    1212Global
  • Farmatiko/ClientApp/src/app/login/login.component.html

    r1f4846d rd23bf72  
    66  <div class="example-container">
    77    <mat-form-field>
    8       <input matInput placeholder="Email" [(ngModel)]="this.username" formControlName="email">
     8      <input matInput placeholder="Email" [(ngModel)]="this.username" formControlName="username">
    99    </mat-form-field>
    1010
  • Farmatiko/ClientApp/src/app/shared/interfaces.ts

    r1f4846d rd23bf72  
    5555    Passwd: string;
    5656    Name: string;
     57    originalUserName?: string;
    5758    Role?: string;
    5859
  • Farmatiko/ClientApp/src/app/shared/services/auth.service.ts

    r1f4846d rd23bf72  
    1111  username: string;
    1212  role: string;
     13  originalUserName?: string;
    1314  accessToken: string;
    1415  refreshToken: string;
    15   head: IPharmacyHead;
     16  head?: IPharmacyHead;
    1617}
    1718
     
    3536        this.http.get<LoginResult>(`${this.apiUrl}/user`).subscribe((x) => {
    3637          this._user.next({
    37             Email: x.username,
    38             Role: x.role,
     38            Email: x.head.Email,
     39            Role: x.head.Role,
     40            originalUserName: x.head.originalUserName,
    3941            Passwd: x.head.Passwd,
    40             Name: x.head.Name
     42            Name: x.head.Name,
     43            PharmacyMedicines: x.head.PharmacyMedicines,
     44            Pharmacy: x.head.Pharmacy
    4145          });
    4246        });
     
    6064        map((x) => {
    6165          this._user.next({
    62             Email: x.username,
    63             Role: x.role,
     66            Email: x.head.Email,
     67            Role: x.head.Role,
     68            originalUserName: x.head.originalUserName,
    6469            Passwd: x.head.Passwd,
    65             Name: x.head.Name
     70            Name: x.head.Name,
     71            PharmacyMedicines: x.head.PharmacyMedicines,
     72            Pharmacy: x.head.Pharmacy
    6673          });
    6774          this.setLocalStorage(x);
     
    98105        map((x) => {
    99106          this._user.next({
    100             Email: x.username,
    101             Role: x.role,
     107            Email: x.head.Email,
     108            Role: x.head.Role,
     109            originalUserName: x.head.originalUserName,
    102110            Passwd: x.head.Passwd,
    103             Name: x.head.Name
     111            Name: x.head.Name,
     112            PharmacyMedicines: x.head.PharmacyMedicines,
     113            Pharmacy: x.head.Pharmacy
    104114          });
    105115          this.setLocalStorage(x);
  • Farmatiko/ClientApp/src/environments/environment.ts

    r1f4846d rd23bf72  
    55export const environment = {
    66  production: false,
    7   baseApiUrl: 'https://localhost:44342/',
     7  baseApiUrl: 'https://localhost:5001/',
    88};
    99
  • Farmatiko/Controllers/AdminController.cs

    r1f4846d rd23bf72  
    55using FarmatikoData.Models;
    66using FarmatikoServices.FarmatikoServiceInterfaces;
     7using Microsoft.AspNetCore.Authorization;
    78using Microsoft.AspNetCore.Mvc;
    89
    910namespace Farmatiko.Controllers
    1011{
     12    [ApiController]
     13    [Authorize(Roles = "PharmacyHead")]
    1114    public class AdminController : Controller
    1215    {
     
    4043        [HttpPost]
    4144        [Route("api/pharmacyhead/add")]
    42         public async Task<IActionResult> AddPharmacyHead(PharmacyHead pharmacyHead)
     45        public async Task<IActionResult> AddPharmacyHead([FromBody]PharmacyHead pharmacyHead)
    4346        {
    4447            await _service.AddPharmacyHead(pharmacyHead);
     
    4649        }
    4750
    48         [HttpPost]
     51        [HttpDelete]
    4952        [Route("api/pharmacyhead/delete/{Id}")]
    50         public async Task<IActionResult> RemovePharmacyHead([FromQuery]int Id)
     53        public async Task<IActionResult> RemovePharmacyHead([FromRoute] int Id)
    5154        {
    5255            await _service.RemovePharmacyHead(Id);
    5356            return Ok();
    5457        }
    55         [HttpPost]
    56         public IActionResult RejectRequset(RequestPharmacyHead req)
     58        [HttpDelete]
     59        [Route("api/pharmacyhead/requests/{Id}")]
     60        public IActionResult RejectRequest([FromRoute] int Id)
    5761        {
    58             bool Success = _adminService.RejectRequest(req);
     62            bool Success = _adminService.RejectRequest(Id);
    5963            return Ok(Success);
    6064        }
    6165        [HttpPost]
    62         public async Task<IActionResult> ApproveRequest(PharmacyHead pharmacyHead)
     66        [Route("api/pharmacyhead/{Id}")]
     67        public async Task<IActionResult> ApproveRequest([FromRoute]int Id, [FromBody]PharmacyHead pharmacyHead)
    6368        {
     69            int id = Id;
    6470            await _phservice.UpdatePharmacyHead(pharmacyHead);
    6571            return Ok();
  • Farmatiko/Controllers/ErrorController.cs

    r1f4846d rd23bf72  
    1 using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Threading.Tasks;
     1using System.Net;
     2using Microsoft.AspNetCore.Diagnostics;
    53using Microsoft.AspNetCore.Mvc;
     4using Microsoft.Extensions.Logging;
    65
    76namespace Farmatiko.Controllers
    87{
     8    [ApiController]
    99    public class ErrorController : Controller
    1010    {
    11         public IActionResult Index()
     11        private readonly ILogger<ErrorController> _logger;
     12
     13        public ErrorController(ILogger<ErrorController> logger)
    1214        {
    13             return View();
     15            _logger = logger;
     16        }
     17        [Route("/Error")]
     18        public IActionResult Error()
     19        {
     20            var exception = HttpContext.Features.Get<IExceptionHandlerFeature>();
     21            var statusCode = exception.Error.GetType().Name switch
     22            {
     23                "ArgumentException" => HttpStatusCode.BadRequest,
     24                "Exception" => HttpStatusCode.InternalServerError,
     25                /*"NotFoundResult" => HttpStatusCode.NotFound,*/
     26                _ => HttpStatusCode.ServiceUnavailable
     27            };
     28            _logger.LogInformation(statusCode.ToString() + " " + exception.ToString());
     29            return Problem(detail: exception.Error.Message, statusCode: (int)statusCode);
    1430        }
    1531    }
  • Farmatiko/Controllers/FarmatikoController.cs

    r1f4846d rd23bf72  
    1111    {
    1212        private readonly IService _service;
    13         public FarmatikoController(IService service)
     13        private readonly IProcessJSONService _JSONservice;
     14        public FarmatikoController(IService service, IProcessJSONService JSONservice)
    1415        {
    1516            _service = service;
     17            _JSONservice = JSONservice;
    1618        }
    1719        // Workers
    1820        //Get
     21        [HttpGet]
     22        [Route("api/getData")]
     23        public void InsertData()
     24        {
     25            //_JSONservice.DownloadPharmaciesExcel();
     26            //_JSONservice.GetProcessedHealthcareWorkersFromJSON();
     27            //_JSONservice.GetProcessedHealthFacilitiesFromJSON();
     28            //_JSONservice.GetProcessedMedicinesFromJSON();
     29            //_JSONservice.GetProcessedPandemicsFromJSONApi();
     30        }
    1931        [HttpGet]
    2032        [Route("api/workers")]
     
    2537        }
    2638        [HttpGet]
    27         [Route("api/workers/search/{Query}")]
    28         public async Task<IEnumerable<HealthcareWorker>> SearchWorkers(string Query)
     39        [Route("api/workers/search/{query}")]
     40        public async Task<IEnumerable<HealthcareWorker>> SearchWorkers([FromRoute]string query)
    2941        {
    30             return await _service.SearchWorkers(Query);
     42            return await _service.SearchWorkers(query);
    3143        }
    3244        [HttpGet]
    3345        [Route("api/workers/{id}")]
    34         public async Task<HealthcareWorker> GetWorker(int Id)
     46        public async Task<HealthcareWorker> GetWorker([FromRoute] int Id)
    3547        {
    3648            return await _service.GetWorker(Id);
     
    4860        }
    4961        [HttpGet]
    50         [Route("api/facilities/search/{Query}")]
    51         public async Task<IEnumerable<HealthFacility>> SearchFacilities(string Query)
     62        [Route("api/facilities/search/{query}")]
     63        public async Task<IEnumerable<HealthFacility>> SearchFacilities([FromRoute] string query)
    5264        {
    53             return await _service.SearchFacilities(Query);
     65            return await _service.SearchFacilities(query);
    5466        }
    5567        [HttpGet]
    56         [Route("api/facilities/{Id}")]
    57         public async Task<HealthFacility> GetFacility(int Id)
     68        [Route("api/facilities/{id}")]
     69        public async Task<HealthFacility> GetFacility([FromRoute] int id)
    5870        {
    59             return await _service.GetFacility(Id);
     71            return await _service.GetFacility(id);
    6072        }
    6173        //Post
     
    7082        }
    7183        [HttpGet]
    72         [Route("api/medicines/search/{Query}")]
    73         public async Task<IEnumerable<Medicine>> SearchMedicines(string Query)
     84        [Route("api/medicines/search/{query}")]
     85        public async Task<IEnumerable<Medicine>> SearchMedicines([FromRoute] string query)
    7486        {
    75             return await _service.SearchMedicines(Query);
     87            return await _service.SearchMedicines(query);
    7688        }
    7789        [HttpGet]
    7890        [Route("api/medicines/{Id}")]
    79         public async Task<Medicine> GetMedicine(int Id)
     91        public async Task<Medicine> GetMedicine([FromRoute] int Id)
    8092        {
    8193            return await _service.GetMedicine(Id);
     
    98110        [HttpGet]
    99111        [Route("api/pharmacy/search/{Query}")]
    100         public async Task<IEnumerable<Pharmacy>> SearchPharmacies(string Query)
     112        public async Task<IEnumerable<Pharmacy>> SearchPharmacies([FromRoute] string Query)
    101113        {
    102114            return await _service.SearchPharmacies(Query);
     
    104116        [HttpGet]
    105117        [Route("api/pharmacy/{Id}")]
    106         public async Task<Pharmacy> GetPharmacy(int Id)
     118        public async Task<Pharmacy> GetPharmacy([FromRoute] int Id)
    107119        {
    108120            return await _service.GetPharmacy(Id);
  • Farmatiko/Controllers/PharmacyHeadController.cs

    r1f4846d rd23bf72  
    1 using System.Collections;
    2 using System.Collections.Generic;
    3 using System.Linq;
     1using System.Collections.Generic;
    42using System.Threading.Tasks;
    5 using FarmatikoData.FarmatikoRepoInterfaces;
    63using FarmatikoData.Models;
    74using FarmatikoServices.FarmatikoServiceInterfaces;
     5using Microsoft.AspNetCore.Authorization;
    86using Microsoft.AspNetCore.Mvc;
    97
     
    119{
    1210    [ApiController]
     11    [Authorize(Roles = "PharmacyHead")]
    1312    public class PharmacyHeadController : Controller
    1413    {
     
    2019
    2120        //GET
    22         //Mi trebaat rutite
    23         [HttpGet]
     21        /*[HttpGet]
    2422        [Route("api/pharmacyhead")]
    25         public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo(string Token)
     23        public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo()
    2624        {
    27             var PHeads = await _PHService.GetPharmacyHeadInfo(Token);
     25            var PHeads = await _PHService.GetPharmacyHeadInfo();
    2826            return PHeads;
    29         }
     27        }*/
    3028        [HttpGet]
    3129        [Route("api/pharmacyhead/{Id}")]
    32         public async Task<PharmacyHead> GetPharmacyHeadById(int Id)
     30        public async Task<PharmacyHead> GetPharmacyHeadById([FromRoute]int Id)
    3331        {
    3432            var Phead = await _PHService.GetPharmacyHeadByIdAsync(Id);
     
    3836        [HttpPost]
    3937        [Route("api/pharmacyhead/add")]
    40         public async Task<IActionResult> AddPharmacyHead(PharmacyHead pharmacyHead)
     38        public async Task<IActionResult> AddPharmacyHead([FromBody]PharmacyHead pharmacyHead)
    4139        {
    4240            bool Success = await _PHService.Add(pharmacyHead);
     
    4442        }
    4543
    46         [HttpPost]
     44        /*[HttpPost]
    4745        [Route("api/pharmacyhead/login")]
    4846        public async Task<int> Login([FromBody]PharmacyHead pharmacyHead)
    4947        {
    5048            return await _PHService.Login(pharmacyHead);
    51         }
     49        }*/
    5250        [HttpPut]
    5351        [Route("api/pharmacyhead/{Id}")]
     
    5856        [HttpPost]
    5957        [Route("api/pharmacyhead/requests")]
    60         public async Task<IActionResult> ClaimPharmacy(RequestPharmacyHead pharmacy)
     58        public async Task<IActionResult> ClaimPharmacy([FromBody]RequestPharmacyHead pharmacy)
    6159        {
    6260            bool Success = await _PHService.ClaimPharmacy(pharmacy);
     
    6563        [HttpDelete]
    6664        [Route("api/pharmacyhead/delete/{Id}")]
    67         public async Task<IActionResult> Remove([FromQuery] int Id)
     65        public async Task<IActionResult> Remove([FromRoute] int Id)
    6866        {
    6967            bool Success = await _PHService.Remove(Id);
     
    7270        [HttpPost]
    7371        [Route("api/pharmacyhead/requests/{Id}")]
    74         public async Task<IActionResult> RemoveClaimingRequest([FromQuery] int Id)
     72        public async Task<IActionResult> RemoveClaimingRequest([FromRoute] int Id)
    7573        {
    7674            bool Success = await _PHService.RemoveClaimingRequest(Id);
  • Farmatiko/Farmatiko.csproj

    r1f4846d rd23bf72  
    1414
    1515  <ItemGroup>
     16    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.9" />
    1617    <PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="3.1.6" />
    1718    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.6" />
  • Farmatiko/Startup.cs

    r1f4846d rd23bf72  
    77using FarmatikoData;
    88using Microsoft.EntityFrameworkCore;
    9 using FarmatikoServices;
    109using FarmatikoData.FarmatikoRepoInterfaces;
    1110using FarmatikoData.FarmatikoRepo;
     
    1312using FarmatikoServices.Services;
    1413using Microsoft.Extensions.Logging;
     14using Microsoft.AspNetCore.Authentication.JwtBearer;
     15using Microsoft.IdentityModel.Tokens;
     16using System.Text;
     17using FarmatikoServices.Auth;
     18using FarmatikoServices.Infrastructure;
     19using System;
    1520
    1621namespace Farmatiko
     
    5964
    6065            services.AddTransient<ILogger, Logger<ProcessJSONService>>();
     66
     67            // services.AddTransient<ISystemService, SystemService>();
     68
     69
     70            var jwtTokenConfig = Configuration.GetSection("jwtTokenConfig").Get<JwtTokenConfig>();
     71            services.AddSingleton(jwtTokenConfig);
     72
     73            services.AddAuthentication(o =>
     74            {
     75                o.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
     76                o.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
     77                o.DefaultSignInScheme = JwtBearerDefaults.AuthenticationScheme;
     78            }).AddJwtBearer(x =>
     79            {
     80                x.RequireHttpsMetadata = true;
     81                x.SaveToken = true;
     82                x.TokenValidationParameters = new TokenValidationParameters
     83                {
     84                    ValidateIssuer = true,
     85                    ValidIssuer = jwtTokenConfig.Issuer,
     86                    ValidateIssuerSigningKey = true,
     87                    IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(jwtTokenConfig.Secret)),
     88                    ValidAudience = jwtTokenConfig.Audience,
     89                    ValidateAudience = true,
     90                    ValidateLifetime = true,
     91                    ClockSkew = TimeSpan.FromMinutes(1)
     92                };
     93            });
     94
     95            /*.AddJwtBearer(cfg =>
     96                     {
     97                         cfg.RequireHttpsMetadata = false;
     98                         cfg.SaveToken = true;
     99                         cfg.IncludeErrorDetails = true;
     100                         cfg.TokenValidationParameters = new TokenValidationParameters()
     101                         {
     102                             ValidIssuer = Configuration.GetSection("TokenIssuer").Value,
     103                             ValidAudience = Configuration.GetSection("TokenIssuer").Value,
     104                             IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration.GetSection("SecretKey").Value))
     105                         };
     106
     107                     });
     108*/
     109            services.AddSingleton<IJwtAuthManager, JwtAuthManager>();
     110            services.AddHostedService<JwtRefreshTokenCache>();
     111            services.AddScoped<IAuthService, AuthService>();
     112            //If we add imgs
     113            /*services.Configure<FormOptions>(o => {
     114                o.ValueLengthLimit = int.MaxValue;
     115                o.MultipartBodyLengthLimit = int.MaxValue;
     116                o.MemoryBufferThreshold = int.MaxValue;
     117            });*/
     118
    61119        }
    62120
     
    74132                app.UseHsts();
    75133            }
    76 
     134            app.UseExceptionHandler("/Error");
    77135            app.UseHttpsRedirection();
    78136            app.UseStaticFiles();
     137
     138            // if we add imgs
     139            /*app.UseStaticFiles(new StaticFileOptions()
     140            {
     141                FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), @"wwwroot")),
     142                RequestPath = new PathString("/wwwroot")
     143            });*/
     144
    79145            if (!env.IsDevelopment())
    80146            {
     
    84150            app.UseRouting();
    85151
     152            app.UseAuthentication();
     153            app.UseAuthorization();
     154
    86155            app.UseCors(MyAllowSpecificOrigins);
    87156
     
    90159                endpoints.MapControllerRoute(
    91160                    name: "default",
    92                     pattern: "{controller}/{action=Index}/{id?}");
     161                    pattern: "api/{controller}/{action=Index}/{id?}");
    93162            });
    94163
  • Farmatiko/appsettings.json

    r1f4846d rd23bf72  
    1212  "EPPlus": {
    1313    "ExcelPackage": {
    14       "LicenseContext": "NonCommercial" 
     14      "LicenseContext": "NonCommercial"
    1515    }
    1616  },
    17   "AllowedHosts": "*"
     17  "AllowedHosts": "*",
     18  "jwtTokenConfig": {
     19    "secret": "1234567890123456789",
     20    "issuer": "FARMATIKO",
     21    "audience": "FARMATIKO",
     22    "accessTokenExpiration": 20,
     23    "refreshTokenExpiration": 60
     24  },
     25  "SecretKey": "PEJcK2bD4E2BKdNmAlUl",
     26  "TokenIssuer": "FARMATIKOISSUER"
    1827}
  • FarmatikoData/FarmatikoData.csproj

    r1f4846d rd23bf72  
    44    <TargetFramework>netcoreapp3.1</TargetFramework>
    55  </PropertyGroup>
    6 
    7   <ItemGroup>
    8     <Compile Remove="Migrations\20200729091456_Second migration.cs" />
    9     <Compile Remove="Migrations\20200729091456_Second migration.Designer.cs" />
    10     <Compile Remove="Migrations\20200729091727_Second Migration.cs" />
    11     <Compile Remove="Migrations\20200729091727_Second Migration.Designer.cs" />
    12     <Compile Remove="Migrations\20200729101719_Third Migration.cs" />
    13     <Compile Remove="Migrations\20200729101719_Third Migration.Designer.cs" />
    14   </ItemGroup>
    156
    167  <ItemGroup>
  • FarmatikoData/FarmatikoDataContext.cs

    r1f4846d rd23bf72  
    1717        public virtual DbSet<MedicineList> MedicineLists { get; set; }
    1818        public virtual DbSet<RequestPharmacyHead> PHRequests { get; set; }
     19        public virtual DbSet<User> Users { get; set; }
    1920    }
    2021}
  • FarmatikoData/FarmatikoRepo/AdminRepo.cs

    r1f4846d rd23bf72  
    3131        }
    3232        //POST
    33         public void RemoveClaimRequest(RequestPharmacyHead req)
     33        public void RemoveClaimRequest(int Id)
    3434        {
     35            var req = _context.PHRequests.Where(x => x.Id == Id).FirstOrDefault();
    3536            _context.PHRequests.Remove(req);
    3637            _context.SaveChanges();
  • FarmatikoData/FarmatikoRepo/PHRepo.cs

    r1f4846d rd23bf72  
    7171            await _context.SaveChangesAsync();
    7272        }
     73
     74        public PharmacyHead GetPharmacyHeadByUserName(string userName)
     75        {
     76            return _context.PharmacyHeads
     77                .Where(x => x.Email.Equals(userName))
     78                .FirstOrDefault();
     79        }
    7380    }
    7481}
  • FarmatikoData/FarmatikoRepo/Repository.cs

    r1f4846d rd23bf72  
    1919        public async Task<IEnumerable<HealthcareWorker>> GetAllWorkers()
    2020        {
    21             var Workers = await Task.Run(() => _context.HealthcareWorkers.Take(10));
     21            var Workers = await _context.HealthcareWorkers.Take(5).ToListAsync();
    2222            return Workers;
    2323        }
     
    2525        public async Task<IEnumerable<HealthFacility>> GetFacilities()
    2626        {
    27             var Facilities = await Task.Run(() => _context.HealthFacilities.Take(10));
     27            var Facilities = await _context.HealthFacilities.Take(5).ToListAsync();
    2828            return Facilities;
    2929        }
     
    4343        public async Task<IEnumerable<Medicine>> GetMedicines()
    4444        {
    45             var Medicines = await Task.Run(() => _context.Medicines.Take(10));
     45            var Medicines = await _context.Medicines.Take(3).ToListAsync();
    4646            return Medicines;
    4747        }
     
    4949        public async Task<Pandemic> GetPandemic()
    5050        {
    51             var Pandemic = await Task.Run(() => _context.Pandemics.FirstOrDefault());
     51            var Pandemic = await _context.Pandemics.FirstOrDefaultAsync();
    5252            return Pandemic;
    5353        }
     
    5555        public async Task<IEnumerable<Pharmacy>> GetPharmacies()
    5656        {
    57             var Pharmacies = await Task.Run(() => _context.Pharmacies.Take(10));
     57            var Pharmacies = await _context.Pharmacies.Take(5).ToListAsync();
    5858            return Pharmacies;
    5959        }
     
    7373        public async Task<IEnumerable<HealthFacility>> SearchFacilities(string query)
    7474        {
    75             var SearchQuery = await Task.Run(() => _context.HealthFacilities
    76             .Where(x => x.Name.Equals(query))
    77             .OrderBy(x => x.Name));
     75            var SearchQuery = await _context.HealthFacilities
     76            .Where(x => x.Name.Contains(query))
     77            .OrderBy(x => x.Name).Take(3).ToListAsync();
    7878
    7979            return SearchQuery;
     
    8282        public async Task<IEnumerable<Medicine>> SearchMedicines(string query)
    8383        {
    84             var SearchQuery = await Task.Run(() => _context.Medicines
    85             .Where(x => x.Name.Equals(query))
    86             .OrderBy(x => x.Name));
     84            var SearchQuery = await _context.Medicines
     85            .Where(x => x.Name.Contains(query))
     86            .OrderBy(x => x.Name).Take(5).ToListAsync();
    8787
    8888            return SearchQuery;
     
    9191        public async Task<IEnumerable<Pharmacy>> SearchPharmacies(string query)
    9292        {
    93             var SearchQuery = await Task.Run(() => _context.Pharmacies
    94             .Where(x => x.Name.Equals(query))
    95             .OrderBy(x => x.Name));
     93            var SearchQuery = await _context.Pharmacies.Take(5)
     94            .Where(x => x.Name.Contains(query))
     95            .OrderBy(x => x.Name).Take(5).ToListAsync();
    9696
    9797            return SearchQuery;
     
    100100        public async Task<IEnumerable<HealthcareWorker>> SearchWorkers(string query)
    101101        {
    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         }
    108         public async Task<HealthFacility> GetFacilityJSON(string healthFacility)
    109         {
    110             var Facility = await Task.Run(() => _context.HealthFacilities.Where(x => x.Name.Equals(healthFacility)).FirstOrDefault());
     102            var SearchQuery = await _context.HealthcareWorkers.Take(5)
     103            .Where(x => x.Name.Contains(query))
     104            .OrderBy(x => x.Name).Take(5).ToListAsync();
     105
     106            return SearchQuery;
     107        }
     108        public HealthFacility GetFacilityJSON(string healthFacility)
     109        {
     110            var Facility = _context.HealthFacilities.Where(x => x.Name.Equals(healthFacility)).FirstOrDefault();
    111111            return Facility;
    112112        }
     
    116116        public async Task AddWorker(HealthcareWorker Worker)
    117117        {
    118             await Task.Run(() => _context.HealthcareWorkers.Add(Worker));
    119             await _context.SaveChangesAsync();
     118            await _context.HealthcareWorkers.AddAsync(Worker);
     119            _context.SaveChanges();
    120120        }
    121121
    122122        public async Task AddFacility(HealthFacility healthFacility)
    123123        {
    124             await Task.Run(() => _context.HealthFacilities.Add(healthFacility));
    125             await _context.SaveChangesAsync();
     124            await _context.HealthFacilities.AddAsync(healthFacility);
     125            _context.SaveChanges();
    126126        }
    127127
    128128        public async Task AddPharmacy(Pharmacy pharmacy)
    129129        {
    130             await Task.Run(() => _context.Pharmacies.Add(pharmacy));
    131             await _context.SaveChangesAsync();
     130            await _context.Pharmacies.AddAsync(pharmacy);
     131            _context.SaveChanges();
    132132        }
    133133
    134134        public async Task AddPharmacyHead(PharmacyHead pharmacyHead)
    135135        {
    136             await Task.Run(() => _context.PharmacyHeads.Add(pharmacyHead));
    137             await _context.SaveChangesAsync();
     136            await _context.PharmacyHeads.AddAsync(pharmacyHead);
     137            _context.SaveChanges();
    138138        }
    139139
    140140        public async Task AddMedicines(Medicine medicine)
    141141        {
    142             await Task.Run(() => _context.Medicines.Add(medicine));
    143             await _context.SaveChangesAsync();
     142            await _context.Medicines.AddAsync(medicine);
     143            _context.SaveChanges();
    144144        }
    145145
    146146        public async Task AddPandemic(Pandemic pandemic)
    147147        {
    148             await Task.Run(() => _context.Pandemics.Add(pandemic));
    149             await _context.SaveChangesAsync();
     148            var pand = await _context.Pandemics.AddAsync(pandemic);
     149            _context.SaveChanges();
    150150        }
    151151
    152152        public async Task UpdateFacility(HealthFacility healthFacility)
    153153        {
    154             var Facility = await Task.Run(() => _context.HealthFacilities.Where(x => x.Id == healthFacility.Id).FirstOrDefault());
     154            var Facility = await _context.HealthFacilities.Where(x => x.Id == healthFacility.Id).FirstOrDefaultAsync();
    155155            Facility.Address = healthFacility.Address;
    156156            Facility.Email = healthFacility.Email;
     
    159159            Facility.Phone = healthFacility.Phone;
    160160            Facility.Type = healthFacility.Type;
    161             await _context.SaveChangesAsync();
     161            _context.SaveChanges();
    162162        }
    163163
     
    165165        {
    166166            await Task.Run(() => _context.Medicines.Remove(medicine));
    167             await _context.SaveChangesAsync();
     167            _context.SaveChanges();
    168168        }
    169169
    170170        public async Task UpdatePandemic(Pandemic pandemic)
    171171        {
    172             var Pandemic = await Task.Run(() => _context.Pandemics.Where(x => x.Id == pandemic.Id).FirstOrDefault());
     172            var Pandemic = await _context.Pandemics.Where(x => x.Id == pandemic.Id).FirstOrDefaultAsync();
    173173            Pandemic.ActiveGlobal = pandemic.ActiveGlobal;
    174174            Pandemic.ActiveMK = pandemic.ActiveMK;
     
    179179            Pandemic.TotalGlobal = pandemic.TotalGlobal;
    180180            Pandemic.TotalMK = pandemic.TotalMK;
    181             await _context.SaveChangesAsync();
     181            _context.SaveChanges();
    182182        }
    183183
     
    185185        {
    186186            await Task.Run(() => _context.Pharmacies.Remove(pharmacy));
    187             await _context.SaveChangesAsync();
     187            _context.SaveChanges();
    188188        }
    189189        //not impl
     
    195195        public async Task UpadatePharmacy(Pharmacy pharmacy)
    196196        {
    197             var Pharmacy = await Task.Run(() => _context.Pharmacies.Where(x => x.Id == pharmacy.Id).FirstOrDefault());
     197            var Pharmacy = await _context.Pharmacies.Where(x => x.Id == pharmacy.Id).FirstOrDefaultAsync();
    198198            Pharmacy.Name = pharmacy.Name;
    199199            Pharmacy.Location = pharmacy.Location;
    200200            Pharmacy.WorkAllTime = pharmacy.WorkAllTime;
    201201            Pharmacy.Address = pharmacy.Address;
    202             await _context.SaveChangesAsync();
     202            _context.SaveChanges();
    203203        }
    204204        //ke vidime
     
    212212            var PHead = await _context.PharmacyHeads.Where(x => x.Id == Id).FirstOrDefaultAsync();
    213213            PHead.DeletedOn = DateTime.UtcNow;
    214             await _context.SaveChangesAsync();
    215         }
    216 
     214            _context.SaveChanges();
     215        }
     216
     217        public IDictionary<string, User> GetUsers()
     218        {
     219            var users = _context.Users.ToDictionary(x => x.Email, x => new User
     220            {
     221                Id = x.Id,
     222                Name = x.Name,
     223                Email = x.Email,
     224                Password = x.Password,
     225                UserRole = x.UserRole
     226            });
     227            return users;
     228        }
    217229    }
    218230}
  • FarmatikoData/FarmatikoRepoInterfaces/IAdminRepo.cs

    r1f4846d rd23bf72  
    1212        Task<IEnumerable<RequestPharmacyHead>> GetClaimingRequests();
    1313        Task<IEnumerable<PharmacyHead>> GetPharmacyHeads();
    14         void RemoveClaimRequest(RequestPharmacyHead req);
     14        void RemoveClaimRequest(int Id);
    1515    }
    1616}
  • FarmatikoData/FarmatikoRepoInterfaces/IPHRepo.cs

    r1f4846d rd23bf72  
    1717        Task Remove(PharmacyHead phead);
    1818        Task RemoveClaimingRequest(int id);
     19        PharmacyHead GetPharmacyHeadByUserName(string userName);
    1920    }
    2021}
  • FarmatikoData/FarmatikoRepoInterfaces/IRepository.cs

    r1f4846d rd23bf72  
    2424        Task<IEnumerable<Pharmacy>> SearchPharmacies(string query);
    2525        Task<IEnumerable<HealthcareWorker>> SearchWorkers(string query);
    26         Task<HealthFacility> GetFacilityJSON(string healthFacility);
     26        HealthFacility GetFacilityJSON(string healthFacility);
     27        IDictionary<string, User> GetUsers();
    2728
    2829        //POST
  • FarmatikoData/Migrations/20201104230858_InitialMigration.cs

    r1f4846d rd23bf72  
    55namespace FarmatikoData.Migrations
    66{
    7     public partial class Initialmigration : Migration
     7    public partial class InitialMigration : Migration
    88    {
    99        protected override void Up(MigrationBuilder migrationBuilder)
     
    1515                    Id = table.Column<int>(nullable: false)
    1616                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
    17                     CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: "now()"),
     17                    CreatedOn = table.Column<DateTime>(nullable: false),
    1818                    DeletedOn = table.Column<DateTime>(nullable: true),
    1919                    Name = table.Column<string>(nullable: false),
     
    2424                    Phone = table.Column<string>(nullable: true)
    2525                },
    26                 constraints: table => 
     26                constraints: table =>
    2727                {
    2828                    table.PrimaryKey("PK_HealthFacilities", x => x.Id);
     
    3030
    3131            migrationBuilder.CreateTable(
     32                name: "Medicines",
     33                columns: table => new
     34                {
     35                    Id = table.Column<int>(nullable: false)
     36                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
     37                    CreatedOn = table.Column<DateTime>(nullable: false),
     38                    DeletedOn = table.Column<DateTime>(nullable: true),
     39                    Name = table.Column<string>(nullable: false),
     40                    Strength = table.Column<string>(nullable: false),
     41                    Form = table.Column<string>(nullable: true),
     42                    WayOfIssuing = table.Column<string>(nullable: false),
     43                    Manufacturer = table.Column<string>(nullable: false),
     44                    Price = table.Column<float>(nullable: false),
     45                    Packaging = table.Column<string>(nullable: true)
     46                },
     47                constraints: table =>
     48                {
     49                    table.PrimaryKey("PK_Medicines", x => x.Id);
     50                });
     51
     52            migrationBuilder.CreateTable(
    3253                name: "Pandemics",
    3354                columns: table => new
     
    3556                    Id = table.Column<int>(nullable: false)
    3657                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
    37                     CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: "now()"),
    38                     DeletedOn = table.Column<DateTime>(nullable: true),
    39                     Name = table.Column<string>(nullable: true),
     58                    CreatedOn = table.Column<DateTime>(nullable: false),
     59                    DeletedOn = table.Column<DateTime>(nullable: true),
     60                    Name = table.Column<string>(nullable: false),
    4061                    TotalMK = table.Column<int>(nullable: false),
    4162                    ActiveMK = table.Column<int>(nullable: false),
    4263                    DeathsMK = table.Column<int>(nullable: false),
    4364                    NewMK = table.Column<int>(nullable: false),
    44                     TotalGlobal = table.Column<int>(nullable: false),
    45                     DeathsGlobal = table.Column<int>(nullable: false),
    46                     ActiveGlobal = table.Column<int>(nullable: false)
     65                    TotalGlobal = table.Column<long>(nullable: false),
     66                    DeathsGlobal = table.Column<long>(nullable: false),
     67                    ActiveGlobal = table.Column<long>(nullable: false)
    4768                },
    4869                constraints: table =>
     
    5273
    5374            migrationBuilder.CreateTable(
     75                name: "PharmacyHeads",
     76                columns: table => new
     77                {
     78                    Id = table.Column<int>(nullable: false)
     79                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
     80                    CreatedOn = table.Column<DateTime>(nullable: false),
     81                    DeletedOn = table.Column<DateTime>(nullable: true),
     82                    Email = table.Column<string>(nullable: false),
     83                    Name = table.Column<string>(nullable: false),
     84                    Password = table.Column<string>(nullable: false)
     85                },
     86                constraints: table =>
     87                {
     88                    table.PrimaryKey("PK_PharmacyHeads", x => x.Id);
     89                });
     90
     91            migrationBuilder.CreateTable(
     92                name: "Users",
     93                columns: table => new
     94                {
     95                    Id = table.Column<int>(nullable: false)
     96                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
     97                    CreatedOn = table.Column<DateTime>(nullable: false),
     98                    DeletedOn = table.Column<DateTime>(nullable: true),
     99                    Name = table.Column<string>(nullable: true),
     100                    Email = table.Column<string>(nullable: true),
     101                    Password = table.Column<string>(nullable: true),
     102                    UserRole = table.Column<int>(nullable: false)
     103                },
     104                constraints: table =>
     105                {
     106                    table.PrimaryKey("PK_Users", x => x.Id);
     107                });
     108
     109            migrationBuilder.CreateTable(
    54110                name: "HealthcareWorkers",
    55111                columns: table => new
     
    57113                    Id = table.Column<int>(nullable: false)
    58114                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
    59                     CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: "now()"),
     115                    CreatedOn = table.Column<DateTime>(nullable: false),
    60116                    DeletedOn = table.Column<DateTime>(nullable: true),
    61117                    Name = table.Column<string>(nullable: false),
     
    76132
    77133            migrationBuilder.CreateTable(
    78                 name: "Medicines",
    79                 columns: table => new
    80                 {
    81                     Id = table.Column<int>(nullable: false)
    82                         .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
    83                     CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: "now()"),
    84                     DeletedOn = table.Column<DateTime>(nullable: true),
    85                     Name = table.Column<string>(nullable: true),
    86                     Strength = table.Column<string>(nullable: true),
    87                     Form = table.Column<string>(nullable: true),
    88                     WayOfIssuing = table.Column<string>(nullable: true),
    89                     Manufacturer = table.Column<string>(nullable: true),
    90                     Price = table.Column<float>(nullable: false),
    91                     Packaging = table.Column<string>(nullable: true),
    92                     MedicineListId = table.Column<int>(nullable: true)
    93                 },
    94                 constraints: table =>
    95                 {
    96                     table.PrimaryKey("PK_Medicines", x => x.Id);
    97                 });
    98 
    99             migrationBuilder.CreateTable(
    100                 name: "PharmacyHeads",
    101                 columns: table => new
    102                 {
    103                     Id = table.Column<int>(nullable: false)
    104                         .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
    105                     CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: "now()"),
    106                     DeletedOn = table.Column<DateTime>(nullable: true),
    107                     PharmacyMedicinesId = table.Column<int>(nullable: true),
    108                     PharmacyId = table.Column<int>(nullable: true),
    109                     Email = table.Column<string>(nullable: true),
    110                     Name = table.Column<string>(nullable: true),
    111                     Password = table.Column<string>(nullable: true)
    112                 },
    113                 constraints: table =>
    114                 {
    115                     table.PrimaryKey("PK_PharmacyHeads", x => x.Id);
    116                 });
    117 
    118             migrationBuilder.CreateTable(
    119134                name: "MedicineLists",
    120135                columns: table => new
     
    122137                    Id = table.Column<int>(nullable: false)
    123138                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
    124                     CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: "now()"),
    125                     DeletedOn = table.Column<DateTime>(nullable: true),
    126                     MedicinesId = table.Column<int>(nullable: true),
     139                    CreatedOn = table.Column<DateTime>(nullable: false),
     140                    DeletedOn = table.Column<DateTime>(nullable: true),
     141                    MedicineId = table.Column<int>(nullable: false),
    127142                    HasMedicine = table.Column<bool>(nullable: false),
    128143                    PharmacyHeadId = table.Column<int>(nullable: true)
     
    132147                    table.PrimaryKey("PK_MedicineLists", x => x.Id);
    133148                    table.ForeignKey(
    134                         name: "FK_MedicineLists_Medicines_MedicinesId",
    135                         column: x => x.MedicinesId,
     149                        name: "FK_MedicineLists_Medicines_MedicineId",
     150                        column: x => x.MedicineId,
    136151                        principalTable: "Medicines",
    137152                        principalColumn: "Id",
    138                         onDelete: ReferentialAction.Restrict);
     153                        onDelete: ReferentialAction.Cascade);
    139154                    table.ForeignKey(
    140155                        name: "FK_MedicineLists_PharmacyHeads_PharmacyHeadId",
     
    151166                    Id = table.Column<int>(nullable: false)
    152167                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
    153                     CreatedOn = table.Column<DateTime>(nullable: false, defaultValueSql: "now()"),
    154                     DeletedOn = table.Column<DateTime>(nullable: true),
    155                     Name = table.Column<string>(nullable: true),
    156                     Location = table.Column<string>(nullable: true),
    157                     Address = table.Column<string>(nullable: true),
     168                    CreatedOn = table.Column<DateTime>(nullable: false),
     169                    DeletedOn = table.Column<DateTime>(nullable: true),
     170                    Name = table.Column<string>(nullable: false),
     171                    Location = table.Column<string>(nullable: false),
     172                    Address = table.Column<string>(nullable: false),
    158173                    WorkAllTime = table.Column<bool>(nullable: false),
    159174                    PharmacyHeadId = table.Column<int>(nullable: true)
     
    170185                });
    171186
     187            migrationBuilder.CreateTable(
     188                name: "PHRequests",
     189                columns: table => new
     190                {
     191                    Id = table.Column<int>(nullable: false)
     192                        .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
     193                    CreatedOn = table.Column<DateTime>(nullable: false),
     194                    DeletedOn = table.Column<DateTime>(nullable: true),
     195                    HeadId = table.Column<int>(nullable: false),
     196                    PharmacyId = table.Column<int>(nullable: false)
     197                },
     198                constraints: table =>
     199                {
     200                    table.PrimaryKey("PK_PHRequests", x => x.Id);
     201                    table.ForeignKey(
     202                        name: "FK_PHRequests_PharmacyHeads_HeadId",
     203                        column: x => x.HeadId,
     204                        principalTable: "PharmacyHeads",
     205                        principalColumn: "Id",
     206                        onDelete: ReferentialAction.Cascade);
     207                    table.ForeignKey(
     208                        name: "FK_PHRequests_Pharmacies_PharmacyId",
     209                        column: x => x.PharmacyId,
     210                        principalTable: "Pharmacies",
     211                        principalColumn: "Id",
     212                        onDelete: ReferentialAction.Cascade);
     213                });
     214
    172215            migrationBuilder.CreateIndex(
    173216                name: "IX_HealthcareWorkers_FacilityId",
     
    176219
    177220            migrationBuilder.CreateIndex(
    178                 name: "IX_MedicineLists_MedicinesId",
     221                name: "IX_MedicineLists_MedicineId",
    179222                table: "MedicineLists",
    180                 column: "MedicinesId");
     223                column: "MedicineId");
    181224
    182225            migrationBuilder.CreateIndex(
     
    186229
    187230            migrationBuilder.CreateIndex(
    188                 name: "IX_Medicines_MedicineListId",
    189                 table: "Medicines",
    190                 column: "MedicineListId");
    191 
    192             migrationBuilder.CreateIndex(
    193231                name: "IX_Pharmacies_PharmacyHeadId",
    194232                table: "Pharmacies",
     
    196234
    197235            migrationBuilder.CreateIndex(
    198                 name: "IX_PharmacyHeads_PharmacyId",
    199                 table: "PharmacyHeads",
     236                name: "IX_PHRequests_HeadId",
     237                table: "PHRequests",
     238                column: "HeadId");
     239
     240            migrationBuilder.CreateIndex(
     241                name: "IX_PHRequests_PharmacyId",
     242                table: "PHRequests",
    200243                column: "PharmacyId");
    201 
    202             migrationBuilder.CreateIndex(
    203                 name: "IX_PharmacyHeads_PharmacyMedicinesId",
    204                 table: "PharmacyHeads",
    205                 column: "PharmacyMedicinesId");
    206 
    207             migrationBuilder.AddForeignKey(
    208                 name: "FK_Medicines_MedicineLists_MedicineListId",
    209                 table: "Medicines",
    210                 column: "MedicineListId",
    211                 principalTable: "MedicineLists",
    212                 principalColumn: "Id",
    213                 onDelete: ReferentialAction.Restrict);
    214 
    215             migrationBuilder.AddForeignKey(
    216                 name: "FK_PharmacyHeads_MedicineLists_PharmacyMedicinesId",
    217                 table: "PharmacyHeads",
    218                 column: "PharmacyMedicinesId",
    219                 principalTable: "MedicineLists",
    220                 principalColumn: "Id",
    221                 onDelete: ReferentialAction.Restrict);
    222 
    223             migrationBuilder.AddForeignKey(
    224                 name: "FK_PharmacyHeads_Pharmacies_PharmacyId",
    225                 table: "PharmacyHeads",
    226                 column: "PharmacyId",
    227                 principalTable: "Pharmacies",
    228                 principalColumn: "Id",
    229                 onDelete: ReferentialAction.Restrict);
    230244        }
    231245
    232246        protected override void Down(MigrationBuilder migrationBuilder)
    233247        {
    234             migrationBuilder.DropForeignKey(
    235                 name: "FK_MedicineLists_Medicines_MedicinesId",
    236                 table: "MedicineLists");
    237 
    238             migrationBuilder.DropForeignKey(
    239                 name: "FK_MedicineLists_PharmacyHeads_PharmacyHeadId",
    240                 table: "MedicineLists");
    241 
    242             migrationBuilder.DropForeignKey(
    243                 name: "FK_Pharmacies_PharmacyHeads_PharmacyHeadId",
    244                 table: "Pharmacies");
    245 
    246248            migrationBuilder.DropTable(
    247249                name: "HealthcareWorkers");
    248250
    249251            migrationBuilder.DropTable(
     252                name: "MedicineLists");
     253
     254            migrationBuilder.DropTable(
    250255                name: "Pandemics");
    251256
    252257            migrationBuilder.DropTable(
     258                name: "PHRequests");
     259
     260            migrationBuilder.DropTable(
     261                name: "Users");
     262
     263            migrationBuilder.DropTable(
    253264                name: "HealthFacilities");
    254265
     
    257268
    258269            migrationBuilder.DropTable(
     270                name: "Pharmacies");
     271
     272            migrationBuilder.DropTable(
    259273                name: "PharmacyHeads");
    260 
    261             migrationBuilder.DropTable(
    262                 name: "Pharmacies");
    263 
    264             migrationBuilder.DropTable(
    265                 name: "MedicineLists");
    266274        }
    267275    }
  • FarmatikoData/Migrations/20201105055526_NewMigration.Designer.cs

    r1f4846d rd23bf72  
    1111{
    1212    [DbContext(typeof(FarmatikoDataContext))]
    13     [Migration("20200722131856_Initial migration")]
    14     partial class Initialmigration
     13    [Migration("20201105055526_NewMigration")]
     14    partial class NewMigration
    1515    {
    1616        protected override void BuildTargetModel(ModelBuilder modelBuilder)
     
    2222                .HasAnnotation("Relational:MaxIdentifierLength", 63);
    2323
    24             modelBuilder.Entity("FarmatikoData.Models.HealthFacilities", b =>
     24            modelBuilder.Entity("FarmatikoData.Models.HealthFacility", b =>
    2525                {
    2626                    b.Property<int>("Id")
     
    3636                        .HasColumnType("timestamp without time zone");
    3737
    38                     b.Property<DateTime>("DeletedOn")
     38                    b.Property<DateTime?>("DeletedOn")
    3939                        .HasColumnType("timestamp without time zone");
    4040
     
    6262                });
    6363
    64             modelBuilder.Entity("FarmatikoData.Models.HealthcareWorkers", b =>
     64            modelBuilder.Entity("FarmatikoData.Models.HealthcareWorker", b =>
    6565                {
    6666                    b.Property<int>("Id")
     
    7676                        .HasColumnType("timestamp without time zone");
    7777
    78                     b.Property<DateTime>("DeletedOn")
     78                    b.Property<DateTime?>("DeletedOn")
    7979                        .HasColumnType("timestamp without time zone");
    8080
     
    106106                        .HasColumnType("timestamp without time zone");
    107107
    108                     b.Property<DateTime>("DeletedOn")
     108                    b.Property<DateTime?>("DeletedOn")
    109109                        .HasColumnType("timestamp without time zone");
    110110
     
    113113
    114114                    b.Property<string>("Manufacturer")
    115                         .HasColumnType("text");
    116 
    117                     b.Property<int?>("MedicineListId")
    118                         .HasColumnType("integer");
    119 
    120                     b.Property<string>("Name")
     115                        .IsRequired()
     116                        .HasColumnType("text");
     117
     118                    b.Property<string>("Name")
     119                        .IsRequired()
    121120                        .HasColumnType("text");
    122121
     
    128127
    129128                    b.Property<string>("Strength")
     129                        .IsRequired()
    130130                        .HasColumnType("text");
    131131
    132132                    b.Property<string>("WayOfIssuing")
    133                         .HasColumnType("text");
    134 
    135                     b.HasKey("Id");
    136 
    137                     b.HasIndex("MedicineListId");
     133                        .IsRequired()
     134                        .HasColumnType("text");
     135
     136                    b.HasKey("Id");
    138137
    139138                    b.ToTable("Medicines");
     
    150149                        .HasColumnType("timestamp without time zone");
    151150
    152                     b.Property<DateTime>("DeletedOn")
     151                    b.Property<DateTime?>("DeletedOn")
    153152                        .HasColumnType("timestamp without time zone");
    154153
     
    156155                        .HasColumnType("boolean");
    157156
    158                     b.Property<int?>("MedicinesId")
     157                    b.Property<int>("MedicineId")
    159158                        .HasColumnType("integer");
    160159
     
    164163                    b.HasKey("Id");
    165164
    166                     b.HasIndex("MedicinesId");
     165                    b.HasIndex("MedicineId");
    167166
    168167                    b.HasIndex("PharmacyHeadId");
     
    178177                        .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
    179178
    180                     b.Property<int>("ActiveGlobal")
    181                         .HasColumnType("integer");
     179                    b.Property<long>("ActiveGlobal")
     180                        .HasColumnType("bigint");
    182181
    183182                    b.Property<int>("ActiveMK")
     
    187186                        .HasColumnType("timestamp without time zone");
    188187
    189                     b.Property<int>("DeathsGlobal")
    190                         .HasColumnType("integer");
     188                    b.Property<long>("DeathsGlobal")
     189                        .HasColumnType("bigint");
    191190
    192191                    b.Property<int>("DeathsMK")
    193192                        .HasColumnType("integer");
    194193
    195                     b.Property<DateTime>("DeletedOn")
    196                         .HasColumnType("timestamp without time zone");
    197 
    198                     b.Property<string>("Name")
     194                    b.Property<DateTime?>("DeletedOn")
     195                        .HasColumnType("timestamp without time zone");
     196
     197                    b.Property<string>("Name")
     198                        .IsRequired()
    199199                        .HasColumnType("text");
    200200
     
    202202                        .HasColumnType("integer");
    203203
    204                     b.Property<int>("TotalGlobal")
    205                         .HasColumnType("integer");
     204                    b.Property<long>("TotalGlobal")
     205                        .HasColumnType("bigint");
    206206
    207207                    b.Property<int>("TotalMK")
     
    221221
    222222                    b.Property<string>("Address")
    223                         .HasColumnType("text");
    224 
    225                     b.Property<DateTime>("CreatedOn")
    226                         .HasColumnType("timestamp without time zone");
    227 
    228                     b.Property<DateTime>("DeletedOn")
     223                        .IsRequired()
     224                        .HasColumnType("text");
     225
     226                    b.Property<DateTime>("CreatedOn")
     227                        .HasColumnType("timestamp without time zone");
     228
     229                    b.Property<DateTime?>("DeletedOn")
    229230                        .HasColumnType("timestamp without time zone");
    230231
    231232                    b.Property<string>("Location")
    232                         .HasColumnType("text");
    233 
    234                     b.Property<string>("Name")
     233                        .IsRequired()
     234                        .HasColumnType("text");
     235
     236                    b.Property<string>("Name")
     237                        .IsRequired()
    235238                        .HasColumnType("text");
    236239
     
    258261                        .HasColumnType("timestamp without time zone");
    259262
    260                     b.Property<DateTime>("DeletedOn")
     263                    b.Property<DateTime?>("DeletedOn")
    261264                        .HasColumnType("timestamp without time zone");
    262265
    263266                    b.Property<string>("Email")
    264                         .HasColumnType("text");
    265 
    266                     b.Property<string>("Name")
     267                        .IsRequired()
     268                        .HasColumnType("text");
     269
     270                    b.Property<string>("Name")
     271                        .IsRequired()
    267272                        .HasColumnType("text");
    268273
    269274                    b.Property<string>("Password")
    270                         .HasColumnType("text");
    271 
    272                     b.Property<int?>("PharmacyId")
    273                         .HasColumnType("integer");
    274 
    275                     b.Property<int?>("PharmacyMedicinesId")
    276                         .HasColumnType("integer");
    277 
    278                     b.HasKey("Id");
     275                        .IsRequired()
     276                        .HasColumnType("text");
     277
     278                    b.HasKey("Id");
     279
     280                    b.ToTable("PharmacyHeads");
     281                });
     282
     283            modelBuilder.Entity("FarmatikoData.Models.RequestPharmacyHead", b =>
     284                {
     285                    b.Property<int>("Id")
     286                        .ValueGeneratedOnAdd()
     287                        .HasColumnType("integer")
     288                        .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
     289
     290                    b.Property<DateTime>("CreatedOn")
     291                        .HasColumnType("timestamp without time zone");
     292
     293                    b.Property<DateTime?>("DeletedOn")
     294                        .HasColumnType("timestamp without time zone");
     295
     296                    b.Property<int>("HeadId")
     297                        .HasColumnType("integer");
     298
     299                    b.Property<int>("PharmacyId")
     300                        .HasColumnType("integer");
     301
     302                    b.HasKey("Id");
     303
     304                    b.HasIndex("HeadId");
    279305
    280306                    b.HasIndex("PharmacyId");
    281307
    282                     b.HasIndex("PharmacyMedicinesId");
    283 
    284                     b.ToTable("PharmacyHeads");
    285                 });
    286 
    287             modelBuilder.Entity("FarmatikoData.Models.HealthcareWorkers", b =>
    288                 {
    289                     b.HasOne("FarmatikoData.Models.HealthFacilities", "Facility")
     308                    b.ToTable("PHRequests");
     309                });
     310
     311            modelBuilder.Entity("FarmatikoData.Models.User", b =>
     312                {
     313                    b.Property<int>("Id")
     314                        .ValueGeneratedOnAdd()
     315                        .HasColumnType("integer")
     316                        .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
     317
     318                    b.Property<DateTime>("CreatedOn")
     319                        .HasColumnType("timestamp without time zone");
     320
     321                    b.Property<DateTime?>("DeletedOn")
     322                        .HasColumnType("timestamp without time zone");
     323
     324                    b.Property<string>("Email")
     325                        .HasColumnType("text");
     326
     327                    b.Property<string>("Name")
     328                        .HasColumnType("text");
     329
     330                    b.Property<string>("Password")
     331                        .HasColumnType("text");
     332
     333                    b.Property<int>("UserRole")
     334                        .HasColumnType("integer");
     335
     336                    b.HasKey("Id");
     337
     338                    b.ToTable("Users");
     339                });
     340
     341            modelBuilder.Entity("FarmatikoData.Models.HealthcareWorker", b =>
     342                {
     343                    b.HasOne("FarmatikoData.Models.HealthFacility", "Facility")
    290344                        .WithMany()
    291345                        .HasForeignKey("FacilityId")
     
    294348                });
    295349
    296             modelBuilder.Entity("FarmatikoData.Models.Medicine", b =>
    297                 {
    298                     b.HasOne("FarmatikoData.Models.MedicineList", null)
    299                         .WithMany("MedicinesList")
    300                         .HasForeignKey("MedicineListId");
    301                 });
    302 
    303350            modelBuilder.Entity("FarmatikoData.Models.MedicineList", b =>
    304351                {
    305                     b.HasOne("FarmatikoData.Models.Medicine", "Medicines")
     352                    b.HasOne("FarmatikoData.Models.Medicine", "Medicine")
    306353                        .WithMany()
    307                         .HasForeignKey("MedicinesId");
     354                        .HasForeignKey("MedicineId")
     355                        .OnDelete(DeleteBehavior.Cascade)
     356                        .IsRequired();
    308357
    309358                    b.HasOne("FarmatikoData.Models.PharmacyHead", null)
     
    319368                });
    320369
    321             modelBuilder.Entity("FarmatikoData.Models.PharmacyHead", b =>
    322                 {
     370            modelBuilder.Entity("FarmatikoData.Models.RequestPharmacyHead", b =>
     371                {
     372                    b.HasOne("FarmatikoData.Models.PharmacyHead", "Head")
     373                        .WithMany()
     374                        .HasForeignKey("HeadId")
     375                        .OnDelete(DeleteBehavior.Cascade)
     376                        .IsRequired();
     377
    323378                    b.HasOne("FarmatikoData.Models.Pharmacy", "Pharmacy")
    324379                        .WithMany()
    325                         .HasForeignKey("PharmacyId");
    326 
    327                     b.HasOne("FarmatikoData.Models.MedicineList", "PharmacyMedicines")
    328                         .WithMany()
    329                         .HasForeignKey("PharmacyMedicinesId");
     380                        .HasForeignKey("PharmacyId")
     381                        .OnDelete(DeleteBehavior.Cascade)
     382                        .IsRequired();
    330383                });
    331384#pragma warning restore 612, 618
  • FarmatikoData/Migrations/FarmatikoDataContextModelSnapshot.cs

    r1f4846d rd23bf72  
    2020                .HasAnnotation("Relational:MaxIdentifierLength", 63);
    2121
    22             modelBuilder.Entity("FarmatikoData.Models.HealthFacilities", b =>
     22            modelBuilder.Entity("FarmatikoData.Models.HealthFacility", b =>
    2323                {
    2424                    b.Property<int>("Id")
     
    6060                });
    6161
    62             modelBuilder.Entity("FarmatikoData.Models.HealthcareWorkers", b =>
     62            modelBuilder.Entity("FarmatikoData.Models.HealthcareWorker", b =>
    6363                {
    6464                    b.Property<int>("Id")
     
    111111
    112112                    b.Property<string>("Manufacturer")
    113                         .HasColumnType("text");
    114 
    115                     b.Property<string>("Name")
     113                        .IsRequired()
     114                        .HasColumnType("text");
     115
     116                    b.Property<string>("Name")
     117                        .IsRequired()
    116118                        .HasColumnType("text");
    117119
     
    123125
    124126                    b.Property<string>("Strength")
     127                        .IsRequired()
    125128                        .HasColumnType("text");
    126129
    127130                    b.Property<string>("WayOfIssuing")
     131                        .IsRequired()
    128132                        .HasColumnType("text");
    129133
     
    149153                        .HasColumnType("boolean");
    150154
    151                     b.Property<int?>("MedicineId")
     155                    b.Property<int>("MedicineId")
    152156                        .HasColumnType("integer");
    153157
     
    190194
    191195                    b.Property<string>("Name")
     196                        .IsRequired()
    192197                        .HasColumnType("text");
    193198
     
    214219
    215220                    b.Property<string>("Address")
     221                        .IsRequired()
    216222                        .HasColumnType("text");
    217223
     
    223229
    224230                    b.Property<string>("Location")
    225                         .HasColumnType("text");
    226 
    227                     b.Property<string>("Name")
     231                        .IsRequired()
     232                        .HasColumnType("text");
     233
     234                    b.Property<string>("Name")
     235                        .IsRequired()
    228236                        .HasColumnType("text");
    229237
     
    255263
    256264                    b.Property<string>("Email")
    257                         .HasColumnType("text");
    258 
    259                     b.Property<string>("Name")
     265                        .IsRequired()
     266                        .HasColumnType("text");
     267
     268                    b.Property<string>("Name")
     269                        .IsRequired()
    260270                        .HasColumnType("text");
    261271
    262272                    b.Property<string>("Password")
    263                         .HasColumnType("text");
    264 
    265                     b.Property<int?>("PharmacyId")
    266                         .HasColumnType("integer");
    267 
    268                     b.Property<int?>("PharmacyMedicinesId")
    269                         .HasColumnType("integer");
    270 
    271                     b.HasKey("Id");
     273                        .IsRequired()
     274                        .HasColumnType("text");
     275
     276                    b.HasKey("Id");
     277
     278                    b.ToTable("PharmacyHeads");
     279                });
     280
     281            modelBuilder.Entity("FarmatikoData.Models.RequestPharmacyHead", b =>
     282                {
     283                    b.Property<int>("Id")
     284                        .ValueGeneratedOnAdd()
     285                        .HasColumnType("integer")
     286                        .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
     287
     288                    b.Property<DateTime>("CreatedOn")
     289                        .HasColumnType("timestamp without time zone");
     290
     291                    b.Property<DateTime?>("DeletedOn")
     292                        .HasColumnType("timestamp without time zone");
     293
     294                    b.Property<int>("HeadId")
     295                        .HasColumnType("integer");
     296
     297                    b.Property<int>("PharmacyId")
     298                        .HasColumnType("integer");
     299
     300                    b.HasKey("Id");
     301
     302                    b.HasIndex("HeadId");
    272303
    273304                    b.HasIndex("PharmacyId");
    274305
    275                     b.HasIndex("PharmacyMedicinesId");
    276 
    277                     b.ToTable("PharmacyHeads");
    278                 });
    279 
    280             modelBuilder.Entity("FarmatikoData.Models.HealthcareWorkers", b =>
    281                 {
    282                     b.HasOne("FarmatikoData.Models.HealthFacilities", "Facility")
     306                    b.ToTable("PHRequests");
     307                });
     308
     309            modelBuilder.Entity("FarmatikoData.Models.User", b =>
     310                {
     311                    b.Property<int>("Id")
     312                        .ValueGeneratedOnAdd()
     313                        .HasColumnType("integer")
     314                        .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
     315
     316                    b.Property<DateTime>("CreatedOn")
     317                        .HasColumnType("timestamp without time zone");
     318
     319                    b.Property<DateTime?>("DeletedOn")
     320                        .HasColumnType("timestamp without time zone");
     321
     322                    b.Property<string>("Email")
     323                        .HasColumnType("text");
     324
     325                    b.Property<string>("Name")
     326                        .HasColumnType("text");
     327
     328                    b.Property<string>("Password")
     329                        .HasColumnType("text");
     330
     331                    b.Property<int>("UserRole")
     332                        .HasColumnType("integer");
     333
     334                    b.HasKey("Id");
     335
     336                    b.ToTable("Users");
     337                });
     338
     339            modelBuilder.Entity("FarmatikoData.Models.HealthcareWorker", b =>
     340                {
     341                    b.HasOne("FarmatikoData.Models.HealthFacility", "Facility")
    283342                        .WithMany()
    284343                        .HasForeignKey("FacilityId")
     
    291350                    b.HasOne("FarmatikoData.Models.Medicine", "Medicine")
    292351                        .WithMany()
    293                         .HasForeignKey("MedicineId");
     352                        .HasForeignKey("MedicineId")
     353                        .OnDelete(DeleteBehavior.Cascade)
     354                        .IsRequired();
    294355
    295356                    b.HasOne("FarmatikoData.Models.PharmacyHead", null)
     
    305366                });
    306367
    307             modelBuilder.Entity("FarmatikoData.Models.PharmacyHead", b =>
    308                 {
     368            modelBuilder.Entity("FarmatikoData.Models.RequestPharmacyHead", b =>
     369                {
     370                    b.HasOne("FarmatikoData.Models.PharmacyHead", "Head")
     371                        .WithMany()
     372                        .HasForeignKey("HeadId")
     373                        .OnDelete(DeleteBehavior.Cascade)
     374                        .IsRequired();
     375
    309376                    b.HasOne("FarmatikoData.Models.Pharmacy", "Pharmacy")
    310377                        .WithMany()
    311                         .HasForeignKey("PharmacyId");
    312 
    313                     b.HasOne("FarmatikoData.Models.MedicineList", "PharmacyMedicines")
    314                         .WithMany()
    315                         .HasForeignKey("PharmacyMedicinesId");
     378                        .HasForeignKey("PharmacyId")
     379                        .OnDelete(DeleteBehavior.Cascade)
     380                        .IsRequired();
    316381                });
    317382#pragma warning restore 612, 618
  • FarmatikoData/Models/PharmacyHead.cs

    r1f4846d rd23bf72  
    1616        [Required]
    1717        public string Password { get; set; }
    18         public ICollection<MedicineList> MedicineLists { get; set; }
    19         public ICollection<Pharmacy> PharmaciesList { get; set; }
     18        public List<MedicineList> MedicineLists { get; set; }
     19        public List<Pharmacy> PharmaciesList { get; set; }
    2020
    2121    }
  • FarmatikoServices/FarmatikoServiceInterfaces/IAdminService.cs

    r1f4846d rd23bf72  
    1212        Task<IEnumerable<PharmacyHead>> GetPharmacyHeads();
    1313        Task<IEnumerable<RequestPharmacyHead>> GetClaimingRequests();
    14         bool RejectRequest(RequestPharmacyHead req);
     14        bool RejectRequest(int Id);
    1515    }
    1616}
  • FarmatikoServices/FarmatikoServiceInterfaces/IPHService.cs

    r1f4846d rd23bf72  
    1010    public interface IPHService
    1111    {
    12         Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo(string Token);
     12        Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo();
    1313        Task UpdatePharmacyHead(PharmacyHead pharmacyHead);
    1414        Task<int> Login(PharmacyHead pharmacyHead);
     
    1818        Task<bool> Remove(int id);
    1919        Task<bool> RemoveClaimingRequest(int id);
     20        PharmacyHead GetPharmacyHead(string userName);
    2021    }
    2122}
  • FarmatikoServices/FarmatikoServiceInterfaces/IProcessJSONService.cs

    r1f4846d rd23bf72  
    99    public interface IProcessJSONService
    1010    {
    11         Task<HealthFacility> GetProcessedHealthFacilitiesFromJSON();
    12         Task<Pandemic> GetProcessedPandemicsFromJSONApi();
    13         Task<HealthcareWorker> GetProcessedHealthcareWorkersFromJSON();
    14         Task<Medicine> GetProcessedMedicinesFromJSON();
    15         Task<Medicine> ReadPharmaciesFromExcel();
     11        void GetProcessedHealthFacilitiesFromJSON();
     12        void GetProcessedPandemicsFromJSONApi();
     13        void GetProcessedHealthcareWorkersFromJSON();
     14        void GetProcessedMedicinesFromJSON();
     15        void DownloadPharmaciesExcel();
    1616    }
    1717}
  • FarmatikoServices/FarmatikoServiceInterfaces/IService.cs

    r1f4846d rd23bf72  
    1515        Task<IEnumerable<HealthFacility>> SearchFacilities(string query);
    1616        Task<HealthFacility> GetFacility(int id);
    17         Task<HealthFacility> GetFacilityJSON(string healthFacility);
     17        HealthFacility GetFacilityJSON(string healthFacility);
    1818        Task<Medicine> GetMedicine(int id);
    1919        Task<IEnumerable<Medicine>> SearchMedicines(string query);
  • FarmatikoServices/FarmatikoServices.csproj

    r1f4846d rd23bf72  
    66
    77  <ItemGroup>
     8    <PackageReference Include="AngleSharp" Version="0.14.0" />
    89    <PackageReference Include="EPPlus" Version="5.4.0" />
     10    <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
    911    <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
    10     <PackageReference Include="RestSharp" Version="106.11.4" />
     12    <PackageReference Include="RestSharp" Version="106.11.7" />
     13    <PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="6.8.0" />
    1114  </ItemGroup>
    1215
     
    1518  </ItemGroup>
    1619
     20  <ItemGroup>
     21    <Folder Include="Services\ExcellDocs\" />
     22  </ItemGroup>
     23
    1724</Project>
  • FarmatikoServices/Services/AdminService.cs

    r1f4846d rd23bf72  
    3636        }
    3737
    38         public bool RejectRequest(RequestPharmacyHead req)
     38        public bool RejectRequest(int Id)
    3939        {
    40             if (req != null)
     40            if (Id >= 0)
    4141            {
    42                 _adminRepo.RemoveClaimRequest(req);
     42                _adminRepo.RemoveClaimRequest(Id);
    4343                return true;
    4444            }
  • FarmatikoServices/Services/PHService.cs

    r1f4846d rd23bf72  
    3838        }
    3939
    40         public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo(string Token)
     40        public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo()
    4141        {
    4242            var PHeads = await _iPHRepo.GetPharmacyHeadInfo();
     
    9292            return false;
    9393        }
     94
     95        public PharmacyHead GetPharmacyHead(string userName)
     96        {
     97            if (userName != null)
     98            {
     99                return _iPHRepo.GetPharmacyHeadByUserName(userName);
     100            }
     101            return default;
     102        }
    94103    }
    95104}
  • FarmatikoServices/Services/ProcessJSONService.cs

    r1f4846d rd23bf72  
    1313using OfficeOpenXml;
    1414using System.IO;
     15using Microsoft.VisualBasic;
    1516
    1617namespace FarmatikoServices.Services
     
    2627            _service = service;
    2728        }
    28 
    29         public async Task<Medicine> ReadPharmaciesFromExcel()
    30         {
    31             try
    32             {
    33                 var client = new WebClient();
    34                 string Path = client.DownloadString(@"C:\Users\dslez\Desktop\apteki-fzo.xlsx");
    35                 using (var package = new ExcelPackage(new FileInfo(Path)))
    36                 {
    37                     var Sheet = package.Workbook.Worksheets[1];
    38                     for (int i = 2; i < Sheet.Dimension.End.Row; ++i)
     29        //Excel reader
     30        private async Task<bool> ReadPharmaciesFromExcel(string Path)
     31        {
     32            using (var package = new ExcelPackage(new FileInfo(Path)))
     33            {
     34                var Sheet = package.Workbook.Worksheets[1];
     35                for (int i = 2; i < Sheet.Dimension.End.Row; ++i)
     36                {
     37                    Pharmacy pharmacy = new Pharmacy()
    3938                    {
    40                         Pharmacy pharmacy = new Pharmacy()
    41                         {
    42                             Name = Sheet.Cells[i, 2].Value.ToString(),
    43                             Address = Sheet.Cells[i, 3].Value.ToString(),
    44                             Location = Sheet.Cells[i, 4].Value.ToString(),
    45                             WorkAllTime = false
    46                         };
    47                         await _service.AddPharmacy(pharmacy);
    48                     }
    49                 }
    50 
    51             }
    52             catch(Exception e)
     39                        Name = Sheet.Cells[i, 2].Value.ToString(),
     40                        Address = Sheet.Cells[i, 3].Value.ToString(),
     41                        Location = Sheet.Cells[i, 4].Value.ToString(),
     42                        WorkAllTime = false
     43                    };
     44                    await _service.AddPharmacy(pharmacy);
     45                    return true;
     46                }
     47            }
     48            return false;
     49        }
     50        public async void DownloadPharmaciesExcel()
     51        {
     52            try
     53            {
     54                string pathToSave1 = Directory.GetCurrentDirectory() + @"\ExcellDocs\1.xlsx";
     55
     56                string pathToSave2 = Directory.GetCurrentDirectory() + @"\ExcellDocs\2.xlsx";
     57                var client = new WebClient();
     58                string url1 = "http://data.gov.mk/dataset/d84c31d9-e749-4b17-9faf-a5b4db3e7a70/resource/ce446f5c-e541-46f6-9e8c-67568059cbc6/download/registar-na-apteki-vnatre-vo-mreza-na-fzo-12.08.2020.xlsx";
     59                string url2 = "http://data.gov.mk/dataset/d84c31d9-e749-4b17-9faf-a5b4db3e7a70/resource/a16379b4-ec81-4de7-994d-0ee503d71b55/download/registar-na-apteki-nadvor-od-mreza-na-fzo-12.08.2020.xlsx";
     60                int count = 0;
     61                Uri uri1 = new Uri(url1);
     62                Uri uri2 = new Uri(url2);
     63                client.DownloadFile(uri1, @pathToSave1);
     64                client.DownloadFile(uri2, @pathToSave2);
     65
     66
     67                bool Success = await ReadPharmaciesFromExcel(pathToSave1);
     68                _logger.LogInformation(Success.ToString() + "1");
     69                Success = await ReadPharmaciesFromExcel(pathToSave2);
     70                _logger.LogInformation(Success.ToString() + "2");
     71            }
     72            catch (Exception e)
    5373            {
    5474                _logger.LogInformation(e.Message);
    5575                throw new Exception("Cannot process Medicines from Excel.");
    5676            }
    57             return null;
    58         }
    59 
    60 
    61         public async Task<HealthFacility> GetProcessedHealthFacilitiesFromJSON()
    62         {
    63             try
    64             {
    65                 var client = new WebClient();
    66                 var json = client.DownloadString(@"C:\Users\dslez\Desktop\ustanovi.json");
     77        }
     78
     79        //Healthfacilities
     80        public async void GetProcessedHealthFacilitiesFromJSON()
     81        {
     82            try
     83            {
     84                var client = new WebClient();
     85                var json = client.DownloadString(@"http://www.otvorenipodatoci.gov.mk/datastore/dump/505db453-4de2-4761-8a81-2800f7820b06?format=json");
    6786
    6887                var jsonResponse = JObject.Parse(json);
     
    7897                    var Phone = obj[11];
    7998                    var Type = obj[5];
    80                     HealthFacility healthFacility = new HealthFacility(Name, Municipality, Address, Type, Email, Phone);
    81                     await Task.Run(() => _service.AddFacility(healthFacility));
    82 
    83                 }
    84 
    85             }
    86             catch (Exception e)
    87             {
    88                 _logger.LogInformation(e.Message);
    89                 throw new Exception("Cannot process health facilities from JSON.");
    90             }
    91             return null;
    92         }
    93 
    94         public async Task<Pandemic> GetProcessedPandemicsFromJSONApi()
    95         {
    96             try
    97             {
    98                 var client = new RestClient("https://api.covid19api.com/summary");
     99                    HealthFacility healthFacility = new HealthFacility();
     100                    //Name, Municipality, Address, Type, Email, Phone
     101                    healthFacility.Name = Convert.ToString(Name);
     102                    healthFacility.Municipality = Convert.ToString(Municipality);
     103                    healthFacility.Address = Convert.ToString(Address);
     104                    healthFacility.Type = Convert.ToString(Type);
     105                    healthFacility.Email = Convert.ToString(Email);
     106                    healthFacility.Phone = Convert.ToString(Phone);
     107                    await _service.AddFacility(healthFacility);
     108
     109                }
     110
     111            }
     112            catch (Exception e)
     113            {
     114                _logger.LogInformation(e.Message);
     115                throw new Exception("Cannot process health facilities from JSON." + e.Message);
     116            }
     117        }
     118        //Pandemics
     119        public async void GetProcessedPandemicsFromJSONApi()
     120        {
     121            try
     122            {
     123                var Date = DateTime.UtcNow.ToString("yyyy-MM-dd");
     124                var client = new RestClient($"https://api.covid19tracking.narrativa.com/api/{Date}/country/north_macedonia");
    99125                var response = client.Execute(new RestRequest());
    100126                string original = response.Content;
    101127                var jsonResponsePandemic = JObject.Parse(original);
    102                 var global = JObject.Parse(jsonResponsePandemic.GetValue("Global").ToString());
    103                 var TotalConfirmed = long.Parse(global.GetValue("TotalConfirmed").ToString());
    104                 var TotalDeaths = long.Parse(global.GetValue("TotalDeaths").ToString());
    105                 var TotalRecovered = long.Parse(global.GetValue("TotalRecovered").ToString());
    106 
    107                 var mk = JArray.Parse(jsonResponsePandemic.GetValue("Countries").ToString());
    108                 dynamic objP = mk[100];
    109                 var TotalMk = Int32.Parse(objP.GetValue("TotalConfirmed").ToString());
    110                 var TotalDeathsMK = Int32.Parse(objP.GetValue("TotalDeaths").ToString());
    111                 var TotalRecoveredMK = Int32.Parse(objP.GetValue("TotalRecovered").ToString());
    112                 var NewMK = Int32.Parse(objP.GetValue("NewConfirmed").ToString());
     128                var global = JObject.Parse(jsonResponsePandemic.GetValue("total").ToString());
     129                var TotalConfirmed = long.Parse(global.GetValue("today_confirmed").ToString());
     130                var TotalDeaths = long.Parse(global.GetValue("today_deaths").ToString());
     131                var TotalRecovered = long.Parse(global.GetValue("today_new_recovered").ToString());
     132
     133                var mk = JObject.Parse(jsonResponsePandemic.GetValue("dates").ToString());
     134
     135                var date = JObject.Parse(mk.GetValue(Date).ToString());
     136                var country = JObject.Parse(date.GetValue("countries").ToString());
     137                var mkd = JObject.Parse(country.GetValue("North Macedonia").ToString());
     138                dynamic objP = mkd;
     139                var TotalMk = Int32.Parse(objP.GetValue("today_confirmed").ToString());
     140                var TotalDeathsMK = Int32.Parse(objP.GetValue("today_deaths").ToString());
     141                var TotalRecoveredMK = Int32.Parse(objP.GetValue("today_recovered").ToString());
     142                var NewMK = Int32.Parse(objP.GetValue("today_new_confirmed").ToString());
    113143
    114144                var Name = "Coronavirus";
     
    117147
    118148                Pandemic pandemic = new Pandemic(Name, TotalMk, ActiveMk, TotalDeathsMK, NewMK, TotalConfirmed, TotalDeaths, ActiveGlobal);
    119                 await Task.Run(() => _service.AddPandemic(pandemic));
    120             }
    121             catch (Exception e)
    122             {
    123                 _logger.LogInformation(e.Message);
    124             }
    125             return null;
    126         }
    127 
    128         public async Task<HealthcareWorker> GetProcessedHealthcareWorkersFromJSON()
    129         {
    130             try
    131             {
    132                 var client = new WebClient();
    133                 var jsonW = client.DownloadString(@"C:\Users\dslez\Desktop\rabotnici.json");
     149                await _service.AddPandemic(pandemic);
     150            }
     151            catch (Exception e)
     152            {
     153                _logger.LogInformation(e.Message);
     154            }
     155        }
     156        //Healthcare workers
     157        public async void GetProcessedHealthcareWorkersFromJSON()
     158        {
     159            try
     160            {
     161                var client = new WebClient();
     162                var jsonW = client.DownloadString(@"http://www.otvorenipodatoci.gov.mk/datastore/dump/5b661887-685b-4189-b6bb-9b52eb8ace16?format=json");
    134163
    135164                var jsonResponseW = JObject.Parse(jsonW);
     
    139168                {
    140169                    dynamic obj = JsonConvert.DeserializeObject(rec.ToString());
    141                     var Name = obj[4];
    142                     var Branch = obj[2];
    143                     var FacilityName = obj[1];
    144                     var Title = obj[3];
    145                     HealthFacility facility = await _service.GetFacilityJSON(FacilityName);
    146                     HealthFacility Facility = new HealthFacility(facility.Name, facility.Municipality, facility.Address,
    147                                                                         facility.Type, facility.Email, facility.Phone);
    148                     HealthcareWorker healthcareWorker = new HealthcareWorker(Name, Branch, Facility, Title);
    149                     /*Facility.Name = obj[1];
    150                     Facility.Municipality = "WorkerFacilityMunicipality";
    151                     Facility.Address = "WorkerFacilityAddress";*/
    152                     /*healthcareWorker.Name = Name;
    153                     healthcareWorker.Branch = Branch;
    154                     healthcareWorker.Facility = Facility;
    155                     healthcareWorker.Title = Title;*/
    156                     await Task.Run(() => _service.AddWorker(healthcareWorker));
    157                 }
    158             }
    159             catch (Exception e)
    160             {
    161                 _logger.LogInformation(e.Message);
    162             }
    163             return null;
    164         }
    165 
    166         public async Task<Medicine> GetProcessedMedicinesFromJSON()
    167         {
    168             try
    169             {
    170                 var client = new WebClient();
    171                 var jsonM = client.DownloadString(@"C:\Users\dslez\Desktop\lekovi.json");
     170                    var Name = Convert.ToString(obj[4]);
     171                    var Branch = Convert.ToString(obj[2]);
     172                    var FacilityName = Convert.ToString(obj[1]);
     173                    var Title = Convert.ToString(obj[3]);
     174
     175                    HealthFacility facility = _service.GetFacilityJSON(Convert.ToString(FacilityName));
     176
     177                    if (facility != null)
     178                    {
     179                        HealthFacility Facility = new HealthFacility(
     180                           facility.Name,
     181                           facility.Municipality,
     182                           facility.Address,
     183                           facility.Type,
     184                           facility.Email,
     185                           facility.Phone
     186                           );
     187                        HealthcareWorker healthcareWorker = new HealthcareWorker(Name, Branch, Facility, Title);
     188                        await _service.AddWorker(healthcareWorker);
     189                    }
     190                    else
     191                    {
     192                        HealthFacility Facility = new HealthFacility(
     193                           Convert.ToString(FacilityName),
     194                           "",
     195                           "",
     196                           Convert.ToString(Branch),
     197                           "",
     198                           ""
     199                           );
     200                        HealthcareWorker healthcareWorker = new HealthcareWorker(Name, Branch, Facility, Title);
     201                        await _service.AddWorker(healthcareWorker);
     202                    }
     203                   
     204
     205                }
     206            }
     207            catch (Exception e)
     208            {
     209                _logger.LogInformation(e.Message);
     210            }
     211        }
     212        //Medicines
     213        public async void GetProcessedMedicinesFromJSON()
     214        {
     215            try
     216            {
     217                var client = new WebClient();
     218                var jsonM = client.DownloadString(@"http://www.otvorenipodatoci.gov.mk/datastore/dump/ecff2aef-9c8e-4efd-a557-96df4fff9adb?format=json");
    172219
    173220                var jsonResponseM = JObject.Parse(jsonM);
     
    182229                    var WayOfIssuing = obj[9];
    183230                    var Manufacturer = obj[11];
    184                     var Price = float.Parse(obj[17]);
     231                    var Price = float.Parse(Convert.ToString(obj[17]));
    185232                    var Packaging = obj[8];
    186                     Medicine medicine = new Medicine(Name, Strength, Form, WayOfIssuing, Manufacturer, Price, Packaging);
    187                     /*medicine.Name = Name;
    188                     medicine.Strength = Strength;
    189                     medicine.Form = Form;
    190                     medicine.WayOfIssuing = WayOfIssuing;
    191                     medicine.Manufacturer = Manufacturer;
    192                     medicine.Price = Price;
    193                     medicine.Packaging = Packaging;*/
    194                     await Task.Run(() => _service.AddMedicines(medicine));
    195                 }
    196             }
    197             catch (Exception e)
    198             {
    199                 _logger.LogInformation(e.Message);
    200             }
    201             return null;
     233                    string price = Convert.ToString(Price);
     234                    Medicine medicine = new Medicine(Convert.ToString(Name), Convert.ToString(Strength), Convert.ToString(Form), Convert.ToString(WayOfIssuing), Convert.ToString(Manufacturer), Price, Convert.ToString(Packaging));
     235
     236                    await _service.AddMedicines(medicine);
     237                }
     238            }
     239            catch (Exception e)
     240            {
     241                _logger.LogInformation(e.Message);
     242                throw new Exception("medicine");
     243            }
    202244        }
    203245    }
  • FarmatikoServices/Services/Service.cs

    r1f4846d rd23bf72  
    103103            if (healthFacilities != null)
    104104                await _repository.AddFacility(healthFacilities);
    105             throw new Exception("Facility is null");
     105            else throw new Exception("Facility is null");
    106106        }
    107107        //za json(Sys updateer)
     
    110110            if (medicine != null)
    111111                await _repository.AddMedicines(medicine);
    112             throw new Exception("Medicine is null");
     112            else throw new Exception("Medicine is null");
    113113        }
    114114        //za json(Sys updateer)
     
    117117            if (pandemic != null)
    118118                await _repository.AddPandemic(pandemic);
    119             throw new Exception("Pandemic is null");
     119            else throw new Exception("Pandemic is null");
    120120        }
    121121        // Samo PharmacyHead i Admin imaat pristap
     
    124124            if (pharmacy != null)
    125125                await _repository.AddPharmacy(pharmacy);
    126             throw new Exception("Pharmacy is null");
     126            else throw new Exception("Pharmacy is null");
    127127        }
    128128        // Ovaa kontrola ja ima samo admin
     
    150150            if (worker != null)
    151151                await _repository.AddWorker(worker);
    152             throw new Exception("Worker is null");
     152            else throw new Exception("Worker is null");
    153153        }
    154154
     
    158158            if (healthFacilities != null)
    159159                await _repository.UpdateFacility(healthFacilities);
    160             throw new Exception("Facility is null");
     160            else throw new Exception("Facility is null");
    161161        }
    162162        //PharmacyHead
     
    165165            if (medicine != null)
    166166                await _repository.RemoveMedicine(medicine);
    167             throw new Exception("Medicine is null");
     167            else throw new Exception("Medicine is null");
    168168        }
    169169        //PharmacyHead
     
    172172            if (medicine != null)
    173173                await _repository.UpdateMedicine(medicine);
    174             throw new Exception("Medicine is null");
     174            else throw new Exception("Medicine is null");
    175175        }
    176176        //za json(Sys updateer)
     
    179179            if (pandemic != null)
    180180                await _repository.UpdatePandemic(pandemic);
    181             throw new Exception("Pandemic is null");
     181            else throw new Exception("Pandemic is null");
    182182        }
    183183        //PharmacyHead
     
    186186            if (pharmacy != null)
    187187                await _repository.RemovePharmacy(pharmacy);
    188             throw new Exception("Pharmacy is null");
     188            else throw new Exception("Pharmacy is null");
    189189        }
    190190        //PharamcyHead
     
    193193            if (pharmacy != null)
    194194                await _repository.UpadatePharmacy(pharmacy);
    195             throw new Exception("Pharmacy is null");
     195            else throw new Exception("Pharmacy is null");
    196196        }
    197197        //za json(Sys updateer)
     
    200200            if (worker != null)
    201201                await _repository.UpdateWorker(worker);
    202             throw new Exception("Worker is null");
     202            else throw new Exception("Worker is null");
    203203        }
    204204
     
    209209                await _repository.RemovePharmacyHead(Id);
    210210            }
    211             throw new Exception("Index out of bounds.");
    212         }
    213 
    214         public async Task<HealthFacility> GetFacilityJSON(string healthFacility)
     211            else throw new Exception("Index out of bounds.");
     212        }
     213
     214        public HealthFacility GetFacilityJSON(string healthFacility)
    215215        {
    216216            if (healthFacility != null)
    217                 return await _repository.GetFacilityJSON(healthFacility);
     217                return _repository.GetFacilityJSON(healthFacility);
    218218            return null;
    219219        }
Note: See TracChangeset for help on using the changeset viewer.