no message
This commit is contained in:
parent
dc91f81262
commit
57164f5d45
11 changed files with 34879 additions and 185 deletions
|
|
@ -8,7 +8,9 @@ using BMA.EHR.Placement.Service.Requests;
|
|||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace BMA.EHR.Placement.Service.Controllers
|
||||
|
|
@ -26,18 +28,21 @@ namespace BMA.EHR.Placement.Service.Controllers
|
|||
private readonly ApplicationDBContext _context;
|
||||
private readonly MinIOService _documentService;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly IConfiguration _configuration;
|
||||
|
||||
public PlacementOfficerController(PlacementRepository repository,
|
||||
NotificationRepository repositoryNoti,
|
||||
ApplicationDBContext context,
|
||||
MinIOService documentService,
|
||||
IHttpContextAccessor httpContextAccessor)
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
_repository = repository;
|
||||
_repositoryNoti = repositoryNoti;
|
||||
_context = context;
|
||||
_documentService = documentService;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
#region " Properties "
|
||||
|
|
@ -45,6 +50,7 @@ namespace BMA.EHR.Placement.Service.Controllers
|
|||
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"];
|
||||
|
||||
private bool? PlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
|
||||
|
||||
|
|
@ -176,27 +182,18 @@ namespace BMA.EHR.Placement.Service.Controllers
|
|||
[HttpPost()]
|
||||
public async Task<ActionResult<ResponseObject>> Post([FromForm] PlacementAddProfileRequest req)
|
||||
{
|
||||
var profile = await _context.Profiles
|
||||
.Include(x => x.PositionLevel)
|
||||
.Include(x => x.PositionType)
|
||||
.Include(x => x.PosNo)
|
||||
.Include(x => x.Salaries)
|
||||
.Include(x => x.Position)
|
||||
.FirstOrDefaultAsync(x => x.Id == req.Id);
|
||||
if (profile == null)
|
||||
return Error(GlobalMessages.DataNotFound, 404);
|
||||
|
||||
var placementOfficer = new PlacementOfficer
|
||||
{
|
||||
Profile = profile,
|
||||
// Profile = profile,
|
||||
Organization = Request.Form.ContainsKey("Organization") ? Request.Form["Organization"] : "",
|
||||
Reason = Request.Form.ContainsKey("Reason") ? Request.Form["Reason"] : "",
|
||||
// Date = req.Date,
|
||||
AmountOld = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount,
|
||||
PositionLevelOld = profile.PositionLevel == null ? null : profile.PositionLevel.Name,
|
||||
PositionTypeOld = profile.PositionType == null ? null : profile.PositionType.Name,
|
||||
PositionNumberOld = profile.PosNo == null ? null : profile.PosNo.Name,
|
||||
OrganizationPositionOld = profile.Position == null ? profile.Oc : $"{profile.Position.Name}-{profile.Oc}",
|
||||
// AmountOld = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount,
|
||||
// PositionLevelOld = profile.PositionLevel == null ? null : profile.PositionLevel.Name,
|
||||
// PositionTypeOld = profile.PositionType == null ? null : profile.PositionType.Name,
|
||||
// PositionNumberOld = profile.PosNo == null ? null : profile.PosNo.Name,
|
||||
// OrganizationPositionOld = profile.Position == null ? profile.Oc : $"{profile.Position.Name}-{profile.Oc}",
|
||||
|
||||
Status = "WAITTING",
|
||||
CreatedFullName = FullName ?? "System Administrator",
|
||||
CreatedUserId = UserId ?? "",
|
||||
|
|
@ -205,6 +202,40 @@ namespace BMA.EHR.Placement.Service.Controllers
|
|||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
};
|
||||
var rootId = "";
|
||||
var child1Id = "";
|
||||
var child2Id = "";
|
||||
var child3Id = "";
|
||||
var child4Id = "";
|
||||
var apiUrl = $"{_configuration["API"]}org/profile/keycloak/position";
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
|
||||
var _req = new HttpRequestMessage(HttpMethod.Get, apiUrl);
|
||||
var _res = await client.SendAsync(_req);
|
||||
var _result = await _res.Content.ReadAsStringAsync();
|
||||
|
||||
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
|
||||
|
||||
if (org == null || org.result == null)
|
||||
return Error("ไม่พบหน่วยงานของผู้ใช้งานคนนี้", 404);
|
||||
|
||||
placementOfficer.root = org.result.root;
|
||||
placementOfficer.rootId = org.result.rootId;
|
||||
placementOfficer.rootShortName = org.result.rootShortName;
|
||||
placementOfficer.child1 = org.result.child1;
|
||||
placementOfficer.child1Id = org.result.child1Id;
|
||||
placementOfficer.child1ShortName = org.result.child1ShortName;
|
||||
placementOfficer.child2 = org.result.child2;
|
||||
placementOfficer.child2Id = org.result.child2Id;
|
||||
placementOfficer.child2ShortName = org.result.child2ShortName;
|
||||
placementOfficer.child3 = org.result.child3;
|
||||
placementOfficer.child3Id = org.result.child3Id;
|
||||
placementOfficer.child3ShortName = org.result.child3ShortName;
|
||||
placementOfficer.child4 = org.result.child4;
|
||||
placementOfficer.child4Id = org.result.child4Id;
|
||||
placementOfficer.child4ShortName = org.result.child4ShortName;
|
||||
}
|
||||
await _context.PlacementOfficers.AddAsync(placementOfficer);
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue