noti วินัย

This commit is contained in:
kittapath 2025-02-19 17:56:02 +07:00
parent 9e513d3f1a
commit ae990c0c5f
21 changed files with 244 additions and 1508 deletions

View file

@ -14,6 +14,7 @@ using System.Security.Claims;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.Net.Http.Headers;
namespace BMA.EHR.DisciplineInvestigate.Service.Controllers
{
@ -28,25 +29,31 @@ namespace BMA.EHR.DisciplineInvestigate.Service.Controllers
private readonly DisciplineDbContext _context;
private readonly MinIODisciplineService _documentService;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly NotificationRepository _repositoryNoti;
private readonly PermissionRepository _permission;
private readonly IConfiguration _configuration;
public DisciplineInvestigateController(DisciplineDbContext context,
MinIODisciplineService documentService,
NotificationRepository repositoryNoti,
IHttpContextAccessor httpContextAccessor,
IConfiguration configuration,
PermissionRepository permission)
{
// _repository = repository;
_context = context;
_documentService = documentService;
_httpContextAccessor = httpContextAccessor;
_repositoryNoti = repositoryNoti;
_permission = permission;
_configuration = configuration;
}
#region " Properties "
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
private string? token => _httpContextAccessor.HttpContext.Request.Headers["Authorization"];
#endregion
@ -786,20 +793,33 @@ namespace BMA.EHR.DisciplineInvestigate.Service.Controllers
LastUpdatedAt = DateTime.Now,
});
}
// foreach (var item in data.DisciplineInvestigate_Directors)
// {
// disciplineDisciplinary.DisciplineDisciplinary_DirectorInvestigates.Add(
// new DisciplineDisciplinary_DirectorInvestigate
// {
// DisciplineDirector = item.DisciplineDirector,
// CreatedFullName = FullName ?? "System Administrator",
// CreatedUserId = UserId ?? "",
// CreatedAt = DateTime.Now,
// LastUpdateFullName = FullName ?? "System Administrator",
// LastUpdateUserId = UserId ?? "",
// LastUpdatedAt = DateTime.Now,
// });
// }
var baseAPIOrg = _configuration["API"];
var apiUrlOrg = $"{baseAPIOrg}/org/workflow/find/director";
var refId = new List<Guid>();
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
client.DefaultRequestHeaders.Add("api_key", _configuration["API_KEY"]);
var _res = await client.PostAsJsonAsync(apiUrlOrg, new
{
refId = persons.Select(x => x.PersonId),
});
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<DirectorRequest>(_result);
if (_res.IsSuccessStatusCode)
{
refId = org.result.Select(x => Guid.Parse(x.id)).ToList();
}
}
await _repositoryNoti.PushNotificationsAsync(
refId.ToArray(),
$"มีคำขอสอบสวนเรื่อง {data.Title}",
$"มีคำขอสอบสวนเรื่อง {data.Title}",
"",
"",
true,
true
);
data.DisciplineDisciplinarys.Add(disciplineDisciplinary);
await _context.SaveChangesAsync();