55 lines
1.6 KiB
C#
55 lines
1.6 KiB
C#
using BMA.EHR.Application.Common.Interfaces;
|
|
using BMA.EHR.Domain.Models.HR;
|
|
using BMA.EHR.Domain.Models.Organizations;
|
|
using BMA.EHR.Domain.Shared;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace BMA.EHR.Application.Repositories
|
|
{
|
|
public class UserProfileRepository : GenericRepository<Guid, Profile>
|
|
{
|
|
#region " Fields "
|
|
|
|
private readonly IApplicationDBContext _dbContext;
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
|
|
#endregion
|
|
|
|
#region " Costructor and Destructor "
|
|
|
|
public UserProfileRepository(IApplicationDBContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
|
{
|
|
_dbContext = dbContext;
|
|
_httpContextAccessor = httpContextAccessor;
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region " Methods "
|
|
|
|
public Guid GetUserOCId(Guid keycloakId)
|
|
{
|
|
try
|
|
{
|
|
var data = _dbContext.Set<ProfilePosition>()
|
|
.Include(x => x.Profile)
|
|
.Include(x => x.OrganizationPosition)
|
|
.ThenInclude(x => x.Organization)
|
|
.Where(x => x.Profile!.KeycloakId == keycloakId)
|
|
.FirstOrDefault();
|
|
|
|
if (data == null)
|
|
throw new Exception(GlobalMessages.DataNotFound);
|
|
|
|
return data.OrganizationPosition!.Organization!.Id;
|
|
}
|
|
catch
|
|
{
|
|
throw;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|