fix: Change Profile Link to Guid

This commit is contained in:
Suphonchai Phoonsawat 2024-06-11 09:34:06 +07:00
parent ee2a0f1e36
commit b7120551b5
6 changed files with 1213 additions and 47 deletions

View file

@ -1,6 +1,7 @@
using System.Data.Common;
using System.Globalization;
using System.IO.Pipelines;
using System.Security.Claims;
using BMA.EHR.Application.Repositories;
using BMA.EHR.Application.Repositories.Commands;
using BMA.EHR.Application.Repositories.Leaves.LeaveRequests;
@ -40,6 +41,7 @@ namespace BMA.EHR.Leave.Service.Controllers
private readonly UserDutyTimeRepository _userDutyTimeRepository;
private readonly HolidayRepository _holidayRepository;
private readonly UserCalendarRepository _userCalendarRepository;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
@ -53,7 +55,8 @@ namespace BMA.EHR.Leave.Service.Controllers
DutyTimeRepository dutyTimeRepository,
UserDutyTimeRepository userDutyTimeRepository,
HolidayRepository holidayRepository,
UserCalendarRepository userCalendarRepository)
UserCalendarRepository userCalendarRepository,
IHttpContextAccessor httpContextAccessor)
{
_leaveRequestRepository = leaveRequestRepository;
_userProfileRepository = userProfileRepository;
@ -64,6 +67,30 @@ namespace BMA.EHR.Leave.Service.Controllers
_userDutyTimeRepository = userDutyTimeRepository;
_holidayRepository = holidayRepository;
_userCalendarRepository = userCalendarRepository;
_httpContextAccessor = httpContextAccessor;
}
#endregion
#region " Properties "
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
private bool? PlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
private string? AccessToken => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"];
private Guid OcId
{
get
{
if (UserId != null || UserId != "")
return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!));
else
return Guid.Empty;
}
}
#endregion
@ -74,13 +101,13 @@ namespace BMA.EHR.Leave.Service.Controllers
private async Task<dynamic> GetReport01(LeaveRequest data)
{
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId);
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId, AccessToken);
if (profile == null)
{
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
}
var fullName = $"{profile!.Prefix!.Name}{profile!.FirstName} {profile!.LastName}";
var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}";
var lastLeaveRequest =
await _leaveRequestRepository.GetLastLeaveRequestByTypeForUserAsync(data.KeycloakUserId,
@ -108,8 +135,8 @@ namespace BMA.EHR.Leave.Service.Controllers
leaveTypeName = data.Type.Name,
dear = approver,
fullname = fullName,
positionName = profile!.Position == null ? "-" : profile!.Position!.Name,
positionLeaveName = profile!.Position == null ? "-" : profile!.Position!.Name,
positionName = profile!.Position == null ? "-" : profile!.Position,
positionLeaveName = profile!.Position == null ? "-" : profile!.Position,
organizationName = profile!.Oc ?? "",
leaveDetail = data.LeaveDetail,
leaveDateStart = data.LeaveStartDate.Date.ToThaiShortDate(),
@ -129,13 +156,13 @@ namespace BMA.EHR.Leave.Service.Controllers
private async Task<dynamic> GetReport02(LeaveRequest data)
{
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId);
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId, AccessToken);
if (profile == null)
{
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
}
var fullName = $"{profile!.Prefix!.Name}{profile!.FirstName} {profile!.LastName}";
var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}";
var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty);
var approver = string.Empty;
@ -157,8 +184,8 @@ namespace BMA.EHR.Leave.Service.Controllers
leaveTypeName = data.Type.Name,
dear = approver,
fullname = fullName,
positionName = profile!.Position == null ? "-" : profile!.Position!.Name,
positionLeaveName = profile!.Position == null ? "-" : profile!.Position!.Name,
positionName = profile!.Position == null ? "-" : profile!.Position,
positionLeaveName = profile!.Position == null ? "-" : profile!.Position,
organizationName = profile!.Oc ?? "",
wifeDayName = data.WifeDayName ?? "",
wifeDayDateBorn = data.WifeDayDateBorn ?? "",
@ -173,13 +200,13 @@ namespace BMA.EHR.Leave.Service.Controllers
private async Task<dynamic> GetReport03(LeaveRequest data)
{
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId);
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId, AccessToken);
if (profile == null)
{
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
}
var fullName = $"{profile!.Prefix!.Name}{profile!.FirstName} {profile!.LastName}";
var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}";
var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty);
var approver = string.Empty;
@ -203,8 +230,8 @@ namespace BMA.EHR.Leave.Service.Controllers
leaveTypeName = data.Type.Name,
dear = approver,
fullname = fullName,
positionName = profile!.Position == null ? "-" : profile!.Position!.Name,
positionLeaveName = profile!.Position == null ? "-" : profile!.Position!.Name,
positionName = profile!.Position == null ? "-" : profile!.Position,
positionLeaveName = profile!.Position == null ? "-" : profile!.Position,
organizationName = profile!.Oc ?? "",
restDayOldTotal = data.RestDayOldTotal,
@ -224,13 +251,13 @@ namespace BMA.EHR.Leave.Service.Controllers
private async Task<dynamic> GetReport04(LeaveRequest data, bool isHajj = false)
{
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId);
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId, AccessToken);
if (profile == null)
{
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
}
var fullName = $"{profile!.Prefix!.Name}{profile!.FirstName} {profile!.LastName}";
var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}";
var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty);
var approver = string.Empty;
@ -254,8 +281,8 @@ namespace BMA.EHR.Leave.Service.Controllers
leaveTypeName = data.Type.Name,
dear = approver,
fullname = fullName,
positionName = profile!.Position == null ? "-" : profile!.Position!.Name,
positionLeaveName = profile!.Position == null ? "-" : profile!.Position!.Name,
positionName = profile!.Position == null ? "-" : profile!.Position,
positionLeaveName = profile!.Position == null ? "-" : profile!.Position,
organizationName = profile!.Oc ?? "",
@ -282,8 +309,8 @@ namespace BMA.EHR.Leave.Service.Controllers
leaveTypeName = data.Type.Name,
dear = approver,
fullname = fullName,
positionName = profile!.Position == null ? "-" : profile!.Position!.Name,
positionLeaveName = profile!.Position == null ? "-" : profile!.Position!.Name,
positionName = profile!.Position == null ? "-" : profile!.Position,
positionLeaveName = profile!.Position == null ? "-" : profile!.Position,
organizationName = profile!.Oc ?? "",
leavebirthDate = data.LeaveBirthDate == null ? "" : data.LeaveBirthDate.Value.Date.ToThaiShortDate(),
@ -307,13 +334,13 @@ namespace BMA.EHR.Leave.Service.Controllers
private async Task<dynamic> GetReport05(LeaveRequest data)
{
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId);
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId, AccessToken);
if (profile == null)
{
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
}
var fullName = $"{profile!.Prefix!.Name}{profile!.FirstName} {profile!.LastName}";
var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}";
var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty);
var approver = string.Empty;
@ -335,8 +362,8 @@ namespace BMA.EHR.Leave.Service.Controllers
leaveTypeName = data.Type.Name,
dear = approver,
fullname = fullName,
positionName = profile!.Position == null ? "-" : profile!.Position!.Name,
positionLeaveName = profile!.Position == null ? "-" : profile!.Position!.Name,
positionName = profile!.Position == null ? "-" : profile!.Position,
positionLeaveName = profile!.Position == null ? "-" : profile!.Position,
organizationName = profile!.Oc ?? "",
absentDaySummon = data.AbsentDaySummon,
@ -355,13 +382,13 @@ namespace BMA.EHR.Leave.Service.Controllers
private async Task<dynamic> GetReport06(LeaveRequest data)
{
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId);
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId, AccessToken);
if (profile == null)
{
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
}
var fullName = $"{profile!.Prefix!.Name}{profile!.FirstName} {profile!.LastName}";
var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}";
var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty);
var approver = string.Empty;
@ -383,8 +410,8 @@ namespace BMA.EHR.Leave.Service.Controllers
leaveTypeName = data.Type.Name,
dear = approver,
fullname = fullName,
positionName = profile!.Position == null ? "-" : profile!.Position!.Name,
positionLeaveName = profile!.Position == null ? "-" : profile!.Position!.Name,
positionName = profile!.Position == null ? "-" : profile!.Position,
positionLeaveName = profile!.Position == null ? "-" : profile!.Position,
organizationName = profile!.Oc ?? "",
leavebirthDate = data.LeaveBirthDate == null ? "" : data.LeaveBirthDate.Value.Date.ToThaiShortDate(),
@ -410,13 +437,13 @@ namespace BMA.EHR.Leave.Service.Controllers
private async Task<dynamic> GetReport07(LeaveRequest data)
{
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId);
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId, AccessToken);
if (profile == null)
{
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
}
var fullName = $"{profile!.Prefix!.Name}{profile!.FirstName} {profile!.LastName}";
var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}";
var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty);
var approver = string.Empty;
@ -439,8 +466,8 @@ namespace BMA.EHR.Leave.Service.Controllers
dear = approver,
fullname = fullName,
fullnameEng = "",
positionName = profile!.Position == null ? "-" : profile!.Position!.Name,
positionLeaveName = profile!.Position == null ? "-" : profile!.Position!.Name,
positionName = profile!.Position == null ? "-" : profile!.Position,
positionLeaveName = profile!.Position == null ? "-" : profile!.Position,
organizationName = profile!.Oc ?? "",
leaveDateStart = data.LeaveStartDate.Date.ToThaiShortDate(),
@ -452,13 +479,13 @@ namespace BMA.EHR.Leave.Service.Controllers
private async Task<dynamic> GetReport08(LeaveRequest data)
{
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId);
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId, AccessToken);
if (profile == null)
{
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
}
var fullName = $"{profile!.Prefix!.Name}{profile!.FirstName} {profile!.LastName}";
var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}";
var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty);
var approver = string.Empty;
@ -480,8 +507,8 @@ namespace BMA.EHR.Leave.Service.Controllers
leaveTypeName = data.Type.Name,
dear = approver,
fullname = fullName,
positionName = profile!.Position == null ? "-" : profile!.Position!.Name,
positionLeaveName = profile!.Position == null ? "-" : profile!.Position!.Name,
positionName = profile!.Position == null ? "-" : profile!.Position,
positionLeaveName = profile!.Position == null ? "-" : profile!.Position,
organizationName = profile!.Oc ?? "",
leaveSalary = data.LeaveSalary,
@ -507,13 +534,13 @@ namespace BMA.EHR.Leave.Service.Controllers
private async Task<dynamic> GetReport09(LeaveRequest data)
{
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId);
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId, AccessToken);
if (profile == null)
{
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
}
var fullName = $"{profile!.Prefix!.Name}{profile!.FirstName} {profile!.LastName}";
var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}";
var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty);
var approver = string.Empty;
@ -535,8 +562,8 @@ namespace BMA.EHR.Leave.Service.Controllers
leaveTypeName = data.Type.Name,
dear = approver,
fullname = fullName,
positionName = profile!.Position == null ? "-" : profile!.Position!.Name,
positionLeaveName = profile!.Position == null ? "-" : profile!.Position!.Name,
positionName = profile!.Position == null ? "-" : profile!.Position,
positionLeaveName = profile!.Position == null ? "-" : profile!.Position,
organizationName = profile!.Oc ?? "",
@ -657,13 +684,13 @@ namespace BMA.EHR.Leave.Service.Controllers
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
}
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId);
var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(data.KeycloakUserId, AccessToken);
if (profile == null)
{
return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound);
}
var fullName = $"{profile!.Prefix!.Name}{profile!.FirstName} {profile!.LastName}";
var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}";
var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty);
var approver = string.Empty;
@ -684,8 +711,8 @@ namespace BMA.EHR.Leave.Service.Controllers
dateSendLeave = data.CreatedAt.Date.ToThaiShortDate(),
leaveTypeName = data.Type.Name,
fullname = fullName,
positionName = profile!.Position == null ? "-" : profile!.Position!.Name,
positionLeaveName = profile!.Position == null ? "-" : profile!.Position!.Name,
positionName = profile!.Position == null ? "-" : profile!.Position,
positionLeaveName = profile!.Position == null ? "-" : profile!.Position,
organizationName = profile!.Oc ?? "",
leaveDateStart = data.LeaveStartDate.Date.ToThaiShortDate(),
leaveDateEnd = data.LeaveEndDate.Date.ToThaiShortDate(),