hrms-api-backend/BMA.EHR.Application/Repositories/UserProfileRepository.cs

1465 lines
50 KiB
C#
Raw Normal View History

using BMA.EHR.Application.Common.Interfaces;
using BMA.EHR.Application.Responses.Insignias;
using BMA.EHR.Application.Responses.Leaves;
using BMA.EHR.Application.Responses.Organizations;
using BMA.EHR.Application.Responses.Profiles;
using BMA.EHR.Domain.Models.HR;
using BMA.EHR.Domain.Models.MetaData;
using BMA.EHR.Domain.Models.Organizations;
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
namespace BMA.EHR.Application.Repositories
{
public class UserProfileRepository : GenericRepository<Guid, Profile>
{
#region " Fields "
private readonly IApplicationDBContext _dbContext;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IConfiguration _configuration;
#endregion
#region " Costructor and Destructor "
public UserProfileRepository(IApplicationDBContext dbContext,
IHttpContextAccessor httpContextAccessor,
IConfiguration configuration) : base(dbContext, httpContextAccessor)
{
_dbContext = dbContext;
_httpContextAccessor = httpContextAccessor;
_configuration = configuration;
}
#endregion
#region " Methods "
public async Task<OrganizationEntity?> GetOrganizationById(Guid id)
{
var data = await _dbContext.Set<OrganizationEntity>().AsQueryable()
.FirstOrDefaultAsync(x => x.Id == id);
return data;
}
public async Task<OrganizationAgency?> GetOrgAgencyById(Guid id)
{
var data = await _dbContext.Set<OrganizationAgency>().AsQueryable()
.FirstOrDefaultAsync(x => x.Id == id);
2024-01-10 09:52:59 +07:00
return data;
}
public async Task<OrganizationGovernmentAgency?> GetOrgGovAgencyById(Guid id)
{
var data = await _dbContext.Set<OrganizationGovernmentAgency>().AsQueryable()
.FirstOrDefaultAsync(x => x.Id == id);
return data;
}
2024-01-10 09:52:59 +07:00
public async Task<List<GetProfileByRootIdDto>> GetOfficerProfileByRootIdAsync(Guid rootId, string? accessToken)
{
try
{
2025-11-10 15:02:44 +07:00
var apiPath = $"{_configuration["API"]}/org/unauthorize/root/officer/{rootId}";
2024-08-16 10:39:27 +07:00
var apiKey = _configuration["API_KEY"];
2024-08-16 10:39:27 +07:00
var apiResult = await GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetProfileByRootIdResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
//var data = await _dbContext.Set<Profile>().AsQueryable()
// .Include(p => p.Prefix)
// .Include(p => p.Position)
// .Include(p => p.PositionLevel)
// .Include(p => p.Salaries)
// .FirstOrDefaultAsync(p => p.KeycloakId == keycloakId);
//return data;
}
catch
{
throw;
}
}
public async Task<List<GetProfileByRootIdDto>> GetEmployeeProfileByRootIdAsync(Guid rootId, string? accessToken)
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/root/employee/{rootId}";
2024-08-16 10:39:27 +07:00
var apiKey = _configuration["API_KEY"];
2024-08-16 10:39:27 +07:00
var apiResult = await GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetProfileByRootIdResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
//var data = await _dbContext.Set<Profile>().AsQueryable()
// .Include(p => p.Prefix)
// .Include(p => p.Position)
// .Include(p => p.PositionLevel)
// .Include(p => p.Salaries)
// .FirstOrDefaultAsync(p => p.KeycloakId == keycloakId);
//return data;
}
catch
{
throw;
}
}
2025-05-08 22:19:12 +07:00
public async Task<List<GetProfileByRootIdDto>> GetEmployeeProfileByPositionAsync(Guid rootId, string[] empPosId, string? accessToken)
{
try
{
2025-11-10 15:02:44 +07:00
var apiPath = $"{_configuration["API"]}/org/unauthorize/find/employee/position";
var apiKey = _configuration["API_KEY"];
var body = new
{
rootId,
empPosId
};
2025-05-08 22:19:12 +07:00
//var bodyJson = JsonConvert.SerializeObject(bodyRaw);
// สร้าง HTTP content
//var body = new StringContent(bodyJson, Encoding.UTF8, "application/json");
var apiResult = await PostExternalAPIAsync(apiPath, accessToken ?? "", body, apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetProfileByRootIdResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
2025-12-30 23:55:03 +07:00
catch (Exception ex)
{
throw;
}
}
2024-05-30 09:32:34 +07:00
public async Task<GetProfileByKeycloakIdDto?> GetProfileByKeycloakIdAsync(Guid keycloakId, string? accessToken)
{
try
{
2024-05-30 09:32:34 +07:00
var apiPath = $"{_configuration["API"]}/org/dotnet/keycloak/{keycloakId}";
2024-08-16 10:39:27 +07:00
var apiKey = _configuration["API_KEY"];
2024-05-30 09:32:34 +07:00
2024-08-16 10:39:27 +07:00
var apiResult = await GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey);
2024-05-30 09:32:34 +07:00
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetProfileByKeycloakIdResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
2024-11-18 18:43:46 +07:00
}
catch
{
throw;
}
}
2024-05-30 09:32:34 +07:00
public async Task<GetProfileByKeycloakIdDto?> GetProfileByKeycloakIdNewAsync(Guid keycloakId, string? accessToken,CancellationToken cancellationToken = default)
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/by-keycloak/{keycloakId}";
var apiKey = _configuration["API_KEY"];
var apiResult = await GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey, cancellationToken);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetProfileByKeycloakIdResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
2026-01-29 13:22:41 +07:00
public async Task<GetProfileByKeycloakIdDto?> GetProfileByKeycloakIdNew2Async(Guid keycloakId, string? accessToken)
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/by-keycloak2/{keycloakId}";
var apiKey = _configuration["API_KEY"];
var apiResult = await GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetProfileByKeycloakIdResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
public async Task<GetProfileLeaveByKeycloakDto?> GetProfileLeaveByKeycloakIdAsync(Guid keycloakId, string? accessToken)
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/profile-leave/keycloak/{keycloakId}";
var apiKey = _configuration["API_KEY"];
var apiResult = await GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetProfileLeaveByKeycloakResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
public async Task<GetProfileLeaveByKeycloakDto?> GetProfileLeaveReportByKeycloakIdAsync(Guid keycloakId, string? accessToken, string? report)
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/profile-leave/keycloak";
var apiKey = _configuration["API_KEY"];
var body = new
{
keycloakId = keycloakId,
report = report
};
var profiles = new List<SearchProfileDto>();
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetProfileLeaveByKeycloakResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
public async Task<GetProfileByKeycloakIdDto?> GetProfileByProfileIdAsync(Guid profileId, string? accessToken)
2024-11-18 18:43:46 +07:00
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/profile/{profileId}";
2024-11-18 18:43:46 +07:00
var apiKey = _configuration["API_KEY"];
2024-05-30 09:32:34 +07:00
2024-11-18 18:43:46 +07:00
var apiResult = await GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetProfileByKeycloakIdResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
2024-06-20 13:37:25 +07:00
public async Task<bool> UpdateDutyTimeAsync(Guid profileId, Guid roundId, DateTime effectiveDate, string? accessToken)
{
try
{
2024-06-20 13:37:25 +07:00
var apiPath = $"{_configuration["API"]}/org/dotnet/update-dutytime";
2024-08-16 10:39:27 +07:00
var apiKey = _configuration["API_KEY"];
2023-12-18 15:50:42 +07:00
2024-06-20 13:37:25 +07:00
var body = new
{
2024-06-20 13:37:25 +07:00
EffevtiveDate = effectiveDate,
RoundId = roundId,
ProfileId = profileId
};
2023-12-18 15:50:42 +07:00
2024-08-16 10:39:27 +07:00
var apiResult = await PostExternalAPIBooleanAsync(apiPath, accessToken ?? "", body, apiKey);
2024-06-20 13:37:25 +07:00
return apiResult;
//var profile = await _dbContext.Set<Profile>()
// .AsQueryable()
// .Include(x => x.Prefix)
// .FirstOrDefaultAsync(x => x.Id == profileId);
2024-06-20 13:37:25 +07:00
//if (profile == null)
//{
// throw new Exception(GlobalMessages.DataNotFound);
//}
//else
//{
// var fullName = $"{profile.Prefix.Name}{profile.FirstName} {profile.LastName}";
// Console.WriteLine(fullName);
// profile.DutyTimeId = roundId;
// profile.DutyTimeEffectiveDate = effectiveDate;
// await UpdateAsync(profile);
// return true;
//}
}
catch
{
throw;
}
}
2024-06-20 13:37:25 +07:00
public async Task<List<GetProfileByKeycloakIdDto>> GetProfileWithKeycloak(string? accessToken)
2023-12-24 13:28:37 +07:00
{
try
{
2024-06-20 13:37:25 +07:00
var apiPath = $"{_configuration["API"]}/org/dotnet/keycloak";
2024-08-16 10:39:27 +07:00
var apiKey = _configuration["API_KEY"];
2023-12-24 13:28:37 +07:00
2024-08-16 10:39:27 +07:00
var apiResult = await GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey);
2024-06-20 13:37:25 +07:00
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetListProfileByKeycloakIdResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
2023-12-24 13:28:37 +07:00
}
catch
{
throw;
}
}
2024-12-13 12:12:08 +07:00
public async Task<List<GetProfileByKeycloakIdRootDto>> GetProfileWithKeycloakAllOfficer(string? accessToken, int? node, string? nodeId, bool isAll)
2024-12-12 00:00:43 +07:00
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/keycloak-all-officer";
var apiKey = _configuration["API_KEY"];
var body = new
{
node = node,
nodeId = nodeId,
2024-12-13 12:12:08 +07:00
isAll = isAll,
2024-12-12 00:00:43 +07:00
};
var profiles = new List<SearchProfileDto>();
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
if (apiResult != null)
{
2024-12-13 11:52:58 +07:00
var raw = JsonConvert.DeserializeObject<GetListProfileByKeycloakIdRootResultDto>(apiResult);
2024-12-12 00:00:43 +07:00
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
public async Task<List<GetProfileByKeycloakIdRootDto>> GetProfileWithNoneValidateKeycloakAllOfficer(string? accessToken, int? node, string? nodeId, bool isAll)
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/none-validate-keycloak-all-officer";
var apiKey = _configuration["API_KEY"];
var body = new
{
node = node,
nodeId = nodeId,
isAll = isAll,
};
var profiles = new List<SearchProfileDto>();
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetListProfileByKeycloakIdRootResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
2025-02-04 11:29:22 +07:00
public async Task<List<GetProfileByKeycloakIdRootDto>> GetProfileWithKeycloakAllOfficerRetireFilter(string? accessToken, int? node, string? nodeId, bool isAll, bool? isRetirement)
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/keycloak-all-officer";
var apiKey = _configuration["API_KEY"];
var body = new
{
node = node,
nodeId = nodeId,
isAll = isAll,
isRetirement = isRetirement,
};
var profiles = new List<SearchProfileDto>();
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetListProfileByKeycloakIdRootResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
2024-12-13 12:12:08 +07:00
public async Task<List<GetProfileByKeycloakIdRootDto>> GetProfileWithKeycloakAllEmployee(string? accessToken, int? node, string? nodeId, bool isAll)
2024-12-12 00:00:43 +07:00
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/keycloak-all-employee";
2025-03-11 17:33:10 +07:00
var apiKey = _configuration["API_KEY"];
var body = new
{
node = node,
nodeId = nodeId,
isAll = isAll,
};
var profiles = new List<SearchProfileDto>();
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetListProfileByKeycloakIdRootResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
public async Task<List<GetProfileByKeycloakIdRootDto>> GetProfileWithNoneValidateKeycloakAllEmployee(string? accessToken, int? node, string? nodeId, bool isAll)
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/none-validate-keycloak-all-employee";
var apiKey = _configuration["API_KEY"];
var body = new
{
node = node,
nodeId = nodeId,
isAll = isAll,
};
var profiles = new List<SearchProfileDto>();
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetListProfileByKeycloakIdRootResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
2025-03-11 17:33:10 +07:00
public async Task<List<GetProfileByKeycloakIdRootDto>> GetProfileWithKeycloakAllOfficerAndRevision(string? accessToken, int? node, string? nodeId, bool isAll, string? revisionId)
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/keycloak-all-officer";
var apiKey = _configuration["API_KEY"];
var body = new
{
node = node,
nodeId = nodeId,
isAll = isAll,
2025-03-12 10:17:43 +07:00
revisionId = revisionId,
2025-03-11 17:33:10 +07:00
};
var profiles = new List<SearchProfileDto>();
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetListProfileByKeycloakIdRootResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
public async Task<List<GetProfileByKeycloakIdRootDto>> GetProfileWithNoneValidateKeycloakAllOfficerAndRevision(string? accessToken, int? node, string? nodeId, bool isAll, string? revisionId)
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/none-validate-keycloak-all-officer";
var apiKey = _configuration["API_KEY"];
var body = new
{
node = node,
nodeId = nodeId,
isAll = isAll,
revisionId = revisionId,
};
var profiles = new List<SearchProfileDto>();
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetListProfileByKeycloakIdRootResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
2025-12-30 23:55:03 +07:00
public async Task<List<GetProfileByKeycloakIdRootDto>> GetProfileByAdminRole(string? accessToken, int? node, string? nodeId, string role, string? revisionId, int? reqNode, string? reqNodeId, DateTime? startDate, DateTime? endDate)
2025-06-17 18:07:41 +07:00
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/officer-by-admin-role";
var apiKey = _configuration["API_KEY"];
var body = new
{
node = node,
nodeId = nodeId,
role = role,
revisionId = revisionId,
2025-10-09 21:43:25 +07:00
reqNode = reqNode,
reqNodeId = reqNodeId,
2026-01-13 12:05:52 +07:00
//startDate = startDate,
//endDate = endDate
2025-06-17 18:07:41 +07:00
};
var profiles = new List<SearchProfileDto>();
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetListProfileByKeycloakIdRootResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
2025-12-30 23:55:03 +07:00
public async Task<List<GetProfileByKeycloakIdRootDto>> GetProfileByAdminRolev2(string? accessToken, int? node, string? nodeId, string role, string? revisionId, int? reqNode, string? reqNodeId, DateTime? startDate, DateTime? endDate)
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/officer-by-admin-rolev2";
var apiKey = _configuration["API_KEY"];
var body = new
{
node = node,
nodeId = nodeId,
role = role,
// revisionId = revisionId,
reqNode = reqNode,
reqNodeId = reqNodeId,
// startDate = startDate,
// endDate = endDate
date = endDate
};
2026-01-02 21:46:39 +07:00
Console.WriteLine(body);
2025-12-30 23:55:03 +07:00
var profiles = new List<SearchProfileDto>();
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetListProfileByKeycloakIdRootResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
2026-01-02 21:46:39 +07:00
return new List<GetProfileByKeycloakIdRootDto>();
2025-12-30 23:55:03 +07:00
}
catch
{
throw;
}
}
2026-01-09 18:59:11 +07:00
public async Task<List<GetProfileByKeycloakIdRootDto>> GetProfileByAdminRolev3(string? accessToken, int? node, string? nodeId, string role, string? revisionId, int? reqNode, string? reqNodeId, DateTime? startDate, DateTime? endDate)
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/officer-by-admin-rolev3";
var apiKey = _configuration["API_KEY"];
var body = new
{
node = node,
nodeId = nodeId,
role = role,
// revisionId = revisionId,
reqNode = reqNode,
reqNodeId = reqNodeId,
startDate = startDate,
endDate = endDate
};
var profiles = new List<SearchProfileDto>();
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetListProfileByKeycloakIdRootResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
2026-01-11 16:35:02 +07:00
public async Task<List<GetProfileByKeycloakIdRootDto>> GetProfileByAdminRolev4(string? accessToken, int? node, string? nodeId, string role, string? revisionId, int? reqNode, string? reqNodeId, DateTime? startDate, DateTime? endDate)
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/officer-by-admin-rolev4";
var apiKey = _configuration["API_KEY"];
var body = new
{
node = node,
nodeId = nodeId,
role = role,
// revisionId = revisionId,
reqNode = reqNode,
reqNodeId = reqNodeId,
// startDate = startDate,
// endDate = endDate
date = endDate
};
Console.WriteLine(body);
var profiles = new List<SearchProfileDto>();
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetListProfileByKeycloakIdRootResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return new List<GetProfileByKeycloakIdRootDto>();
}
catch
{
throw;
}
}
2025-03-11 17:33:10 +07:00
public async Task<List<GetProfileByKeycloakIdRootDto>> GetProfileWithKeycloakAllOfficerRetireFilterAndRevision(string? accessToken, int? node, string? nodeId, bool isAll, bool? isRetirement, string? revisionId)
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/keycloak-all-officer";
var apiKey = _configuration["API_KEY"];
var body = new
{
node = node,
nodeId = nodeId,
isAll = isAll,
isRetirement = isRetirement,
2025-03-12 10:17:43 +07:00
revisionId = revisionId,
2025-03-11 17:33:10 +07:00
};
var profiles = new List<SearchProfileDto>();
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
if (apiResult != null)
2025-08-22 16:53:00 +07:00
{
var raw = JsonConvert.DeserializeObject<GetListProfileByKeycloakIdRootResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
public async Task<List<GetProfileByKeycloakIdRootDto>> GetProfileWithKeycloakAllOfficerRetireFilterAndRevisionAndDate(string? accessToken, int? node, string? nodeId, bool isAll, bool? isRetirement, string? revisionId, DateTime? startDate, DateTime? endDate)
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/keycloak-all-officer/date";
var apiKey = _configuration["API_KEY"];
var body = new
{
node = node,
nodeId = nodeId,
isAll = isAll,
isRetirement = isRetirement,
revisionId = revisionId,
2025-08-25 14:37:12 +07:00
startDate = startDate,
endDate = endDate,
2025-08-22 16:53:00 +07:00
};
var profiles = new List<SearchProfileDto>();
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
if (apiResult != null)
2025-03-11 17:33:10 +07:00
{
var raw = JsonConvert.DeserializeObject<GetListProfileByKeycloakIdRootResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
public async Task<List<GetProfileByKeycloakIdRootDto>> GetProfileWithKeycloakAllEmployeeAndRevision(string? accessToken, int? node, string? nodeId, bool isAll, string? revisionId)
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/keycloak-all-employee";
2024-12-12 00:00:43 +07:00
var apiKey = _configuration["API_KEY"];
var body = new
{
node = node,
nodeId = nodeId,
2024-12-13 12:12:08 +07:00
isAll = isAll,
2025-03-12 10:17:43 +07:00
revisionId = revisionId,
2024-12-12 00:00:43 +07:00
};
var profiles = new List<SearchProfileDto>();
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
if (apiResult != null)
{
2024-12-13 11:52:58 +07:00
var raw = JsonConvert.DeserializeObject<GetListProfileByKeycloakIdRootResultDto>(apiResult);
2024-12-12 00:00:43 +07:00
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
public async Task<List<GetProfileByKeycloakIdRootDto>> GetProfileWithNoneValidateKeycloakAllEmployeeAndRevision(string? accessToken, int? node, string? nodeId, bool isAll, string? revisionId)
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/none-validate-keycloak-all-employee";
var apiKey = _configuration["API_KEY"];
var body = new
{
node = node,
nodeId = nodeId,
isAll = isAll,
revisionId = revisionId,
};
var profiles = new List<SearchProfileDto>();
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetListProfileByKeycloakIdRootResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
2025-06-17 18:07:41 +07:00
2025-12-30 23:55:03 +07:00
public async Task<List<GetProfileByKeycloakIdRootDto>> GetEmployeeByAdminRole(string? accessToken, int? node, string? nodeId, string role, string? revisionId, int? reqNode, string? reqNodeId, DateTime? startDate, DateTime? endDate)
2025-06-17 18:07:41 +07:00
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/employee-by-admin-role";
var apiKey = _configuration["API_KEY"];
var body = new
{
node = node,
nodeId = nodeId,
role = role,
revisionId = revisionId,
reqNode = reqNode,
reqNodeId = reqNodeId,
startDate = startDate,
endDate = endDate
2025-06-17 18:07:41 +07:00
};
var profiles = new List<SearchProfileDto>();
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetListProfileByKeycloakIdRootResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
2025-10-09 23:21:36 +07:00
public async Task<GetProfileByKeycloakIdRootAddTotalDto> SearchProfile(string? citizenId, string? firstName, string? lastName, string accessToken, int page, int pageSize, string? role, string? nodeId, int? node)
2023-11-23 15:48:09 +07:00
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/search";
2024-08-16 10:39:27 +07:00
var apiKey = _configuration["API_KEY"];
var body = new
{
citizenId = citizenId,
firstName = firstName,
lastName = lastName,
role = role,
nodeId = nodeId,
node = node,
2025-10-09 21:43:25 +07:00
page = page,
pageSize = pageSize,
};
2023-12-20 15:01:23 +07:00
2025-10-09 23:21:36 +07:00
var profiles = new List<GetProfileByKeycloakIdRootDto>();
2025-10-09 21:43:25 +07:00
var total = 0;
2023-12-20 15:01:23 +07:00
2024-08-16 10:39:27 +07:00
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
if (apiResult != null)
{
2025-10-09 23:21:36 +07:00
var raw = JsonConvert.DeserializeObject<GetListProfileByKeycloakIdRootResultAddTotalDto>(apiResult);
if (raw != null && raw.Result != null)
{
2025-10-12 16:11:31 +07:00
profiles = raw.Result.Data;
2025-10-09 23:21:36 +07:00
total = raw.Result.Total;
}
}
2023-12-20 15:01:23 +07:00
2025-10-09 23:21:36 +07:00
return new GetProfileByKeycloakIdRootAddTotalDto { Data = profiles, Total = total };
2023-12-20 15:01:23 +07:00
}
catch
{
throw;
}
}
2025-10-09 23:21:36 +07:00
public async Task<GetProfileByKeycloakIdRootAddTotalDto> SearchProfileEmployee(string? citizenId, string? firstName, string? lastName, string accessToken, int page, int pageSize, string? role, string? nodeId, int? node)
2023-12-20 15:01:23 +07:00
{
try
{
2024-06-20 13:37:25 +07:00
var apiPath = $"{_configuration["API"]}/org/dotnet/search-employee";
2024-08-16 10:39:27 +07:00
var apiKey = _configuration["API_KEY"];
2024-06-20 13:37:25 +07:00
var body = new
{
citizenId = citizenId,
firstName = firstName,
2025-07-11 10:03:38 +07:00
lastName = lastName,
role = role,
nodeId = nodeId,
node = node,
2025-10-09 21:43:25 +07:00
page = page,
pageSize = pageSize,
2024-06-20 13:37:25 +07:00
};
2025-10-09 23:21:36 +07:00
var profiles = new List<GetProfileByKeycloakIdRootDto>();
2025-10-09 21:43:25 +07:00
var total = 0;
2023-11-23 15:48:09 +07:00
2024-08-16 10:39:27 +07:00
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
2024-06-20 13:37:25 +07:00
if (apiResult != null)
{
2025-10-09 23:21:36 +07:00
var raw = JsonConvert.DeserializeObject<GetListProfileByKeycloakIdRootResultAddTotalDto>(apiResult);
2024-06-20 13:37:25 +07:00
if (raw != null && raw.Result != null)
{
2025-10-09 23:21:36 +07:00
profiles.AddRange(raw.Result.Data);
total = raw.Result.Total;
2024-06-20 13:37:25 +07:00
}
}
2023-11-23 15:48:09 +07:00
2025-10-09 23:21:36 +07:00
return new GetProfileByKeycloakIdRootAddTotalDto { Data = profiles, Total = total };
2023-11-23 15:48:09 +07:00
}
catch
{
throw;
}
}
2024-06-20 13:37:25 +07:00
public string GetUserFullName(Guid keycloakId, string? accessToken)
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/user-fullname/{keycloakId}";
2024-08-16 10:39:27 +07:00
var apiKey = _configuration["API_KEY"];
2024-06-20 13:37:25 +07:00
2024-08-16 10:39:27 +07:00
var apiResult = GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey);
2024-06-20 13:37:25 +07:00
if (apiResult.Result != null)
{
var raw = JsonConvert.DeserializeObject<GetUserFullNameResultDto>(apiResult.Result);
if (raw != null)
return raw.Result;
}
return string.Empty;
}
catch
{
throw;
}
}
2024-06-20 13:37:25 +07:00
public Guid GetUserOCId(Guid keycloakId, string? accessToken)
{
try
{
2024-06-20 13:37:25 +07:00
var apiPath = $"{_configuration["API"]}/org/dotnet/user-oc/{keycloakId}";
2024-08-16 10:39:27 +07:00
var apiKey = _configuration["API_KEY"];
2024-06-20 13:37:25 +07:00
2024-08-16 10:39:27 +07:00
var apiResult = GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey);
2024-06-20 13:37:25 +07:00
if (apiResult.Result != null)
{
2024-08-25 16:31:22 +07:00
var raw = JsonConvert.DeserializeObject<GetUserOCIdDto>(apiResult.Result);
if (raw == null || raw.RootId == null)
return Guid.Empty;
return raw.RootId;
2024-06-20 13:37:25 +07:00
}
return Guid.Empty;
//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);
2024-06-20 13:37:25 +07:00
//return data.OrganizationPosition!.Organization!.Id;
}
catch
{
throw;
}
}
2025-05-06 18:16:14 +07:00
public async Task<GetUserOCAllDto?> GetUserOCAll(Guid keycloakId, string? accessToken)
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/user-oc-all/{keycloakId}";
var apiKey = _configuration["API_KEY"];
var apiResult = await GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetUserOCAllResultDto>(apiResult);
return raw?.Result;
}
return null;
}
catch
{
throw;
}
}
2025-04-17 23:09:37 +07:00
public async Task<GetUserOCIdDto?> GetUserOC(Guid keycloakId, string? accessToken)
2024-11-11 20:46:45 +07:00
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/user-oc/{keycloakId}";
var apiKey = _configuration["API_KEY"];
var apiResult = GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey);
if (apiResult.Result != null)
{
2025-04-17 23:09:37 +07:00
var raw = JsonConvert.DeserializeObject<GetUserOCIdResultDto>(apiResult.Result);
2024-11-11 20:46:45 +07:00
2025-04-17 23:09:37 +07:00
if (raw != null)
return raw.Result;
2024-11-11 20:46:45 +07:00
}
return null;
}
catch
{
throw;
}
}
2024-06-20 13:37:25 +07:00
public Guid? GetRootOcId(Guid ocId, string? accessToken)
2023-12-12 14:17:00 +07:00
{
try
{
2024-06-20 13:37:25 +07:00
var apiPath = $"{_configuration["API"]}/org/dotnet/root-oc/{ocId}";
2024-08-16 10:39:27 +07:00
var apiKey = _configuration["API_KEY"];
2024-06-20 13:37:25 +07:00
2024-08-16 10:39:27 +07:00
var apiResult = GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey);
2024-06-20 13:37:25 +07:00
if (apiResult.Result != null)
{
var raw = JsonConvert.DeserializeObject<GetRootOCIdResultDto>(apiResult.Result);
if (raw != null)
return raw.Result;
}
return null;
//var data = _dbContext.Set<OrganizationEntity>()
// .FirstOrDefault(o => o.Id == ocId);
2023-12-12 14:17:00 +07:00
2024-06-20 13:37:25 +07:00
//return data == null ? Guid.Empty : data.OrganizationAgencyId;
2023-12-12 14:17:00 +07:00
}
catch
{
throw;
}
}
public GetOrganizationResponseDTO? GetOc(Guid ocId, int level, string? accessToken)
{
try
{
2026-01-02 21:46:39 +07:00
var apiPath = $"{_configuration["API"]}/org/find/allv2";
2024-08-16 10:39:27 +07:00
var apiKey = _configuration["API_KEY"];
var body = new
{
nodeId = ocId,
node = level
};
2024-08-16 10:39:27 +07:00
var apiResult = PostExternalAPIAsync(apiPath, accessToken ?? "", body, apiKey).Result;
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetOrganizationResponseResultDTO>(apiResult);
if (raw != null && raw.Result != null)
{
return raw.Result;
}
}
return null;
}
catch
{
throw;
}
}
public GetProfileByIdDto GetOfficerProfileById(Guid id, string? accessToken)
{
try
{
2024-07-01 15:59:41 +07:00
var apiPath = $"{_configuration["API"]}/org/profile/{id}";
2024-08-16 10:39:27 +07:00
var apiKey = _configuration["API_KEY"];
2024-08-16 10:39:27 +07:00
var apiResult = GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey);
if (apiResult.Result != null)
{
var raw = JsonConvert.DeserializeObject<GetProfileByIdResultDto>(apiResult.Result);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
public GetProfileByIdDto GetEmployeeProfileById(Guid id, string? accessToken)
{
try
{
var apiPath = $"{_configuration["API"]}/org/profile-employee/{id}";
2024-08-16 10:39:27 +07:00
var apiKey = _configuration["API_KEY"];
2024-08-16 10:39:27 +07:00
var apiResult = GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey);
if (apiResult.Result != null)
{
var raw = JsonConvert.DeserializeObject<GetProfileByIdResultDto>(apiResult.Result);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
2024-11-18 18:43:46 +07:00
public async Task<GetProfileByKeycloakIdDto?> GetOfficerProfileByCitizenId(string citizenId, string? accessToken)
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/citizenId/{citizenId}";
2024-08-16 10:39:27 +07:00
var apiKey = _configuration["API_KEY"];
2024-08-16 10:39:27 +07:00
var apiResult = GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey);
if (apiResult.Result != null)
{
2024-11-18 18:43:46 +07:00
var raw = JsonConvert.DeserializeObject<GetProfileByKeycloakIdResultDto>(apiResult.Result);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
2024-12-12 00:00:43 +07:00
public async Task<List<GetActiveRootDto>> GetActiveRootAsync(string? accessToken, Guid? revisionId)
{
try
{
var apiPath = $"{_configuration["API"]}/org/active/root/{revisionId}";
2024-08-16 10:39:27 +07:00
var apiKey = _configuration["API_KEY"];
2024-08-16 10:39:27 +07:00
var apiResult = await GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetActiveRootResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
public async Task<Guid?> GetLastRevision(string? accessToken)
{
try
{
var apiPath = $"{_configuration["API"]}/org/active/root/latest";
var apiKey = _configuration["API_KEY"];
var apiResult = await GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetLastRevisionDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
public async Task<List<GetActiveRootDto>> GetActiveRootLatestAsync(string? accessToken)
{
try
{
2025-11-10 15:02:44 +07:00
var apiPath = $"{_configuration["API"]}/org/unauthorize/active/root/all";
var apiKey = _configuration["API_KEY"];
var apiResult = await GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetActiveRootResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
public async Task PostProfileInsigniaAsync(PostProfileInsigniaDto body, string? accessToken)
{
try
{
var apiPath = $"{_configuration["API"]}/org/profile/insignia";
2024-08-16 10:39:27 +07:00
var apiKey = _configuration["API_KEY"];
var profiles = new List<SearchProfileDto>();
var apiResult = await PostExternalAPIBooleanAsync(apiPath, accessToken ?? "", body, apiKey);
}
catch
{
throw;
}
}
public async Task PostInsigniaMessageToSocket(string message, string userId, string? accessToken)
{
try
{
var apiPath = $"{_configuration["API"]}/org/through-socket/notify";
var apiKey = _configuration["API_KEY"];
var body = new
{
message = message,
userId = userId
};
var apiResult = await PostExternalAPIBooleanAsync(apiPath, accessToken ?? "", body, apiKey);
}
catch
{
throw;
}
}
2025-05-27 11:18:06 +07:00
public async Task PostProfileEmpInsigniaAsync(PostProfileEmpInsigniaDto body, string? accessToken)
{
try
{
var apiPath = $"{_configuration["API"]}/org/profile-employee/insignia";
var apiKey = _configuration["API_KEY"];
var profiles = new List<SearchProfileDto>();
2024-08-16 10:39:27 +07:00
var apiResult = await PostExternalAPIBooleanAsync(apiPath, accessToken ?? "", body, apiKey);
}
catch
{
throw;
}
}
public async Task<GetIsOfficerDto> GetIsOfficerRootAsync(string? accessToken, string sys)
{
try
{
var apiPath = $"{_configuration["API"]}/org/workflow/keycloak/isofficer-root/{sys}";
var apiKey = _configuration["API_KEY"];
var apiResult = await GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetIsOfficerResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return new GetIsOfficerDto { isOfficer = false, isStaff = false, isDirector = false };
}
catch
{
throw;
}
}
public async Task<List<GetMarkStatusDto>> GetInsigniaRequestsProfileAsync(string[] profileIds, string type, string? accessToken)
{
try
{
var apiPath = $"{_configuration["API"]}/org/dotnet/find/insignia-requests-profile/{type}";
var apiKey = _configuration["API_KEY"];
var body = new
{
profileIds
};
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetMarkStatusResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
2025-08-01 17:08:11 +07:00
public GetOrgProfileByProfileIdDto GetOrgProfileByProfileId(Guid id, string? accessToken)
{
try
{
var apiPath = $"{_configuration["API"]}/org/profile/org-user/{id}";
var apiKey = _configuration["API_KEY"];
var apiResult = GetExternalAPIAsync(apiPath, accessToken ?? "", apiKey);
if (apiResult.Result != null)
{
var raw = JsonConvert.DeserializeObject<GetOrgProfileByProfileIdResultDto>(apiResult.Result);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
public async Task<List<GetProfileSalaryDto>> GetProfileSalaryById(Guid profileId, string? accessToken)
{
try
{
var apiPath = $"{_configuration["API"]}/org/profile/insignia/position";
var apiKey = _configuration["API_KEY"];
var body = new
{
profileId = profileId.ToString(),
};
var apiResult = await PostExternalAPIAsync(apiPath, accessToken ?? "", body, apiKey);
if (apiResult != null)
{
var raw = JsonConvert.DeserializeObject<GetProfileSalaryResultDto>(apiResult);
if (raw != null)
return raw.Result;
}
return null;
}
catch
{
throw;
}
}
#endregion
}
}