Changeset d23bf72
- Timestamp:
- 11/05/20 06:57:35 (4 years ago)
- Branches:
- master
- Children:
- afc9a9a
- Parents:
- 1f4846d
- Files:
-
- 12 added
- 1 deleted
- 31 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
Farmatiko.sln
r1f4846d rd23bf72 8 8 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FarmatikoData", "FarmatikoData\FarmatikoData.csproj", "{5BC55BDD-A064-4CE7-8606-D2FF42699EBF}" 9 9 EndProject 10 Project("{ FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FarmatikoServices", "FarmatikoServices\FarmatikoServices.csproj", "{D207CD1B-4C31-4414-9EF4-DC18F219CBF6}"10 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FarmatikoServices", "FarmatikoServices\FarmatikoServices.csproj", "{D207CD1B-4C31-4414-9EF4-DC18F219CBF6}" 11 11 EndProject 12 12 Global -
Farmatiko/ClientApp/src/app/login/login.component.html
r1f4846d rd23bf72 6 6 <div class="example-container"> 7 7 <mat-form-field> 8 <input matInput placeholder="Email" [(ngModel)]="this.username" formControlName=" email">8 <input matInput placeholder="Email" [(ngModel)]="this.username" formControlName="username"> 9 9 </mat-form-field> 10 10 -
Farmatiko/ClientApp/src/app/shared/interfaces.ts
r1f4846d rd23bf72 55 55 Passwd: string; 56 56 Name: string; 57 originalUserName?: string; 57 58 Role?: string; 58 59 } -
Farmatiko/ClientApp/src/app/shared/services/auth.service.ts
r1f4846d rd23bf72 11 11 username: string; 12 12 role: string; 13 originalUserName?: string; 13 14 accessToken: string; 14 15 refreshToken: string; 15 head : IPharmacyHead;16 head?: IPharmacyHead; 16 17 } 17 18 … … 35 36 this.http.get<LoginResult>(`${this.apiUrl}/user`).subscribe((x) => { 36 37 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, 39 41 Passwd: x.head.Passwd, 40 Name: x.head.Name 42 Name: x.head.Name, 43 PharmacyMedicines: x.head.PharmacyMedicines, 44 Pharmacy: x.head.Pharmacy 41 45 }); 42 46 }); … … 60 64 map((x) => { 61 65 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, 64 69 Passwd: x.head.Passwd, 65 Name: x.head.Name 70 Name: x.head.Name, 71 PharmacyMedicines: x.head.PharmacyMedicines, 72 Pharmacy: x.head.Pharmacy 66 73 }); 67 74 this.setLocalStorage(x); … … 98 105 map((x) => { 99 106 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, 102 110 Passwd: x.head.Passwd, 103 Name: x.head.Name 111 Name: x.head.Name, 112 PharmacyMedicines: x.head.PharmacyMedicines, 113 Pharmacy: x.head.Pharmacy 104 114 }); 105 115 this.setLocalStorage(x); -
Farmatiko/ClientApp/src/environments/environment.ts
r1f4846d rd23bf72 5 5 export const environment = { 6 6 production: false, 7 baseApiUrl: 'https://localhost: 44342/',7 baseApiUrl: 'https://localhost:5001/', 8 8 }; 9 9 -
Farmatiko/Controllers/AdminController.cs
r1f4846d rd23bf72 5 5 using FarmatikoData.Models; 6 6 using FarmatikoServices.FarmatikoServiceInterfaces; 7 using Microsoft.AspNetCore.Authorization; 7 8 using Microsoft.AspNetCore.Mvc; 8 9 9 10 namespace Farmatiko.Controllers 10 11 { 12 [ApiController] 13 [Authorize(Roles = "PharmacyHead")] 11 14 public class AdminController : Controller 12 15 { … … 40 43 [HttpPost] 41 44 [Route("api/pharmacyhead/add")] 42 public async Task<IActionResult> AddPharmacyHead( PharmacyHead pharmacyHead)45 public async Task<IActionResult> AddPharmacyHead([FromBody]PharmacyHead pharmacyHead) 43 46 { 44 47 await _service.AddPharmacyHead(pharmacyHead); … … 46 49 } 47 50 48 [Http Post]51 [HttpDelete] 49 52 [Route("api/pharmacyhead/delete/{Id}")] 50 public async Task<IActionResult> RemovePharmacyHead([From Query]int Id)53 public async Task<IActionResult> RemovePharmacyHead([FromRoute] int Id) 51 54 { 52 55 await _service.RemovePharmacyHead(Id); 53 56 return Ok(); 54 57 } 55 [HttpPost] 56 public IActionResult RejectRequset(RequestPharmacyHead req) 58 [HttpDelete] 59 [Route("api/pharmacyhead/requests/{Id}")] 60 public IActionResult RejectRequest([FromRoute] int Id) 57 61 { 58 bool Success = _adminService.RejectRequest( req);62 bool Success = _adminService.RejectRequest(Id); 59 63 return Ok(Success); 60 64 } 61 65 [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) 63 68 { 69 int id = Id; 64 70 await _phservice.UpdatePharmacyHead(pharmacyHead); 65 71 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; 1 using System.Net; 2 using Microsoft.AspNetCore.Diagnostics; 5 3 using Microsoft.AspNetCore.Mvc; 4 using Microsoft.Extensions.Logging; 6 5 7 6 namespace Farmatiko.Controllers 8 7 { 8 [ApiController] 9 9 public class ErrorController : Controller 10 10 { 11 public IActionResult Index() 11 private readonly ILogger<ErrorController> _logger; 12 13 public ErrorController(ILogger<ErrorController> logger) 12 14 { 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); 14 30 } 15 31 } -
Farmatiko/Controllers/FarmatikoController.cs
r1f4846d rd23bf72 11 11 { 12 12 private readonly IService _service; 13 public FarmatikoController(IService service) 13 private readonly IProcessJSONService _JSONservice; 14 public FarmatikoController(IService service, IProcessJSONService JSONservice) 14 15 { 15 16 _service = service; 17 _JSONservice = JSONservice; 16 18 } 17 19 // Workers 18 20 //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 } 19 31 [HttpGet] 20 32 [Route("api/workers")] … … 25 37 } 26 38 [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) 29 41 { 30 return await _service.SearchWorkers( Query);42 return await _service.SearchWorkers(query); 31 43 } 32 44 [HttpGet] 33 45 [Route("api/workers/{id}")] 34 public async Task<HealthcareWorker> GetWorker( int Id)46 public async Task<HealthcareWorker> GetWorker([FromRoute] int Id) 35 47 { 36 48 return await _service.GetWorker(Id); … … 48 60 } 49 61 [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) 52 64 { 53 return await _service.SearchFacilities( Query);65 return await _service.SearchFacilities(query); 54 66 } 55 67 [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) 58 70 { 59 return await _service.GetFacility( Id);71 return await _service.GetFacility(id); 60 72 } 61 73 //Post … … 70 82 } 71 83 [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) 74 86 { 75 return await _service.SearchMedicines( Query);87 return await _service.SearchMedicines(query); 76 88 } 77 89 [HttpGet] 78 90 [Route("api/medicines/{Id}")] 79 public async Task<Medicine> GetMedicine( int Id)91 public async Task<Medicine> GetMedicine([FromRoute] int Id) 80 92 { 81 93 return await _service.GetMedicine(Id); … … 98 110 [HttpGet] 99 111 [Route("api/pharmacy/search/{Query}")] 100 public async Task<IEnumerable<Pharmacy>> SearchPharmacies( string Query)112 public async Task<IEnumerable<Pharmacy>> SearchPharmacies([FromRoute] string Query) 101 113 { 102 114 return await _service.SearchPharmacies(Query); … … 104 116 [HttpGet] 105 117 [Route("api/pharmacy/{Id}")] 106 public async Task<Pharmacy> GetPharmacy( int Id)118 public async Task<Pharmacy> GetPharmacy([FromRoute] int Id) 107 119 { 108 120 return await _service.GetPharmacy(Id); -
Farmatiko/Controllers/PharmacyHeadController.cs
r1f4846d rd23bf72 1 using System.Collections; 2 using System.Collections.Generic; 3 using System.Linq; 1 using System.Collections.Generic; 4 2 using System.Threading.Tasks; 5 using FarmatikoData.FarmatikoRepoInterfaces;6 3 using FarmatikoData.Models; 7 4 using FarmatikoServices.FarmatikoServiceInterfaces; 5 using Microsoft.AspNetCore.Authorization; 8 6 using Microsoft.AspNetCore.Mvc; 9 7 … … 11 9 { 12 10 [ApiController] 11 [Authorize(Roles = "PharmacyHead")] 13 12 public class PharmacyHeadController : Controller 14 13 { … … 20 19 21 20 //GET 22 //Mi trebaat rutite 23 [HttpGet] 21 /*[HttpGet] 24 22 [Route("api/pharmacyhead")] 25 public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo( string Token)23 public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo() 26 24 { 27 var PHeads = await _PHService.GetPharmacyHeadInfo( Token);25 var PHeads = await _PHService.GetPharmacyHeadInfo(); 28 26 return PHeads; 29 } 27 }*/ 30 28 [HttpGet] 31 29 [Route("api/pharmacyhead/{Id}")] 32 public async Task<PharmacyHead> GetPharmacyHeadById( int Id)30 public async Task<PharmacyHead> GetPharmacyHeadById([FromRoute]int Id) 33 31 { 34 32 var Phead = await _PHService.GetPharmacyHeadByIdAsync(Id); … … 38 36 [HttpPost] 39 37 [Route("api/pharmacyhead/add")] 40 public async Task<IActionResult> AddPharmacyHead( PharmacyHead pharmacyHead)38 public async Task<IActionResult> AddPharmacyHead([FromBody]PharmacyHead pharmacyHead) 41 39 { 42 40 bool Success = await _PHService.Add(pharmacyHead); … … 44 42 } 45 43 46 [HttpPost]44 /*[HttpPost] 47 45 [Route("api/pharmacyhead/login")] 48 46 public async Task<int> Login([FromBody]PharmacyHead pharmacyHead) 49 47 { 50 48 return await _PHService.Login(pharmacyHead); 51 } 49 }*/ 52 50 [HttpPut] 53 51 [Route("api/pharmacyhead/{Id}")] … … 58 56 [HttpPost] 59 57 [Route("api/pharmacyhead/requests")] 60 public async Task<IActionResult> ClaimPharmacy( RequestPharmacyHead pharmacy)58 public async Task<IActionResult> ClaimPharmacy([FromBody]RequestPharmacyHead pharmacy) 61 59 { 62 60 bool Success = await _PHService.ClaimPharmacy(pharmacy); … … 65 63 [HttpDelete] 66 64 [Route("api/pharmacyhead/delete/{Id}")] 67 public async Task<IActionResult> Remove([From Query] int Id)65 public async Task<IActionResult> Remove([FromRoute] int Id) 68 66 { 69 67 bool Success = await _PHService.Remove(Id); … … 72 70 [HttpPost] 73 71 [Route("api/pharmacyhead/requests/{Id}")] 74 public async Task<IActionResult> RemoveClaimingRequest([From Query] int Id)72 public async Task<IActionResult> RemoveClaimingRequest([FromRoute] int Id) 75 73 { 76 74 bool Success = await _PHService.RemoveClaimingRequest(Id); -
Farmatiko/Farmatiko.csproj
r1f4846d rd23bf72 14 14 15 15 <ItemGroup> 16 <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.9" /> 16 17 <PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="3.1.6" /> 17 18 <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.6" /> -
Farmatiko/Startup.cs
r1f4846d rd23bf72 7 7 using FarmatikoData; 8 8 using Microsoft.EntityFrameworkCore; 9 using FarmatikoServices;10 9 using FarmatikoData.FarmatikoRepoInterfaces; 11 10 using FarmatikoData.FarmatikoRepo; … … 13 12 using FarmatikoServices.Services; 14 13 using Microsoft.Extensions.Logging; 14 using Microsoft.AspNetCore.Authentication.JwtBearer; 15 using Microsoft.IdentityModel.Tokens; 16 using System.Text; 17 using FarmatikoServices.Auth; 18 using FarmatikoServices.Infrastructure; 19 using System; 15 20 16 21 namespace Farmatiko … … 59 64 60 65 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 61 119 } 62 120 … … 74 132 app.UseHsts(); 75 133 } 76 134 app.UseExceptionHandler("/Error"); 77 135 app.UseHttpsRedirection(); 78 136 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 79 145 if (!env.IsDevelopment()) 80 146 { … … 84 150 app.UseRouting(); 85 151 152 app.UseAuthentication(); 153 app.UseAuthorization(); 154 86 155 app.UseCors(MyAllowSpecificOrigins); 87 156 … … 90 159 endpoints.MapControllerRoute( 91 160 name: "default", 92 pattern: " {controller}/{action=Index}/{id?}");161 pattern: "api/{controller}/{action=Index}/{id?}"); 93 162 }); 94 163 -
Farmatiko/appsettings.json
r1f4846d rd23bf72 12 12 "EPPlus": { 13 13 "ExcelPackage": { 14 "LicenseContext": "NonCommercial" 14 "LicenseContext": "NonCommercial" 15 15 } 16 16 }, 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" 18 27 } -
FarmatikoData/FarmatikoData.csproj
r1f4846d rd23bf72 4 4 <TargetFramework>netcoreapp3.1</TargetFramework> 5 5 </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>15 6 16 7 <ItemGroup> -
FarmatikoData/FarmatikoDataContext.cs
r1f4846d rd23bf72 17 17 public virtual DbSet<MedicineList> MedicineLists { get; set; } 18 18 public virtual DbSet<RequestPharmacyHead> PHRequests { get; set; } 19 public virtual DbSet<User> Users { get; set; } 19 20 } 20 21 } -
FarmatikoData/FarmatikoRepo/AdminRepo.cs
r1f4846d rd23bf72 31 31 } 32 32 //POST 33 public void RemoveClaimRequest( RequestPharmacyHead req)33 public void RemoveClaimRequest(int Id) 34 34 { 35 var req = _context.PHRequests.Where(x => x.Id == Id).FirstOrDefault(); 35 36 _context.PHRequests.Remove(req); 36 37 _context.SaveChanges(); -
FarmatikoData/FarmatikoRepo/PHRepo.cs
r1f4846d rd23bf72 71 71 await _context.SaveChangesAsync(); 72 72 } 73 74 public PharmacyHead GetPharmacyHeadByUserName(string userName) 75 { 76 return _context.PharmacyHeads 77 .Where(x => x.Email.Equals(userName)) 78 .FirstOrDefault(); 79 } 73 80 } 74 81 } -
FarmatikoData/FarmatikoRepo/Repository.cs
r1f4846d rd23bf72 19 19 public async Task<IEnumerable<HealthcareWorker>> GetAllWorkers() 20 20 { 21 var Workers = await Task.Run(() => _context.HealthcareWorkers.Take(10));21 var Workers = await _context.HealthcareWorkers.Take(5).ToListAsync(); 22 22 return Workers; 23 23 } … … 25 25 public async Task<IEnumerable<HealthFacility>> GetFacilities() 26 26 { 27 var Facilities = await Task.Run(() => _context.HealthFacilities.Take(10));27 var Facilities = await _context.HealthFacilities.Take(5).ToListAsync(); 28 28 return Facilities; 29 29 } … … 43 43 public async Task<IEnumerable<Medicine>> GetMedicines() 44 44 { 45 var Medicines = await Task.Run(() => _context.Medicines.Take(10));45 var Medicines = await _context.Medicines.Take(3).ToListAsync(); 46 46 return Medicines; 47 47 } … … 49 49 public async Task<Pandemic> GetPandemic() 50 50 { 51 var Pandemic = await Task.Run(() => _context.Pandemics.FirstOrDefault());51 var Pandemic = await _context.Pandemics.FirstOrDefaultAsync(); 52 52 return Pandemic; 53 53 } … … 55 55 public async Task<IEnumerable<Pharmacy>> GetPharmacies() 56 56 { 57 var Pharmacies = await Task.Run(() => _context.Pharmacies.Take(10));57 var Pharmacies = await _context.Pharmacies.Take(5).ToListAsync(); 58 58 return Pharmacies; 59 59 } … … 73 73 public async Task<IEnumerable<HealthFacility>> SearchFacilities(string query) 74 74 { 75 var SearchQuery = await Task.Run(() =>_context.HealthFacilities76 .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(); 78 78 79 79 return SearchQuery; … … 82 82 public async Task<IEnumerable<Medicine>> SearchMedicines(string query) 83 83 { 84 var SearchQuery = await Task.Run(() =>_context.Medicines85 .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(); 87 87 88 88 return SearchQuery; … … 91 91 public async Task<IEnumerable<Pharmacy>> SearchPharmacies(string query) 92 92 { 93 var SearchQuery = await Task.Run(() => _context.Pharmacies94 .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(); 96 96 97 97 return SearchQuery; … … 100 100 public async Task<IEnumerable<HealthcareWorker>> SearchWorkers(string query) 101 101 { 102 var SearchQuery = await Task.Run(() => _context.HealthcareWorkers103 .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(); 111 111 return Facility; 112 112 } … … 116 116 public async Task AddWorker(HealthcareWorker Worker) 117 117 { 118 await Task.Run(() => _context.HealthcareWorkers.Add(Worker));119 await _context.SaveChangesAsync();118 await _context.HealthcareWorkers.AddAsync(Worker); 119 _context.SaveChanges(); 120 120 } 121 121 122 122 public async Task AddFacility(HealthFacility healthFacility) 123 123 { 124 await Task.Run(() => _context.HealthFacilities.Add(healthFacility));125 await _context.SaveChangesAsync();124 await _context.HealthFacilities.AddAsync(healthFacility); 125 _context.SaveChanges(); 126 126 } 127 127 128 128 public async Task AddPharmacy(Pharmacy pharmacy) 129 129 { 130 await Task.Run(() => _context.Pharmacies.Add(pharmacy));131 await _context.SaveChangesAsync();130 await _context.Pharmacies.AddAsync(pharmacy); 131 _context.SaveChanges(); 132 132 } 133 133 134 134 public async Task AddPharmacyHead(PharmacyHead pharmacyHead) 135 135 { 136 await Task.Run(() => _context.PharmacyHeads.Add(pharmacyHead));137 await _context.SaveChangesAsync();136 await _context.PharmacyHeads.AddAsync(pharmacyHead); 137 _context.SaveChanges(); 138 138 } 139 139 140 140 public async Task AddMedicines(Medicine medicine) 141 141 { 142 await Task.Run(() => _context.Medicines.Add(medicine));143 await _context.SaveChangesAsync();142 await _context.Medicines.AddAsync(medicine); 143 _context.SaveChanges(); 144 144 } 145 145 146 146 public async Task AddPandemic(Pandemic pandemic) 147 147 { 148 await Task.Run(() => _context.Pandemics.Add(pandemic));149 await _context.SaveChangesAsync();148 var pand = await _context.Pandemics.AddAsync(pandemic); 149 _context.SaveChanges(); 150 150 } 151 151 152 152 public async Task UpdateFacility(HealthFacility healthFacility) 153 153 { 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(); 155 155 Facility.Address = healthFacility.Address; 156 156 Facility.Email = healthFacility.Email; … … 159 159 Facility.Phone = healthFacility.Phone; 160 160 Facility.Type = healthFacility.Type; 161 await _context.SaveChangesAsync();161 _context.SaveChanges(); 162 162 } 163 163 … … 165 165 { 166 166 await Task.Run(() => _context.Medicines.Remove(medicine)); 167 await _context.SaveChangesAsync();167 _context.SaveChanges(); 168 168 } 169 169 170 170 public async Task UpdatePandemic(Pandemic pandemic) 171 171 { 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(); 173 173 Pandemic.ActiveGlobal = pandemic.ActiveGlobal; 174 174 Pandemic.ActiveMK = pandemic.ActiveMK; … … 179 179 Pandemic.TotalGlobal = pandemic.TotalGlobal; 180 180 Pandemic.TotalMK = pandemic.TotalMK; 181 await _context.SaveChangesAsync();181 _context.SaveChanges(); 182 182 } 183 183 … … 185 185 { 186 186 await Task.Run(() => _context.Pharmacies.Remove(pharmacy)); 187 await _context.SaveChangesAsync();187 _context.SaveChanges(); 188 188 } 189 189 //not impl … … 195 195 public async Task UpadatePharmacy(Pharmacy pharmacy) 196 196 { 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(); 198 198 Pharmacy.Name = pharmacy.Name; 199 199 Pharmacy.Location = pharmacy.Location; 200 200 Pharmacy.WorkAllTime = pharmacy.WorkAllTime; 201 201 Pharmacy.Address = pharmacy.Address; 202 await _context.SaveChangesAsync();202 _context.SaveChanges(); 203 203 } 204 204 //ke vidime … … 212 212 var PHead = await _context.PharmacyHeads.Where(x => x.Id == Id).FirstOrDefaultAsync(); 213 213 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 } 217 229 } 218 230 } -
FarmatikoData/FarmatikoRepoInterfaces/IAdminRepo.cs
r1f4846d rd23bf72 12 12 Task<IEnumerable<RequestPharmacyHead>> GetClaimingRequests(); 13 13 Task<IEnumerable<PharmacyHead>> GetPharmacyHeads(); 14 void RemoveClaimRequest( RequestPharmacyHead req);14 void RemoveClaimRequest(int Id); 15 15 } 16 16 } -
FarmatikoData/FarmatikoRepoInterfaces/IPHRepo.cs
r1f4846d rd23bf72 17 17 Task Remove(PharmacyHead phead); 18 18 Task RemoveClaimingRequest(int id); 19 PharmacyHead GetPharmacyHeadByUserName(string userName); 19 20 } 20 21 } -
FarmatikoData/FarmatikoRepoInterfaces/IRepository.cs
r1f4846d rd23bf72 24 24 Task<IEnumerable<Pharmacy>> SearchPharmacies(string query); 25 25 Task<IEnumerable<HealthcareWorker>> SearchWorkers(string query); 26 Task<HealthFacility> GetFacilityJSON(string healthFacility); 26 HealthFacility GetFacilityJSON(string healthFacility); 27 IDictionary<string, User> GetUsers(); 27 28 28 29 //POST -
FarmatikoData/Migrations/20201104230858_InitialMigration.cs
r1f4846d rd23bf72 5 5 namespace FarmatikoData.Migrations 6 6 { 7 public partial class Initial migration : Migration7 public partial class InitialMigration : Migration 8 8 { 9 9 protected override void Up(MigrationBuilder migrationBuilder) … … 15 15 Id = table.Column<int>(nullable: false) 16 16 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), 17 CreatedOn = table.Column<DateTime>(nullable: false , defaultValueSql: "now()"),17 CreatedOn = table.Column<DateTime>(nullable: false), 18 18 DeletedOn = table.Column<DateTime>(nullable: true), 19 19 Name = table.Column<string>(nullable: false), … … 24 24 Phone = table.Column<string>(nullable: true) 25 25 }, 26 constraints: table => 26 constraints: table => 27 27 { 28 28 table.PrimaryKey("PK_HealthFacilities", x => x.Id); … … 30 30 31 31 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( 32 53 name: "Pandemics", 33 54 columns: table => new … … 35 56 Id = table.Column<int>(nullable: false) 36 57 .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), 40 61 TotalMK = table.Column<int>(nullable: false), 41 62 ActiveMK = table.Column<int>(nullable: false), 42 63 DeathsMK = table.Column<int>(nullable: false), 43 64 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) 47 68 }, 48 69 constraints: table => … … 52 73 53 74 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( 54 110 name: "HealthcareWorkers", 55 111 columns: table => new … … 57 113 Id = table.Column<int>(nullable: false) 58 114 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), 59 CreatedOn = table.Column<DateTime>(nullable: false , defaultValueSql: "now()"),115 CreatedOn = table.Column<DateTime>(nullable: false), 60 116 DeletedOn = table.Column<DateTime>(nullable: true), 61 117 Name = table.Column<string>(nullable: false), … … 76 132 77 133 migrationBuilder.CreateTable( 78 name: "Medicines",79 columns: table => new80 {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 => new102 {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(119 134 name: "MedicineLists", 120 135 columns: table => new … … 122 137 Id = table.Column<int>(nullable: false) 123 138 .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), 124 CreatedOn = table.Column<DateTime>(nullable: false , defaultValueSql: "now()"),125 DeletedOn = table.Column<DateTime>(nullable: true), 126 Medicine sId = 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), 127 142 HasMedicine = table.Column<bool>(nullable: false), 128 143 PharmacyHeadId = table.Column<int>(nullable: true) … … 132 147 table.PrimaryKey("PK_MedicineLists", x => x.Id); 133 148 table.ForeignKey( 134 name: "FK_MedicineLists_Medicines_Medicine sId",135 column: x => x.Medicine sId,149 name: "FK_MedicineLists_Medicines_MedicineId", 150 column: x => x.MedicineId, 136 151 principalTable: "Medicines", 137 152 principalColumn: "Id", 138 onDelete: ReferentialAction. Restrict);153 onDelete: ReferentialAction.Cascade); 139 154 table.ForeignKey( 140 155 name: "FK_MedicineLists_PharmacyHeads_PharmacyHeadId", … … 151 166 Id = table.Column<int>(nullable: false) 152 167 .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), 158 173 WorkAllTime = table.Column<bool>(nullable: false), 159 174 PharmacyHeadId = table.Column<int>(nullable: true) … … 170 185 }); 171 186 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 172 215 migrationBuilder.CreateIndex( 173 216 name: "IX_HealthcareWorkers_FacilityId", … … 176 219 177 220 migrationBuilder.CreateIndex( 178 name: "IX_MedicineLists_Medicine sId",221 name: "IX_MedicineLists_MedicineId", 179 222 table: "MedicineLists", 180 column: "Medicine sId");223 column: "MedicineId"); 181 224 182 225 migrationBuilder.CreateIndex( … … 186 229 187 230 migrationBuilder.CreateIndex( 188 name: "IX_Medicines_MedicineListId",189 table: "Medicines",190 column: "MedicineListId");191 192 migrationBuilder.CreateIndex(193 231 name: "IX_Pharmacies_PharmacyHeadId", 194 232 table: "Pharmacies", … … 196 234 197 235 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", 200 243 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);230 244 } 231 245 232 246 protected override void Down(MigrationBuilder migrationBuilder) 233 247 { 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 246 248 migrationBuilder.DropTable( 247 249 name: "HealthcareWorkers"); 248 250 249 251 migrationBuilder.DropTable( 252 name: "MedicineLists"); 253 254 migrationBuilder.DropTable( 250 255 name: "Pandemics"); 251 256 252 257 migrationBuilder.DropTable( 258 name: "PHRequests"); 259 260 migrationBuilder.DropTable( 261 name: "Users"); 262 263 migrationBuilder.DropTable( 253 264 name: "HealthFacilities"); 254 265 … … 257 268 258 269 migrationBuilder.DropTable( 270 name: "Pharmacies"); 271 272 migrationBuilder.DropTable( 259 273 name: "PharmacyHeads"); 260 261 migrationBuilder.DropTable(262 name: "Pharmacies");263 264 migrationBuilder.DropTable(265 name: "MedicineLists");266 274 } 267 275 } -
FarmatikoData/Migrations/20201105055526_NewMigration.Designer.cs
r1f4846d rd23bf72 11 11 { 12 12 [DbContext(typeof(FarmatikoDataContext))] 13 [Migration("2020 0722131856_Initial migration")]14 partial class Initialmigration13 [Migration("20201105055526_NewMigration")] 14 partial class NewMigration 15 15 { 16 16 protected override void BuildTargetModel(ModelBuilder modelBuilder) … … 22 22 .HasAnnotation("Relational:MaxIdentifierLength", 63); 23 23 24 modelBuilder.Entity("FarmatikoData.Models.HealthFacilit ies", b =>24 modelBuilder.Entity("FarmatikoData.Models.HealthFacility", b => 25 25 { 26 26 b.Property<int>("Id") … … 36 36 .HasColumnType("timestamp without time zone"); 37 37 38 b.Property<DateTime >("DeletedOn")38 b.Property<DateTime?>("DeletedOn") 39 39 .HasColumnType("timestamp without time zone"); 40 40 … … 62 62 }); 63 63 64 modelBuilder.Entity("FarmatikoData.Models.HealthcareWorker s", b =>64 modelBuilder.Entity("FarmatikoData.Models.HealthcareWorker", b => 65 65 { 66 66 b.Property<int>("Id") … … 76 76 .HasColumnType("timestamp without time zone"); 77 77 78 b.Property<DateTime >("DeletedOn")78 b.Property<DateTime?>("DeletedOn") 79 79 .HasColumnType("timestamp without time zone"); 80 80 … … 106 106 .HasColumnType("timestamp without time zone"); 107 107 108 b.Property<DateTime >("DeletedOn")108 b.Property<DateTime?>("DeletedOn") 109 109 .HasColumnType("timestamp without time zone"); 110 110 … … 113 113 114 114 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() 121 120 .HasColumnType("text"); 122 121 … … 128 127 129 128 b.Property<string>("Strength") 129 .IsRequired() 130 130 .HasColumnType("text"); 131 131 132 132 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"); 138 137 139 138 b.ToTable("Medicines"); … … 150 149 .HasColumnType("timestamp without time zone"); 151 150 152 b.Property<DateTime >("DeletedOn")151 b.Property<DateTime?>("DeletedOn") 153 152 .HasColumnType("timestamp without time zone"); 154 153 … … 156 155 .HasColumnType("boolean"); 157 156 158 b.Property<int ?>("MedicinesId")157 b.Property<int>("MedicineId") 159 158 .HasColumnType("integer"); 160 159 … … 164 163 b.HasKey("Id"); 165 164 166 b.HasIndex("Medicine sId");165 b.HasIndex("MedicineId"); 167 166 168 167 b.HasIndex("PharmacyHeadId"); … … 178 177 .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn); 179 178 180 b.Property< int>("ActiveGlobal")181 .HasColumnType(" integer");179 b.Property<long>("ActiveGlobal") 180 .HasColumnType("bigint"); 182 181 183 182 b.Property<int>("ActiveMK") … … 187 186 .HasColumnType("timestamp without time zone"); 188 187 189 b.Property< int>("DeathsGlobal")190 .HasColumnType(" integer");188 b.Property<long>("DeathsGlobal") 189 .HasColumnType("bigint"); 191 190 192 191 b.Property<int>("DeathsMK") 193 192 .HasColumnType("integer"); 194 193 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() 199 199 .HasColumnType("text"); 200 200 … … 202 202 .HasColumnType("integer"); 203 203 204 b.Property< int>("TotalGlobal")205 .HasColumnType(" integer");204 b.Property<long>("TotalGlobal") 205 .HasColumnType("bigint"); 206 206 207 207 b.Property<int>("TotalMK") … … 221 221 222 222 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") 229 230 .HasColumnType("timestamp without time zone"); 230 231 231 232 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() 235 238 .HasColumnType("text"); 236 239 … … 258 261 .HasColumnType("timestamp without time zone"); 259 262 260 b.Property<DateTime >("DeletedOn")263 b.Property<DateTime?>("DeletedOn") 261 264 .HasColumnType("timestamp without time zone"); 262 265 263 266 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() 267 272 .HasColumnType("text"); 268 273 269 274 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"); 279 305 280 306 b.HasIndex("PharmacyId"); 281 307 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") 290 344 .WithMany() 291 345 .HasForeignKey("FacilityId") … … 294 348 }); 295 349 296 modelBuilder.Entity("FarmatikoData.Models.Medicine", b =>297 {298 b.HasOne("FarmatikoData.Models.MedicineList", null)299 .WithMany("MedicinesList")300 .HasForeignKey("MedicineListId");301 });302 303 350 modelBuilder.Entity("FarmatikoData.Models.MedicineList", b => 304 351 { 305 b.HasOne("FarmatikoData.Models.Medicine", "Medicine s")352 b.HasOne("FarmatikoData.Models.Medicine", "Medicine") 306 353 .WithMany() 307 .HasForeignKey("MedicinesId"); 354 .HasForeignKey("MedicineId") 355 .OnDelete(DeleteBehavior.Cascade) 356 .IsRequired(); 308 357 309 358 b.HasOne("FarmatikoData.Models.PharmacyHead", null) … … 319 368 }); 320 369 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 323 378 b.HasOne("FarmatikoData.Models.Pharmacy", "Pharmacy") 324 379 .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(); 330 383 }); 331 384 #pragma warning restore 612, 618 -
FarmatikoData/Migrations/FarmatikoDataContextModelSnapshot.cs
r1f4846d rd23bf72 20 20 .HasAnnotation("Relational:MaxIdentifierLength", 63); 21 21 22 modelBuilder.Entity("FarmatikoData.Models.HealthFacilit ies", b =>22 modelBuilder.Entity("FarmatikoData.Models.HealthFacility", b => 23 23 { 24 24 b.Property<int>("Id") … … 60 60 }); 61 61 62 modelBuilder.Entity("FarmatikoData.Models.HealthcareWorker s", b =>62 modelBuilder.Entity("FarmatikoData.Models.HealthcareWorker", b => 63 63 { 64 64 b.Property<int>("Id") … … 111 111 112 112 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() 116 118 .HasColumnType("text"); 117 119 … … 123 125 124 126 b.Property<string>("Strength") 127 .IsRequired() 125 128 .HasColumnType("text"); 126 129 127 130 b.Property<string>("WayOfIssuing") 131 .IsRequired() 128 132 .HasColumnType("text"); 129 133 … … 149 153 .HasColumnType("boolean"); 150 154 151 b.Property<int ?>("MedicineId")155 b.Property<int>("MedicineId") 152 156 .HasColumnType("integer"); 153 157 … … 190 194 191 195 b.Property<string>("Name") 196 .IsRequired() 192 197 .HasColumnType("text"); 193 198 … … 214 219 215 220 b.Property<string>("Address") 221 .IsRequired() 216 222 .HasColumnType("text"); 217 223 … … 223 229 224 230 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() 228 236 .HasColumnType("text"); 229 237 … … 255 263 256 264 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() 260 270 .HasColumnType("text"); 261 271 262 272 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"); 272 303 273 304 b.HasIndex("PharmacyId"); 274 305 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") 283 342 .WithMany() 284 343 .HasForeignKey("FacilityId") … … 291 350 b.HasOne("FarmatikoData.Models.Medicine", "Medicine") 292 351 .WithMany() 293 .HasForeignKey("MedicineId"); 352 .HasForeignKey("MedicineId") 353 .OnDelete(DeleteBehavior.Cascade) 354 .IsRequired(); 294 355 295 356 b.HasOne("FarmatikoData.Models.PharmacyHead", null) … … 305 366 }); 306 367 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 309 376 b.HasOne("FarmatikoData.Models.Pharmacy", "Pharmacy") 310 377 .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(); 316 381 }); 317 382 #pragma warning restore 612, 618 -
FarmatikoData/Models/PharmacyHead.cs
r1f4846d rd23bf72 16 16 [Required] 17 17 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; } 20 20 21 21 } -
FarmatikoServices/FarmatikoServiceInterfaces/IAdminService.cs
r1f4846d rd23bf72 12 12 Task<IEnumerable<PharmacyHead>> GetPharmacyHeads(); 13 13 Task<IEnumerable<RequestPharmacyHead>> GetClaimingRequests(); 14 bool RejectRequest( RequestPharmacyHead req);14 bool RejectRequest(int Id); 15 15 } 16 16 } -
FarmatikoServices/FarmatikoServiceInterfaces/IPHService.cs
r1f4846d rd23bf72 10 10 public interface IPHService 11 11 { 12 Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo( string Token);12 Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo(); 13 13 Task UpdatePharmacyHead(PharmacyHead pharmacyHead); 14 14 Task<int> Login(PharmacyHead pharmacyHead); … … 18 18 Task<bool> Remove(int id); 19 19 Task<bool> RemoveClaimingRequest(int id); 20 PharmacyHead GetPharmacyHead(string userName); 20 21 } 21 22 } -
FarmatikoServices/FarmatikoServiceInterfaces/IProcessJSONService.cs
r1f4846d rd23bf72 9 9 public interface IProcessJSONService 10 10 { 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(); 16 16 } 17 17 } -
FarmatikoServices/FarmatikoServiceInterfaces/IService.cs
r1f4846d rd23bf72 15 15 Task<IEnumerable<HealthFacility>> SearchFacilities(string query); 16 16 Task<HealthFacility> GetFacility(int id); 17 Task<HealthFacility>GetFacilityJSON(string healthFacility);17 HealthFacility GetFacilityJSON(string healthFacility); 18 18 Task<Medicine> GetMedicine(int id); 19 19 Task<IEnumerable<Medicine>> SearchMedicines(string query); -
FarmatikoServices/FarmatikoServices.csproj
r1f4846d rd23bf72 6 6 7 7 <ItemGroup> 8 <PackageReference Include="AngleSharp" Version="0.14.0" /> 8 9 <PackageReference Include="EPPlus" Version="5.4.0" /> 10 <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" /> 9 11 <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" /> 11 14 </ItemGroup> 12 15 … … 15 18 </ItemGroup> 16 19 20 <ItemGroup> 21 <Folder Include="Services\ExcellDocs\" /> 22 </ItemGroup> 23 17 24 </Project> -
FarmatikoServices/Services/AdminService.cs
r1f4846d rd23bf72 36 36 } 37 37 38 public bool RejectRequest( RequestPharmacyHead req)38 public bool RejectRequest(int Id) 39 39 { 40 if ( req != null)40 if (Id >= 0) 41 41 { 42 _adminRepo.RemoveClaimRequest( req);42 _adminRepo.RemoveClaimRequest(Id); 43 43 return true; 44 44 } -
FarmatikoServices/Services/PHService.cs
r1f4846d rd23bf72 38 38 } 39 39 40 public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo( string Token)40 public async Task<IEnumerable<PharmacyHead>> GetPharmacyHeadInfo() 41 41 { 42 42 var PHeads = await _iPHRepo.GetPharmacyHeadInfo(); … … 92 92 return false; 93 93 } 94 95 public PharmacyHead GetPharmacyHead(string userName) 96 { 97 if (userName != null) 98 { 99 return _iPHRepo.GetPharmacyHeadByUserName(userName); 100 } 101 return default; 102 } 94 103 } 95 104 } -
FarmatikoServices/Services/ProcessJSONService.cs
r1f4846d rd23bf72 13 13 using OfficeOpenXml; 14 14 using System.IO; 15 using Microsoft.VisualBasic; 15 16 16 17 namespace FarmatikoServices.Services … … 26 27 _service = service; 27 28 } 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() 39 38 { 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) 53 73 { 54 74 _logger.LogInformation(e.Message); 55 75 throw new Exception("Cannot process Medicines from Excel."); 56 76 } 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"); 67 86 68 87 var jsonResponse = JObject.Parse(json); … … 78 97 var Phone = obj[11]; 79 98 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"); 99 125 var response = client.Execute(new RestRequest()); 100 126 string original = response.Content; 101 127 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()); 113 143 114 144 var Name = "Coronavirus"; … … 117 147 118 148 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"); 134 163 135 164 var jsonResponseW = JObject.Parse(jsonW); … … 139 168 { 140 169 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"); 172 219 173 220 var jsonResponseM = JObject.Parse(jsonM); … … 182 229 var WayOfIssuing = obj[9]; 183 230 var Manufacturer = obj[11]; 184 var Price = float.Parse( obj[17]);231 var Price = float.Parse(Convert.ToString(obj[17])); 185 232 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 } 202 244 } 203 245 } -
FarmatikoServices/Services/Service.cs
r1f4846d rd23bf72 103 103 if (healthFacilities != null) 104 104 await _repository.AddFacility(healthFacilities); 105 throw new Exception("Facility is null");105 else throw new Exception("Facility is null"); 106 106 } 107 107 //za json(Sys updateer) … … 110 110 if (medicine != null) 111 111 await _repository.AddMedicines(medicine); 112 throw new Exception("Medicine is null");112 else throw new Exception("Medicine is null"); 113 113 } 114 114 //za json(Sys updateer) … … 117 117 if (pandemic != null) 118 118 await _repository.AddPandemic(pandemic); 119 throw new Exception("Pandemic is null");119 else throw new Exception("Pandemic is null"); 120 120 } 121 121 // Samo PharmacyHead i Admin imaat pristap … … 124 124 if (pharmacy != null) 125 125 await _repository.AddPharmacy(pharmacy); 126 throw new Exception("Pharmacy is null");126 else throw new Exception("Pharmacy is null"); 127 127 } 128 128 // Ovaa kontrola ja ima samo admin … … 150 150 if (worker != null) 151 151 await _repository.AddWorker(worker); 152 throw new Exception("Worker is null");152 else throw new Exception("Worker is null"); 153 153 } 154 154 … … 158 158 if (healthFacilities != null) 159 159 await _repository.UpdateFacility(healthFacilities); 160 throw new Exception("Facility is null");160 else throw new Exception("Facility is null"); 161 161 } 162 162 //PharmacyHead … … 165 165 if (medicine != null) 166 166 await _repository.RemoveMedicine(medicine); 167 throw new Exception("Medicine is null");167 else throw new Exception("Medicine is null"); 168 168 } 169 169 //PharmacyHead … … 172 172 if (medicine != null) 173 173 await _repository.UpdateMedicine(medicine); 174 throw new Exception("Medicine is null");174 else throw new Exception("Medicine is null"); 175 175 } 176 176 //za json(Sys updateer) … … 179 179 if (pandemic != null) 180 180 await _repository.UpdatePandemic(pandemic); 181 throw new Exception("Pandemic is null");181 else throw new Exception("Pandemic is null"); 182 182 } 183 183 //PharmacyHead … … 186 186 if (pharmacy != null) 187 187 await _repository.RemovePharmacy(pharmacy); 188 throw new Exception("Pharmacy is null");188 else throw new Exception("Pharmacy is null"); 189 189 } 190 190 //PharamcyHead … … 193 193 if (pharmacy != null) 194 194 await _repository.UpadatePharmacy(pharmacy); 195 throw new Exception("Pharmacy is null");195 else throw new Exception("Pharmacy is null"); 196 196 } 197 197 //za json(Sys updateer) … … 200 200 if (worker != null) 201 201 await _repository.UpdateWorker(worker); 202 throw new Exception("Worker is null");202 else throw new Exception("Worker is null"); 203 203 } 204 204 … … 209 209 await _repository.RemovePharmacyHead(Id); 210 210 } 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) 215 215 { 216 216 if (healthFacility != null) 217 return await_repository.GetFacilityJSON(healthFacility);217 return _repository.GetFacilityJSON(healthFacility); 218 218 return null; 219 219 }
Note:
See TracChangeset
for help on using the changeset viewer.