diff --git a/BMA.EHR.Application/Repositories/UserProfileRepository.cs b/BMA.EHR.Application/Repositories/UserProfileRepository.cs index 490adce9..990ec400 100644 --- a/BMA.EHR.Application/Repositories/UserProfileRepository.cs +++ b/BMA.EHR.Application/Repositories/UserProfileRepository.cs @@ -9,6 +9,7 @@ using BMA.EHR.Domain.Models.Organizations; using Microsoft.AspNetCore.Http; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; +using Nest; using Newtonsoft.Json; namespace BMA.EHR.Application.Repositories @@ -532,7 +533,7 @@ namespace BMA.EHR.Application.Repositories nodeId = nodeId, role = role, revisionId = revisionId, - reqNode = reqNode, + reqNode = reqNode, reqNodeId = reqNodeId }; @@ -686,7 +687,7 @@ namespace BMA.EHR.Application.Repositories } } - public async Task> GetEmployeeByAdminRole(string? accessToken, int? node, string? nodeId, string role, string? revisionId, int? reqNode, string? reqNodeId ) + public async Task> GetEmployeeByAdminRole(string? accessToken, int? node, string? nodeId, string role, string? revisionId, int? reqNode, string? reqNodeId) { try { @@ -720,7 +721,7 @@ namespace BMA.EHR.Application.Repositories } } - public async Task> SearchProfile(string? citizenId, string? firstName, string? lastName, string accessToken, string? role, string? nodeId, int? node) + public async Task SearchProfile(string? citizenId, string? firstName, string? lastName, string accessToken, int page, int pageSize, string? role, string? nodeId, int? node) { try { @@ -734,41 +735,25 @@ namespace BMA.EHR.Application.Repositories role = role, nodeId = nodeId, node = node, + page = page, + pageSize = pageSize, }; - var profiles = new List(); + var profiles = new List(); + var total = 0; var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey); if (apiResult != null) { - var raw = JsonConvert.DeserializeObject(apiResult); + var raw = JsonConvert.DeserializeObject(apiResult); if (raw != null && raw.Result != null) { - profiles.AddRange(raw.Result); + profiles.AddRange(raw.Result.data); + total = raw.Result.total; } } - return profiles; - - //var data = _dbContext.Set().AsQueryable() - // .Where(x => x.ProfileType == "officer"); - - - //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.Position) - // .Include(x => x.PositionLevel) - // .Include(x => x.PosNo); - - //return await data.ToListAsync(); + return new { data = profiles, total = total }; } catch { @@ -776,7 +761,7 @@ namespace BMA.EHR.Application.Repositories } } - public async Task> SearchProfileEmployee(string? citizenId, string? firstName, string? lastName, string accessToken, string? role, string? nodeId, int? node) + public async Task SearchProfileEmployee(string? citizenId, string? firstName, string? lastName, string accessToken, int page, int pageSize, string? role, string? nodeId, int? node) { try { @@ -790,41 +775,25 @@ namespace BMA.EHR.Application.Repositories role = role, nodeId = nodeId, node = node, + page = page, + pageSize = pageSize, }; - var profiles = new List(); + var profiles = new List(); + var total = 0; var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body, apiKey); if (apiResult != null) { - var raw = JsonConvert.DeserializeObject(apiResult); + var raw = JsonConvert.DeserializeObject(apiResult); if (raw != null && raw.Result != null) { - profiles.AddRange(raw.Result); + profiles.AddRange(raw.Result.data); + total = raw.Result.total; } } - return profiles; - - - //var data = _dbContext.Set().AsQueryable() - // .Where(x => x.ProfileType == "employee"); - - - //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(); + return new { data = profiles, total = total }; } catch { diff --git a/BMA.EHR.Leave/Controllers/LeaveController.cs b/BMA.EHR.Leave/Controllers/LeaveController.cs index 5974553a..8bde7abd 100644 --- a/BMA.EHR.Leave/Controllers/LeaveController.cs +++ b/BMA.EHR.Leave/Controllers/LeaveController.cs @@ -1718,17 +1718,14 @@ namespace BMA.EHR.Leave.Service.Controllers { nodeId = profileAdmin?.RootDnaId; } - var profile = await _userProfileRepository.SearchProfile(req.CitizenId, req.FirstName, req.LastName, AccessToken ?? "", role, nodeId, profileAdmin?.Node); - - var pagedProfile = profile.Skip((req.Page - 1) * req.PageSize).Take(req.PageSize).ToList(); + var profile = await _userProfileRepository.SearchProfile(req.CitizenId, req.FirstName, req.LastName, AccessToken ?? "", req.Page, req.PageSize, role, nodeId, profileAdmin?.Node); var getDefaultRound = await _dutyTimeRepository.GetDefaultAsync(); var resultSet = new List(); - foreach (var p in pagedProfile) + foreach (var p in profile.data) { - var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(p.Id); var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty; var userRound = await _dutyTimeRepository.GetByIdAsync(roundId); @@ -1747,7 +1744,7 @@ namespace BMA.EHR.Leave.Service.Controllers resultSet.Add(res); } - return Success(new { data = resultSet, total = profile.Count }); + return Success(new { data = resultSet, total = profile.total }); } /// @@ -1907,17 +1904,14 @@ namespace BMA.EHR.Leave.Service.Controllers { nodeId = profileAdmin?.RootDnaId; } - var profile = await _userProfileRepository.SearchProfileEmployee(req.CitizenId, req.FirstName, req.LastName, AccessToken ?? "", role, nodeId, profileAdmin?.Node); - - var pagedProfile = profile.Skip((req.Page - 1) * req.PageSize).Take(req.PageSize).ToList(); + var profile = await _userProfileRepository.SearchProfileEmployee(req.CitizenId, req.FirstName, req.LastName, AccessToken ?? "", req.Page, req.PageSize, role, nodeId, profileAdmin?.Node); var getDefaultRound = await _dutyTimeRepository.GetDefaultAsync(); var resultSet = new List(); - foreach (var p in pagedProfile) + foreach (var p in profile.data) { - var effectiveDate = await _userDutyTimeRepository.GetLastEffectRound(p.Id); var roundId = effectiveDate != null ? effectiveDate.DutyTimeId : Guid.Empty; var userRound = await _dutyTimeRepository.GetByIdAsync(roundId); @@ -1936,7 +1930,7 @@ namespace BMA.EHR.Leave.Service.Controllers resultSet.Add(res); } - return Success(new { data = resultSet, total = profile.Count }); + return Success(new { data = resultSet, total = profile.total }); } ///