Merge branch 'develop' of github.com:Frappet/BMA-EHR-BackEnd into develop
This commit is contained in:
commit
94980d9157
5 changed files with 134 additions and 23 deletions
|
|
@ -4,7 +4,11 @@ using BMA.EHR.Domain.Models.Base;
|
|||
using BMA.EHR.Domain.Models.HR;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
|
||||
namespace BMA.EHR.Application.Repositories
|
||||
{
|
||||
|
|
@ -43,6 +47,60 @@ namespace BMA.EHR.Application.Repositories
|
|||
|
||||
#region " Methods "
|
||||
|
||||
#region " For Call External API "
|
||||
|
||||
protected async Task<string> GetExternalAPIAsync(string apiPath, string accessToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken.Replace("Bearer ", ""));
|
||||
var _res = await client.GetAsync(apiPath);
|
||||
if (_res.IsSuccessStatusCode)
|
||||
{
|
||||
var _result = await _res.Content.ReadAsStringAsync();
|
||||
|
||||
return _result;
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
protected async Task<string> PostExternalAPIAsync(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);
|
||||
if (_res.IsSuccessStatusCode)
|
||||
{
|
||||
var _result = await _res.Content.ReadAsStringAsync();
|
||||
|
||||
return _result;
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public async Task<Guid> GetProfileOrganizationAsync(string citizenId)
|
||||
{
|
||||
try
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
using System.Security.Cryptography.X509Certificates;
|
||||
using BMA.EHR.Application.Common.Interfaces;
|
||||
using BMA.EHR.Application.Common.Interfaces;
|
||||
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 BMA.EHR.Domain.Shared;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace BMA.EHR.Application.Repositories
|
||||
{
|
||||
|
|
@ -15,15 +18,19 @@ namespace BMA.EHR.Application.Repositories
|
|||
|
||||
private readonly IApplicationDBContext _dbContext;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Costructor and Destructor "
|
||||
|
||||
public UserProfileRepository(IApplicationDBContext dbContext, IHttpContextAccessor httpContextAccessor) : base(dbContext, httpContextAccessor)
|
||||
public UserProfileRepository(IApplicationDBContext dbContext,
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
IConfiguration configuration) : base(dbContext, httpContextAccessor)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
@ -122,29 +129,51 @@ namespace BMA.EHR.Application.Repositories
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<List<Profile>> SearchProfile(string? citizenId, string? firstName, string? lastName)
|
||||
public async Task<List<SearchProfileDto>> SearchProfile(string? citizenId, string? firstName, string? lastName, string accessToken)
|
||||
{
|
||||
try
|
||||
{
|
||||
var data = _dbContext.Set<Profile>().AsQueryable()
|
||||
.Where(x => x.ProfileType == "officer");
|
||||
var apiPath = $"{_configuration["API"]}/org/dotnet/search";
|
||||
var body = new
|
||||
{
|
||||
citizenId = citizenId,
|
||||
firstName = firstName,
|
||||
lastName = lastName
|
||||
};
|
||||
|
||||
var profiles = new List<SearchProfileDto>();
|
||||
|
||||
var apiResult = await PostExternalAPIAsync(apiPath, accessToken, body);
|
||||
if (apiResult != null)
|
||||
{
|
||||
var raw = JsonConvert.DeserializeObject<SearchProfileResultDto>(apiResult);
|
||||
if (raw != null && raw.Result != null)
|
||||
{
|
||||
profiles.AddRange(raw.Result);
|
||||
}
|
||||
}
|
||||
|
||||
return profiles;
|
||||
|
||||
//var data = _dbContext.Set<Profile>().AsQueryable()
|
||||
// .Where(x => x.ProfileType == "officer");
|
||||
|
||||
|
||||
if (citizenId != null)
|
||||
data = data.Where(x => x.CitizenId!.Contains(citizenId));
|
||||
//if (citizenId != null)
|
||||
// data = data.Where(x => x.CitizenId!.Contains(citizenId));
|
||||
|
||||
if (firstName != null)
|
||||
data = data.Where(x => x.FirstName!.Contains(firstName));
|
||||
//if (firstName != null)
|
||||
// data = data.Where(x => x.FirstName!.Contains(firstName));
|
||||
|
||||
if (lastName != null)
|
||||
data = data.Where(x => x.LastName!.Contains(lastName));
|
||||
//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);
|
||||
//data = data.Include(x => x.Prefix)
|
||||
// .Include(x => x.Position)
|
||||
// .Include(x => x.PositionLevel)
|
||||
// .Include(x => x.PosNo);
|
||||
|
||||
return await data.ToListAsync();
|
||||
//return await data.ToListAsync();
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue