75 lines
2.5 KiB
C#
75 lines
2.5 KiB
C#
using BMA.EHR.Application.Common.Interfaces;
|
|
using BMA.EHR.Application.Responses;
|
|
using BMA.EHR.Domain.Models.MetaData;
|
|
using BMA.EHR.Domain.Models.Organizations;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Newtonsoft.Json.Linq;
|
|
using Newtonsoft.Json;
|
|
using System.Net.Http.Headers;
|
|
using Microsoft.Extensions.Configuration;
|
|
using System.Security.Claims;
|
|
|
|
namespace BMA.EHR.Application.Repositories
|
|
{
|
|
public class PermissionRepository
|
|
{
|
|
#region " Fields "
|
|
|
|
private readonly IApplicationDBContext _dbContext;
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
private readonly IConfiguration _configuration;
|
|
|
|
#endregion
|
|
|
|
#region " Constructor and Destuctor "
|
|
|
|
public PermissionRepository(IApplicationDBContext dbContext,
|
|
IHttpContextAccessor httpContextAccessor,
|
|
IConfiguration configuration)
|
|
{
|
|
_dbContext = dbContext;
|
|
_httpContextAccessor = httpContextAccessor;
|
|
_configuration = configuration;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " Properties "
|
|
|
|
//protected string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
|
|
|
//protected string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
|
|
|
|
//protected bool? IsPlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
|
|
|
|
protected string? AccessToken => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"];
|
|
|
|
#endregion
|
|
|
|
#region " Methods "
|
|
|
|
public async Task<dynamic> GetPermissionAPIAsync(string action, string system)
|
|
{
|
|
try
|
|
{
|
|
var apiPath = $"{_configuration["API"]}/org/permission/dotnet/{action}/{system}";
|
|
|
|
using (var client = new HttpClient())
|
|
{
|
|
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AccessToken.Replace("Bearer ", ""));
|
|
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
|
|
var req = await client.GetAsync(apiPath);
|
|
var res = await req.Content.ReadAsStringAsync();
|
|
return res;
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|