Get Receiver for Command C-PM-01, C-PM-02

This commit is contained in:
Suphonchai Phoonsawat 2023-08-28 16:18:35 +07:00
parent ec39bf1505
commit 6253d8d2ab
2 changed files with 119 additions and 24 deletions

View file

@ -1,5 +1,7 @@
using BMA.EHR.Application.Common.Interfaces;
using Amazon.S3.Model.Internal.MarshallTransformations;
using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Domain.Models.Base;
using BMA.EHR.Domain.Models.HR;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using System.Security.Claims;
@ -13,7 +15,7 @@ namespace BMA.EHR.Application.Repositories
private readonly IApplicationDBContext _dbContext;
private readonly DbSet<T> _dbSet;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
#region " Constructor and Destructor "
@ -24,7 +26,7 @@ namespace BMA.EHR.Application.Repositories
_dbContext = dbContext;
_dbSet = _dbContext.Set<T>();
_httpContextAccessor = httpContextAccessor;
}
#endregion
@ -35,12 +37,29 @@ namespace BMA.EHR.Application.Repositories
protected string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
protected bool? IsPlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
protected bool? IsPlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
#endregion
#region " Methods "
public async Task<bool> CheckIsActiveOfficer(string citizenId)
{
try
{
var pf = await _dbContext.Set<Profile>()
.Where(x => x.CitizenId == citizenId)
.Where(x => x.ProfileType.ToLower().Trim() == "officer" && x.IsActive && !x.IsLeave)
.FirstOrDefaultAsync();
return pf != null;
}
catch
{
throw;
}
}
public virtual async Task<IReadOnlyList<T>> GetAllAsync()
{
return await _dbSet.ToListAsync();