diff --git a/BMA.EHR.Application/Repositories/Commands/CommandReportRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandReportRepository.cs index 4cdf4ee8..e5990cf9 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandReportRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandReportRepository.cs @@ -45,7 +45,7 @@ namespace BMA.EHR.Application.Repositories.Commands get { if (UserId != null || UserId != "") - return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!)); + return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), AccessToken); else return Guid.Empty; } diff --git a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs index 35835a86..3491e06c 100644 --- a/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs +++ b/BMA.EHR.Application/Repositories/Commands/CommandRepository.cs @@ -63,7 +63,7 @@ namespace BMA.EHR.Application.Repositories.Commands get { if (UserId != null || UserId != "") - return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!)); + return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), AccessToken); else return Guid.Empty; } diff --git a/BMA.EHR.Application/Repositories/GenericRepository.cs b/BMA.EHR.Application/Repositories/GenericRepository.cs index e7647057..9a21b29f 100644 --- a/BMA.EHR.Application/Repositories/GenericRepository.cs +++ b/BMA.EHR.Application/Repositories/GenericRepository.cs @@ -101,6 +101,27 @@ namespace BMA.EHR.Application.Repositories } } + protected async Task PostExternalAPIBooleanAsync(string apiPath, string accessToken, object? body) + { + try + { + var json = JsonConvert.SerializeObject(body); + var stringContent = new StringContent(json, UnicodeEncoding.UTF8, "application/json"); + stringContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); + + using (var client = new HttpClient()) + { + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken.Replace("Bearer ", "")); + var _res = await client.PostAsync(apiPath, stringContent); + return _res.IsSuccessStatusCode; + } + } + catch + { + throw; + } + } + #endregion public async Task GetProfileOrganizationAsync(string citizenId) diff --git a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs index 56ed3dbe..4a9731f3 100644 --- a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveRequestRepository.cs @@ -55,7 +55,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests get { if (UserId != null || UserId != "") - return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!)); + return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), AccessToken); else return Guid.Empty; } diff --git a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveTypeRepository.cs b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveTypeRepository.cs index f55e8fb4..65a43b25 100644 --- a/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveTypeRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/LeaveRequests/LeaveTypeRepository.cs @@ -46,7 +46,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.LeaveRequests get { if (UserId != null || UserId != "") - return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!)); + return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), AccessToken); else return Guid.Empty; } diff --git a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/AdditionalCheckRequestRepository.cs b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/AdditionalCheckRequestRepository.cs index f2c99845..ceae6c2b 100644 --- a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/AdditionalCheckRequestRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/AdditionalCheckRequestRepository.cs @@ -57,7 +57,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants get { if (UserId != null || UserId != "") - return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!)); + return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), AccessToken); else return Guid.Empty; } @@ -75,7 +75,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants var profile = await _userProfileRepository.GetProfileByKeycloakIdAsync(userId, AccessToken ?? ""); var profile_id = profile == null ? Guid.Empty : profile.Id; - var rootOc = _userProfileRepository.GetRootOcId(profile_id); + var rootOc = _userProfileRepository.GetRootOcId(profile_id, AccessToken); var approver = string.Empty; var list = new List(); if (rootOc != null) diff --git a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/DutyTimeRepository.cs b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/DutyTimeRepository.cs index 347f1a2b..2db889ac 100644 --- a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/DutyTimeRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/DutyTimeRepository.cs @@ -46,7 +46,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants get { if (UserId != null || UserId != "") - return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!)); + return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), AccessToken); else return Guid.Empty; } diff --git a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/ProcessUserTimeStampRepository.cs b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/ProcessUserTimeStampRepository.cs index 74535bd1..44e80537 100644 --- a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/ProcessUserTimeStampRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/ProcessUserTimeStampRepository.cs @@ -46,7 +46,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants get { if (UserId != null || UserId != "") - return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!)); + return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), AccessToken); else return Guid.Empty; } diff --git a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserCalendarRepository.cs b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserCalendarRepository.cs index 5ea0d3b8..05fa10ed 100644 --- a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserCalendarRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserCalendarRepository.cs @@ -46,7 +46,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants get { if (UserId != null || UserId != "") - return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!)); + return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), AccessToken); else return Guid.Empty; } diff --git a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserDutyTimeRepository.cs b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserDutyTimeRepository.cs index 00f7aa55..48bdd0da 100644 --- a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserDutyTimeRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserDutyTimeRepository.cs @@ -46,7 +46,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants get { if (UserId != null || UserId != "") - return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!)); + return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), AccessToken); else return Guid.Empty; } diff --git a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserTimeStampRepository.cs b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserTimeStampRepository.cs index a348e9c6..2eb6f6b3 100644 --- a/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserTimeStampRepository.cs +++ b/BMA.EHR.Application/Repositories/Leaves/TimeAttendants/UserTimeStampRepository.cs @@ -47,7 +47,7 @@ namespace BMA.EHR.Application.Repositories.Leaves.TimeAttendants get { if (UserId != null || UserId != "") - return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!)); + return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), AccessToken); else return Guid.Empty; } diff --git a/BMA.EHR.Application/Repositories/UserProfileRepository.cs b/BMA.EHR.Application/Repositories/UserProfileRepository.cs index 9e52dea5..d3b389e1 100644 --- a/BMA.EHR.Application/Repositories/UserProfileRepository.cs +++ b/BMA.EHR.Application/Repositories/UserProfileRepository.cs @@ -92,31 +92,43 @@ namespace BMA.EHR.Application.Repositories } } - public async Task UpdateDutyTimeAsync(Guid profileId, Guid roundId, DateTime effectiveDate) + public async Task UpdateDutyTimeAsync(Guid profileId, Guid roundId, DateTime effectiveDate, string? accessToken) { try { - var profile = await _dbContext.Set() - .AsQueryable() - .Include(x => x.Prefix) - .FirstOrDefaultAsync(x => x.Id == profileId); + var apiPath = $"{_configuration["API"]}/org/dotnet/update-dutytime"; - if (profile == null) + var body = new { - throw new Exception(GlobalMessages.DataNotFound); - } - else - { - var fullName = $"{profile.Prefix.Name}{profile.FirstName} {profile.LastName}"; - Console.WriteLine(fullName); + EffevtiveDate = effectiveDate, + RoundId = roundId, + ProfileId = profileId + }; - profile.DutyTimeId = roundId; - profile.DutyTimeEffectiveDate = effectiveDate; + var apiResult = await PostExternalAPIBooleanAsync(apiPath, accessToken ?? "", body); - await UpdateAsync(profile); + return apiResult; + //var profile = await _dbContext.Set() + // .AsQueryable() + // .Include(x => x.Prefix) + // .FirstOrDefaultAsync(x => x.Id == profileId); - return true; - } + //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 { @@ -124,16 +136,21 @@ namespace BMA.EHR.Application.Repositories } } - public async Task> GetProfileWithKeycloak() + public async Task> GetProfileWithKeycloak(string? accessToken) { try { - var data = await _dbContext.Set().AsQueryable() - .Where(x => x.ProfileType == "officer") - .Where(x => x.KeycloakId != null) - .ToListAsync(); + var apiPath = $"{_configuration["API"]}/org/dotnet/keycloak"; - return data; + var apiResult = await GetExternalAPIAsync(apiPath, accessToken ?? ""); + if (apiResult != null) + { + var raw = JsonConvert.DeserializeObject(apiResult); + if (raw != null) + return raw.Result; + } + + return null; } catch { @@ -193,28 +210,51 @@ namespace BMA.EHR.Application.Repositories } } - public async Task> SearchProfileEmployee(string? citizenId, string? firstName, string? lastName) + public async Task> SearchProfileEmployee(string? citizenId, string? firstName, string? lastName, string accessToken) { try { - var data = _dbContext.Set().AsQueryable() - .Where(x => x.ProfileType == "employee"); + var apiPath = $"{_configuration["API"]}/org/dotnet/search-employee"; + var body = new + { + citizenId = citizenId, + firstName = firstName, + lastName = lastName + }; + + var profiles = new List(); + + var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body); + if (apiResult != null) + { + var raw = JsonConvert.DeserializeObject(apiResult); + if (raw != null && raw.Result != null) + { + profiles.AddRange(raw.Result); + } + } + + return profiles; - if (citizenId != null) - data = data.Where(x => x.CitizenId!.Contains(citizenId)); - - if (firstName != null) - data = data.Where(x => x.FirstName!.Contains(firstName)); - - if (lastName != null) - data = data.Where(x => x.LastName!.Contains(lastName)); - - data = data.Include(x => x.Prefix); - //.Include(x => x.PosNoEmployee); + //var data = _dbContext.Set().AsQueryable() + // .Where(x => x.ProfileType == "employee"); - return await data.ToListAsync(); + //if (citizenId != null) + // data = data.Where(x => x.CitizenId!.Contains(citizenId)); + + //if (firstName != null) + // data = data.Where(x => x.FirstName!.Contains(firstName)); + + //if (lastName != null) + // data = data.Where(x => x.LastName!.Contains(lastName)); + + //data = data.Include(x => x.Prefix); + ////.Include(x => x.PosNoEmployee); + + + //return await data.ToListAsync(); } catch { @@ -222,17 +262,22 @@ namespace BMA.EHR.Application.Repositories } } - public string GetUserFullName(Guid keycloakId) + public string GetUserFullName(Guid keycloakId, string? accessToken) { try { - var data = _dbContext.Set().AsQueryable() - .Include(x => x.Prefix) - .Where(x => x.KeycloakId == keycloakId) - .Select(x => $"{x.Prefix!.Name}{x.FirstName} {x.LastName}") - .FirstOrDefault(); + var apiPath = $"{_configuration["API"]}/org/dotnet/keycloak"; + + var apiResult = GetExternalAPIAsync(apiPath, accessToken ?? ""); + if (apiResult.Result != null) + { + var raw = JsonConvert.DeserializeObject(apiResult.Result); + if (raw != null) + return raw.Result; + } + + return string.Empty; - return data ?? "-"; } catch { @@ -240,21 +285,34 @@ namespace BMA.EHR.Application.Repositories } } - public Guid GetUserOCId(Guid keycloakId) + public Guid GetUserOCId(Guid keycloakId, string? accessToken) { try { - var data = _dbContext.Set() - .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); + var apiPath = $"{_configuration["API"]}/org/dotnet/user-oc/{keycloakId}"; - return data.OrganizationPosition!.Organization!.Id; + var apiResult = GetExternalAPIAsync(apiPath, accessToken ?? ""); + if (apiResult.Result != null) + { + var raw = JsonConvert.DeserializeObject(apiResult.Result); + if (raw != null) + return raw.Result!.RootId; + } + + return Guid.Empty; + + //var data = _dbContext.Set() + // .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 { @@ -262,14 +320,26 @@ namespace BMA.EHR.Application.Repositories } } - public Guid? GetRootOcId(Guid ocId) + public Guid? GetRootOcId(Guid ocId, string? accessToken) { try { - var data = _dbContext.Set() - .FirstOrDefault(o => o.Id == ocId); + var apiPath = $"{_configuration["API"]}/org/dotnet/root-oc/{ocId}"; - return data == null ? Guid.Empty : data.OrganizationAgencyId; + var apiResult = GetExternalAPIAsync(apiPath, accessToken ?? ""); + if (apiResult.Result != null) + { + var raw = JsonConvert.DeserializeObject(apiResult.Result); + if (raw != null) + return raw.Result; + } + + return null; + + //var data = _dbContext.Set() + // .FirstOrDefault(o => o.Id == ocId); + + //return data == null ? Guid.Empty : data.OrganizationAgencyId; } diff --git a/BMA.EHR.Application/Responses/Profiles/GetListProfileByKeycloakIdResultDto.cs b/BMA.EHR.Application/Responses/Profiles/GetListProfileByKeycloakIdResultDto.cs new file mode 100644 index 00000000..d9c3bb00 --- /dev/null +++ b/BMA.EHR.Application/Responses/Profiles/GetListProfileByKeycloakIdResultDto.cs @@ -0,0 +1,11 @@ +namespace BMA.EHR.Application.Responses.Profiles +{ + public class GetListProfileByKeycloakIdResultDto + { + public string Message { get; set; } = string.Empty; + + public int Status { get; set; } = -1; + + public List Result { get; set; } = new(); + } +} diff --git a/BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdDto.cs b/BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdDto.cs index 951ce149..e0a397e0 100644 --- a/BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdDto.cs +++ b/BMA.EHR.Application/Responses/Profiles/GetProfileByKeycloakIdDto.cs @@ -29,6 +29,12 @@ namespace BMA.EHR.Application.Responses.Profiles public List Salaries { get; set; } = new(); + public Guid? Keycloak { get; set; } + + public string? PosNo { get; set; } + + public string? PosNoEmployee { get; set; } + } public class PosLevel diff --git a/BMA.EHR.Application/Responses/Profiles/GetRootOCIdResultDto.cs b/BMA.EHR.Application/Responses/Profiles/GetRootOCIdResultDto.cs new file mode 100644 index 00000000..b7eca45a --- /dev/null +++ b/BMA.EHR.Application/Responses/Profiles/GetRootOCIdResultDto.cs @@ -0,0 +1,11 @@ +namespace BMA.EHR.Application.Responses.Profiles +{ + public class GetRootOCIdResultDto + { + public string Message { get; set; } = string.Empty; + + public int Status { get; set; } = -1; + + public Guid Result { get; set; } + } +} diff --git a/BMA.EHR.Application/Responses/Profiles/GetUserFullNameResultDto.cs b/BMA.EHR.Application/Responses/Profiles/GetUserFullNameResultDto.cs new file mode 100644 index 00000000..445aa1fd --- /dev/null +++ b/BMA.EHR.Application/Responses/Profiles/GetUserFullNameResultDto.cs @@ -0,0 +1,11 @@ +namespace BMA.EHR.Application.Responses.Profiles +{ + public class GetUserFullNameResultDto + { + public string Message { get; set; } = string.Empty; + + public int Status { get; set; } = -1; + + public string Result { get; set; } = string.Empty; + } +} diff --git a/BMA.EHR.Application/Responses/Profiles/GetUserOCIdDto.cs b/BMA.EHR.Application/Responses/Profiles/GetUserOCIdDto.cs new file mode 100644 index 00000000..db187a17 --- /dev/null +++ b/BMA.EHR.Application/Responses/Profiles/GetUserOCIdDto.cs @@ -0,0 +1,29 @@ +namespace BMA.EHR.Application.Responses.Profiles +{ + public class GetUserOCIdDto + { + public Guid ProfileId { get; set; } + + public string Prefix { get; set; } = string.Empty; + + public string Rank { get; set; } = string.Empty; + + public string Avatar { get; set; } = string.Empty; + + public string FirstName { get; set; } = string.Empty; + + public string LastName { get; set; } = string.Empty; + + public string CitizenId { get; set; } = string.Empty; + + public DateTime BirthDate { get; set; } = DateTime.MinValue; + + public string Position { get; set; } = string.Empty; + + public Guid RootId { get; set; } + + public string Root { get; set; } = string.Empty; + + public string RootShortName { get; set; } = string.Empty; + } +} diff --git a/BMA.EHR.Application/Responses/Profiles/GetUserOCIdResultDto.cs b/BMA.EHR.Application/Responses/Profiles/GetUserOCIdResultDto.cs new file mode 100644 index 00000000..5f96f48a --- /dev/null +++ b/BMA.EHR.Application/Responses/Profiles/GetUserOCIdResultDto.cs @@ -0,0 +1,11 @@ +namespace BMA.EHR.Application.Responses.Profiles +{ + public class GetUserOCIdResultDto + { + public string Message { get; set; } = string.Empty; + + public int Status { get; set; } = -1; + + public GetUserOCIdDto? Result { get; set; } + } +} diff --git a/BMA.EHR.Application/Responses/Profiles/SearchProfileDto.cs b/BMA.EHR.Application/Responses/Profiles/SearchProfileDto.cs index b557f7d9..6f4cb647 100644 --- a/BMA.EHR.Application/Responses/Profiles/SearchProfileDto.cs +++ b/BMA.EHR.Application/Responses/Profiles/SearchProfileDto.cs @@ -8,5 +8,13 @@ public string? FirstName { get; set; } public string? LastName { get; set; } public string? CitizenId { get; set; } + + public Guid? Keycloak { get; set; } + + public string? PosNoEmployee { get; set; } + + public string? Oc { get; set; } + + public string? PosNo { get; set; } } } diff --git a/BMA.EHR.Leave.Service/Controllers/LeaveController.cs b/BMA.EHR.Leave.Service/Controllers/LeaveController.cs index 9f4d067d..543b1fbf 100644 --- a/BMA.EHR.Leave.Service/Controllers/LeaveController.cs +++ b/BMA.EHR.Leave.Service/Controllers/LeaveController.cs @@ -102,7 +102,7 @@ namespace BMA.EHR.Leave.Service.Controllers get { if (UserId != null || UserId != "") - return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!)); + return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), AccessToken); else return Guid.Empty; } @@ -687,7 +687,7 @@ namespace BMA.EHR.Leave.Service.Controllers .Select(d => new CheckInHistoryForAdminDto { Id = d.Id, - FullName = _userProfileRepository.GetUserFullName(d.KeycloakUserId), + FullName = _userProfileRepository.GetUserFullName(d.KeycloakUserId, AccessToken), CheckInDate = d.CheckIn.Date, CheckInTime = d.CheckIn.ToString("HH:mm:ss"), @@ -773,7 +773,7 @@ namespace BMA.EHR.Leave.Service.Controllers var result = new CheckInDetailForAdminDto { Id = d.Id, - FullName = _userProfileRepository.GetUserFullName(d.KeycloakUserId), + FullName = _userProfileRepository.GetUserFullName(d.KeycloakUserId, AccessToken), CheckInDate = d.CheckIn.Date, CheckInTime = d.CheckIn.ToString("HH:mm"), @@ -873,7 +873,7 @@ namespace BMA.EHR.Leave.Service.Controllers .Select(d => new CheckInProcessHistoryForAdminDto { Id = d.Id, - FullName = _userProfileRepository.GetUserFullName(d.KeycloakUserId), + FullName = _userProfileRepository.GetUserFullName(d.KeycloakUserId, AccessToken), CheckInDate = d.CheckIn.Date, CheckInTime = d.CheckIn.ToString("HH:mm"), @@ -1387,7 +1387,7 @@ namespace BMA.EHR.Leave.Service.Controllers var result = new CheckInDetailForAdminDto { Id = d.Id, - FullName = _userProfileRepository.GetUserFullName(d.KeycloakUserId), + FullName = _userProfileRepository.GetUserFullName(d.KeycloakUserId, AccessToken), CheckInDate = d.CheckIn.Date, CheckInTime = d.CheckIn.ToString("HH:mm"), diff --git a/BMA.EHR.Leave.Service/Controllers/LeaveReportController.cs b/BMA.EHR.Leave.Service/Controllers/LeaveReportController.cs index 11391d62..5d80fc38 100644 --- a/BMA.EHR.Leave.Service/Controllers/LeaveReportController.cs +++ b/BMA.EHR.Leave.Service/Controllers/LeaveReportController.cs @@ -87,7 +87,7 @@ namespace BMA.EHR.Leave.Service.Controllers get { if (UserId != null || UserId != "") - return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!)); + return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), AccessToken); else return Guid.Empty; } @@ -113,7 +113,7 @@ namespace BMA.EHR.Leave.Service.Controllers await _leaveRequestRepository.GetLastLeaveRequestByTypeForUserAsync(data.KeycloakUserId, data.Type.Id); - var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty); + var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty, AccessToken); var approver = string.Empty; if (rootOc != null) { @@ -164,7 +164,7 @@ namespace BMA.EHR.Leave.Service.Controllers var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}"; - var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty); + var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty, AccessToken); var approver = string.Empty; if (rootOc != null) { @@ -208,7 +208,7 @@ namespace BMA.EHR.Leave.Service.Controllers var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}"; - var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty); + var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty, AccessToken); var approver = string.Empty; if (rootOc != null) { @@ -259,7 +259,7 @@ namespace BMA.EHR.Leave.Service.Controllers var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}"; - var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty); + var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty, AccessToken); var approver = string.Empty; if (rootOc != null) { @@ -342,7 +342,7 @@ namespace BMA.EHR.Leave.Service.Controllers var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}"; - var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty); + var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty, AccessToken); var approver = string.Empty; if (rootOc != null) { @@ -390,7 +390,7 @@ namespace BMA.EHR.Leave.Service.Controllers var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}"; - var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty); + var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty, AccessToken); var approver = string.Empty; if (rootOc != null) { @@ -445,7 +445,7 @@ namespace BMA.EHR.Leave.Service.Controllers var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}"; - var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty); + var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty, AccessToken); var approver = string.Empty; if (rootOc != null) { @@ -487,7 +487,7 @@ namespace BMA.EHR.Leave.Service.Controllers var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}"; - var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty); + var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty, AccessToken); var approver = string.Empty; if (rootOc != null) { @@ -542,7 +542,7 @@ namespace BMA.EHR.Leave.Service.Controllers var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}"; - var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty); + var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty, AccessToken); var approver = string.Empty; if (rootOc != null) { @@ -692,7 +692,7 @@ namespace BMA.EHR.Leave.Service.Controllers var fullName = $"{profile!.Prefix}{profile!.FirstName} {profile!.LastName}"; - var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty); + var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty, AccessToken); var approver = string.Empty; if (rootOc != null) { @@ -749,7 +749,7 @@ namespace BMA.EHR.Leave.Service.Controllers try { //var profile = await _userProfileRepository.SearchProfile(null, null, null); - var profile = await _userProfileRepository.GetProfileWithKeycloak(); + var profile = await _userProfileRepository.GetProfileWithKeycloak(AccessToken); var count = 1; var employees = new List(); @@ -761,7 +761,7 @@ namespace BMA.EHR.Leave.Service.Controllers var sickType = await _leaveTypeRepository.GetLeaveTypeByCodeAsync("LV-001"); if (sickType == null) return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); - var sickDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.KeycloakId ?? Guid.Empty, + var sickDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.Keycloak ?? Guid.Empty, sickType.Id, req.StartDate, req.EndDate); @@ -769,7 +769,7 @@ namespace BMA.EHR.Leave.Service.Controllers var personalType = await _leaveTypeRepository.GetLeaveTypeByCodeAsync("LV-002"); if (personalType == null) return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); - var personalDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.KeycloakId ?? Guid.Empty, + var personalDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.Keycloak ?? Guid.Empty, personalType.Id, req.StartDate, req.EndDate); @@ -777,7 +777,7 @@ namespace BMA.EHR.Leave.Service.Controllers var maternityType = await _leaveTypeRepository.GetLeaveTypeByCodeAsync("LV-003"); if (maternityType == null) return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); - var maternityDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.KeycloakId ?? Guid.Empty, + var maternityDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.Keycloak ?? Guid.Empty, maternityType.Id, req.StartDate, req.EndDate); @@ -785,7 +785,7 @@ namespace BMA.EHR.Leave.Service.Controllers var wifeType = await _leaveTypeRepository.GetLeaveTypeByCodeAsync("LV-004"); if (wifeType == null) return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); - var wifeDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.KeycloakId ?? Guid.Empty, + var wifeDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.Keycloak ?? Guid.Empty, wifeType.Id, req.StartDate, req.EndDate); @@ -793,7 +793,7 @@ namespace BMA.EHR.Leave.Service.Controllers var restType = await _leaveTypeRepository.GetLeaveTypeByCodeAsync("LV-005"); if (restType == null) return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); - var restDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.KeycloakId ?? Guid.Empty, + var restDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.Keycloak ?? Guid.Empty, restType.Id, req.StartDate, req.EndDate); @@ -801,7 +801,7 @@ namespace BMA.EHR.Leave.Service.Controllers var ordainType = await _leaveTypeRepository.GetLeaveTypeByCodeAsync("LV-006"); if (ordainType == null) return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); - var ordainDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.KeycloakId ?? Guid.Empty, + var ordainDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.Keycloak ?? Guid.Empty, ordainType.Id, req.StartDate, req.EndDate); @@ -809,7 +809,7 @@ namespace BMA.EHR.Leave.Service.Controllers var absentType = await _leaveTypeRepository.GetLeaveTypeByCodeAsync("LV-007"); if (absentType == null) return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); - var absentDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.KeycloakId ?? Guid.Empty, + var absentDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.Keycloak ?? Guid.Empty, absentType.Id, req.StartDate, req.EndDate); @@ -817,7 +817,7 @@ namespace BMA.EHR.Leave.Service.Controllers var studyType = await _leaveTypeRepository.GetLeaveTypeByCodeAsync("LV-008"); if (studyType == null) return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); - var studyDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.KeycloakId ?? Guid.Empty, + var studyDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.Keycloak ?? Guid.Empty, studyType.Id, req.StartDate, req.EndDate); @@ -825,7 +825,7 @@ namespace BMA.EHR.Leave.Service.Controllers var agencyType = await _leaveTypeRepository.GetLeaveTypeByCodeAsync("LV-009"); if (agencyType == null) return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); - var agencyDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.KeycloakId ?? Guid.Empty, + var agencyDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.Keycloak ?? Guid.Empty, agencyType.Id, req.StartDate, req.EndDate); @@ -833,7 +833,7 @@ namespace BMA.EHR.Leave.Service.Controllers var coupleType = await _leaveTypeRepository.GetLeaveTypeByCodeAsync("LV-010"); if (coupleType == null) return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); - var coupleDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.KeycloakId ?? Guid.Empty, + var coupleDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.Keycloak ?? Guid.Empty, coupleType.Id, req.StartDate, req.EndDate); @@ -841,12 +841,12 @@ namespace BMA.EHR.Leave.Service.Controllers var therapyType = await _leaveTypeRepository.GetLeaveTypeByCodeAsync("LV-011"); if (therapyType == null) return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); - var therapyDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.KeycloakId ?? Guid.Empty, + var therapyDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.Keycloak ?? Guid.Empty, therapyType.Id, req.StartDate, req.EndDate); - var timeStamps = await _processUserTimeStampRepository.GetTimeStampHistoryByRangeForUserAsync(p.KeycloakId ?? Guid.Empty, + var timeStamps = await _processUserTimeStampRepository.GetTimeStampHistoryByRangeForUserAsync(p.Keycloak ?? Guid.Empty, req.StartDate, req.EndDate); @@ -890,10 +890,10 @@ namespace BMA.EHR.Leave.Service.Controllers var emp = new { no = count, - fullName = _userProfileRepository.GetUserFullName(p.KeycloakId ?? Guid.Empty), - position = p.Position == null ? "" : p.Position.Name, - positionLevel = p.PositionLevel == null ? "" : p.PositionLevel.Name, - posNo = p.PosNo == null ? "" : p.PosNo.Name, + fullName = _userProfileRepository.GetUserFullName(p.Keycloak ?? Guid.Empty, AccessToken), + position = p.Position == null ? "" : p.Position, + positionLevel = p.PosLevel == null ? "" : p.PosLevel.PosLevelName, + posNo = p.PosNo ?? "", reason = "", sickDayCount = sickDayCount, @@ -966,7 +966,7 @@ namespace BMA.EHR.Leave.Service.Controllers { try { - var profile = await _userProfileRepository.SearchProfileEmployee(null, null, null); + var profile = await _userProfileRepository.SearchProfileEmployee(null, null, null, AccessToken ?? ""); var count = 1; var employees = new List(); @@ -977,11 +977,12 @@ namespace BMA.EHR.Leave.Service.Controllers var sickType = await _leaveTypeRepository.GetLeaveTypeByCodeAsync("LV-001"); if (sickType == null) return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); - var sickDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.KeycloakId ?? Guid.Empty, + var sickDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.Keycloak ?? Guid.Empty, sickType.Id, req.StartDate, req.EndDate); - var sickCount = await _leaveRequestRepository.GetCountApproveLeaveByTypeAndRangeForUser(p.KeycloakId ?? Guid.Empty, + + var sickCount = await _leaveRequestRepository.GetCountApproveLeaveByTypeAndRangeForUser(p.Keycloak ?? Guid.Empty, sickType.Id, req.StartDate, req.EndDate); @@ -989,12 +990,12 @@ namespace BMA.EHR.Leave.Service.Controllers var personalType = await _leaveTypeRepository.GetLeaveTypeByCodeAsync("LV-002"); if (personalType == null) return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); - var personalDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.KeycloakId ?? Guid.Empty, + var personalDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.Keycloak ?? Guid.Empty, personalType.Id, req.StartDate, req.EndDate); - var personalCount = await _leaveRequestRepository.GetCountApproveLeaveByTypeAndRangeForUser(p.KeycloakId ?? Guid.Empty, + var personalCount = await _leaveRequestRepository.GetCountApproveLeaveByTypeAndRangeForUser(p.Keycloak ?? Guid.Empty, personalType.Id, req.StartDate, req.EndDate); @@ -1002,7 +1003,7 @@ namespace BMA.EHR.Leave.Service.Controllers var maternityType = await _leaveTypeRepository.GetLeaveTypeByCodeAsync("LV-003"); if (maternityType == null) return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); - var maternityDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.KeycloakId ?? Guid.Empty, + var maternityDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.Keycloak ?? Guid.Empty, maternityType.Id, req.StartDate, req.EndDate); @@ -1010,7 +1011,7 @@ namespace BMA.EHR.Leave.Service.Controllers var wifeType = await _leaveTypeRepository.GetLeaveTypeByCodeAsync("LV-004"); if (wifeType == null) return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); - var wifeDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.KeycloakId ?? Guid.Empty, + var wifeDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.Keycloak ?? Guid.Empty, wifeType.Id, req.StartDate, req.EndDate); @@ -1018,7 +1019,7 @@ namespace BMA.EHR.Leave.Service.Controllers var restType = await _leaveTypeRepository.GetLeaveTypeByCodeAsync("LV-005"); if (restType == null) return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); - var restDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.KeycloakId ?? Guid.Empty, + var restDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.Keycloak ?? Guid.Empty, restType.Id, req.StartDate, req.EndDate); @@ -1026,12 +1027,12 @@ namespace BMA.EHR.Leave.Service.Controllers var ordainType = await _leaveTypeRepository.GetLeaveTypeByCodeAsync("LV-006"); if (ordainType == null) return Error(GlobalMessages.DataNotFound, StatusCodes.Status404NotFound); - var ordainDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.KeycloakId ?? Guid.Empty, + var ordainDayCount = await _leaveRequestRepository.GetSumApproveLeaveByTypeAndRangeForUser(p.Keycloak ?? Guid.Empty, ordainType.Id, req.StartDate, req.EndDate); - var timeStamps = await _processUserTimeStampRepository.GetTimeStampHistoryByRangeForUserAsync(p.KeycloakId ?? Guid.Empty, + var timeStamps = await _processUserTimeStampRepository.GetTimeStampHistoryByRangeForUserAsync(p.Keycloak ?? Guid.Empty, req.StartDate, req.EndDate); @@ -1074,7 +1075,7 @@ namespace BMA.EHR.Leave.Service.Controllers var emp = new { no = count, - fullName = _userProfileRepository.GetUserFullName(p.KeycloakId ?? Guid.Empty), + fullName = _userProfileRepository.GetUserFullName(p.Keycloak ?? Guid.Empty, AccessToken), posNo = p.PosNoEmployee ?? "", reason = "", @@ -1137,7 +1138,7 @@ namespace BMA.EHR.Leave.Service.Controllers try { //var profile = await _userProfileRepository.SearchProfile(null, null, null); - var profile = await _userProfileRepository.GetProfileWithKeycloak(); + var profile = await _userProfileRepository.GetProfileWithKeycloak(AccessToken); var date = req.StartDate.Date; var holidays = await _holidayRepository.GetHolidayAsync(req.StartDate.Date, req.EndDate.Date); @@ -1168,11 +1169,11 @@ namespace BMA.EHR.Leave.Service.Controllers foreach (var p in profile) { - var keycloakUserId = p.KeycloakId ?? Guid.Empty; + var keycloakUserId = p.Keycloak ?? Guid.Empty; var timeStamps = await _processUserTimeStampRepository.GetTimestampByDateAsync(keycloakUserId, dd); - var fullName = _userProfileRepository.GetUserFullName(keycloakUserId); + var fullName = _userProfileRepository.GetUserFullName(keycloakUserId, AccessToken); var defaultRound = await _dutyTimeRepository.GetDefaultAsync(); diff --git a/BMA.EHR.Leave.Service/Controllers/LeaveRequestController.cs b/BMA.EHR.Leave.Service/Controllers/LeaveRequestController.cs index 95579c11..85f18b44 100644 --- a/BMA.EHR.Leave.Service/Controllers/LeaveRequestController.cs +++ b/BMA.EHR.Leave.Service/Controllers/LeaveRequestController.cs @@ -90,7 +90,7 @@ namespace BMA.EHR.Leave.Service.Controllers get { if (UserId != null || UserId != "") - return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!)); + return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), AccessToken); else return Guid.Empty; } @@ -298,7 +298,7 @@ namespace BMA.EHR.Leave.Service.Controllers } // add dear and oc_data - var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty); + var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty, AccessToken); var approver = string.Empty; if (rootOc != null) { @@ -524,7 +524,7 @@ namespace BMA.EHR.Leave.Service.Controllers } // add dear and oc_data - var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty); + var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty, AccessToken); var approver = string.Empty; if (rootOc != null) { @@ -613,7 +613,7 @@ namespace BMA.EHR.Leave.Service.Controllers var lastSalary = profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault(); - var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty); + var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty, AccessToken); var approver = string.Empty; if (rootOc != null) { @@ -1423,7 +1423,7 @@ namespace BMA.EHR.Leave.Service.Controllers await _leaveRequestRepository.GetLastLeaveRequestByTypeForUserAsync(rawData.KeycloakUserId, rawData.Type.Id); - var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty); + var rootOc = _userProfileRepository.GetRootOcId(profile.OcId ?? Guid.Empty, AccessToken); var approver = string.Empty; if (rootOc != null) { diff --git a/BMA.EHR.Leave.Service/Controllers/LeaveTypeController.cs b/BMA.EHR.Leave.Service/Controllers/LeaveTypeController.cs index 7c3d84ad..23fd835c 100644 --- a/BMA.EHR.Leave.Service/Controllers/LeaveTypeController.cs +++ b/BMA.EHR.Leave.Service/Controllers/LeaveTypeController.cs @@ -55,12 +55,14 @@ namespace BMA.EHR.Leave.Service.Controllers 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!)); + return _userProfileRepository.GetUserOCId(Guid.Parse(UserId!), AccessToken); else return Guid.Empty; }