107 lines
4.1 KiB
C#
107 lines
4.1 KiB
C#
using System.Security.Claims;
|
|
using BMA.EHR.Application.Repositories;
|
|
using BMA.EHR.Application.Repositories.MessageQueue;
|
|
using BMA.EHR.Application.Requests;
|
|
using BMA.EHR.Application.Responses.Insignias;
|
|
using BMA.EHR.Domain.Common;
|
|
using BMA.EHR.Domain.Models.Insignias;
|
|
using BMA.EHR.Domain.Shared;
|
|
using BMA.EHR.Infrastructure.Persistence;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Swashbuckle.AspNetCore.Annotations;
|
|
|
|
namespace BMA.EHR.Insignia.Service.Controllers
|
|
{
|
|
[Route("api/v{version:apiVersion}/insignia/receive")]
|
|
[ApiVersion("1.0")]
|
|
[ApiController]
|
|
[Produces("application/json")]
|
|
[Authorize]
|
|
[SwaggerTag("เครื่องราช")]
|
|
public class InsigniaReceiveController : BaseController
|
|
{
|
|
private readonly ApplicationDBContext _context;
|
|
private readonly MinIOService _documentService;
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
private readonly InsigniaPeriodsRepository _repository;
|
|
private readonly NotificationRepository _repositoryNoti;
|
|
|
|
private readonly UserProfileRepository _userProfileRepository;
|
|
|
|
public InsigniaReceiveController(ApplicationDBContext context,
|
|
MinIOService documentService,
|
|
InsigniaPeriodsRepository repository,
|
|
NotificationRepository repositoryNoti,
|
|
IHttpContextAccessor httpContextAccessor,
|
|
UserProfileRepository userProfileRepository)
|
|
{
|
|
_context = context;
|
|
_documentService = documentService;
|
|
_repository = repository;
|
|
_repositoryNoti = repositoryNoti;
|
|
_httpContextAccessor = httpContextAccessor;
|
|
_userProfileRepository = userProfileRepository;
|
|
}
|
|
|
|
private string? AccessToken => _httpContextAccessor?.HttpContext?.Request.Headers["Authorization"];
|
|
|
|
[HttpGet("{type}/{ocId:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> GetInsigniaList(string type, Guid id, Guid ocId)
|
|
{
|
|
var result = _repository.GetInsigniaRequest(id, ocId);
|
|
|
|
if (result == null)
|
|
{
|
|
return NotFound();
|
|
}
|
|
else
|
|
{
|
|
return Success();
|
|
}
|
|
}
|
|
|
|
|
|
[HttpPost("{type}")]
|
|
public async Task<ActionResult<ResponseObject>> SaveToProfile([FromBody] SaveToProfileRequest items, string type)
|
|
{
|
|
var item = new Kp7Item
|
|
{
|
|
InsigniaDatereceive = items.InsigniaDatereceive,
|
|
InsigniaLevel = items.InsigniaLevel,
|
|
InsigniaIssue = items.InsigniaIssue,
|
|
InsigniaVolumeno = items.InsigniaVolumeno,
|
|
InsigniaVolume = items.InsigniaVolume,
|
|
InsigniaSection = items.InsigniaSection,
|
|
InsigniaDateannounce = items.InsigniaDateannounce
|
|
};
|
|
|
|
if (items.Profile.Count() != 0)
|
|
{
|
|
foreach(var p in items.Profile)
|
|
{
|
|
await _userProfileRepository.PostProfileInsigniaAsync(new PostProfileInsigniaDto
|
|
{
|
|
profileId = Guid.Parse(p.FkProfileId),
|
|
year = item.InsigniaDateannounce.Value.Year,
|
|
no = p.InsigniaNo,
|
|
volume = item.InsigniaVolume,
|
|
section = item.InsigniaSection,
|
|
page = p.InsigniaPage,
|
|
receiveDate = item.InsigniaDatereceive.Value,
|
|
insigniaId = p.Kp7InsigniaId,
|
|
dateAnnounce = item.InsigniaDateannounce.Value,
|
|
issue = item.InsigniaIssue,
|
|
volumeNo = item.InsigniaVolumeno.Value.ToString(),
|
|
note = "",
|
|
refCommandDate = null,
|
|
refCommandNo = "",
|
|
|
|
}, AccessToken);
|
|
}
|
|
}
|
|
return Success();
|
|
}
|
|
|
|
}
|
|
}
|