แก้ระบบบรรจุผูกโครงสร้างใหม่

This commit is contained in:
Kittapath 2024-05-02 09:31:38 +07:00
parent 57164f5d45
commit 18d75f4b04
37 changed files with 79295 additions and 3904 deletions

View file

@ -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 PlacementAppointmentEmployeeController(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");
@ -63,47 +69,48 @@ namespace BMA.EHR.Placement.Service.Controllers
{
var placementAppointments = await _context.PlacementAppointments.AsQueryable()
.Where(x => x.type == "EMPLOYEE")
.OrderByDescending(x => x.CreatedAt)
.Where(x => x.Profile.ProfileType == "employee" && x.Profile.EmployeeClass == "perm")
.Select(p => new
{
p.Id,
p.CitizenId,
Prefix = p.Prefix == null ? null : p.Prefix.Name,
p.Firstname,
p.Lastname,
p.DateOfBirth,
Gender = p.Gender == null ? null : p.Gender.Name,
p.prefix,
p.firstName,
p.lastName,
p.root,
p.rootShortName,
p.child1,
p.child1ShortName,
p.child2,
p.child2ShortName,
p.child3,
p.child3ShortName,
p.child4,
p.child4ShortName,
p.posMasterNo,
p.positionName,
p.posLevelName,
p.posTypeName,
p.rootOld,
p.rootShortNameOld,
p.child1Old,
p.child1ShortNameOld,
p.child2Old,
p.child2ShortNameOld,
p.child3Old,
p.child3ShortNameOld,
p.child4Old,
p.child4ShortNameOld,
p.posMasterNoOld,
p.positionOld,
p.posLevelNameOld,
p.posTypeNameOld,
p.Status,
p.Amount,
p.RecruitDate,
// PositionNumber = p.PositionNumber == null ? null : p.PositionNumber.Name,
// PositionPath = p.PositionPath == null ? null : p.PositionPath.Name,
// PositionPathSide = p.PositionPathSide == null ? null : p.PositionPathSide.Name,
// PositionType = p.PositionType == null ? null : p.PositionType.Name,
// PositionLine = p.PositionLine == null ? null : p.PositionLine.Name,
// PositionLevel = p.PositionLevel == null ? null : p.PositionLevel.Name,
// PosNoId = p.PositionNumber == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionNumber.Id,
// PositionId = p.PositionPath == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionPath.Id,
// PositionPathSideId = p.PositionPathSide == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionPathSide.Id,
// PositionTypeId = p.PositionType == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionType.Id,
// PositionLineId = p.PositionLine == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionLine.Id,
// PositionLevelId = p.PositionLevel == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionLevel.Id,
OrgEmployeeId = p.OrgEmployee == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.OrgEmployee.Id,
PositionEmployeeStatusId = p.PositionEmployeeStatus == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionEmployeeStatus.Id,
PositionEmployeeLineId = p.PositionEmployeeLine == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionEmployeeLine.Id,
PositionEmployeePositionId = p.PositionEmployeePosition == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionEmployeePosition.Id,
PositionEmployeeStatus = p.PositionEmployeeStatus == null ? null : p.PositionEmployeeStatus.Name,
PositionEmployeeLine = p.PositionEmployeeLine == null ? null : p.PositionEmployeeLine.Name,
PositionEmployeePosition = p.PositionEmployeePosition == null ? null : p.PositionEmployeePosition.Name,
// OrganizationShortName = x.OrganizationShortName == null ? null : x.OrganizationShortName.Name,
OrganizationPositionId = p.OrganizationPosition == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.OrganizationPosition.Id,
// OrganizationName = p.OrganizationPosition == null ? null : (p.OrganizationPosition.Organization == null ? null : (p.OrganizationPosition.Organization.OrganizationOrganization == null ? null : p.OrganizationPosition.Organization.OrganizationOrganization.Name)),////
OrganizationName = p.OrgEmployee == null ? null : (p.OrgEmployee.OrganizationOrganization == null ? null : p.OrgEmployee.OrganizationOrganization.Name),
OrganizationShortName = p.OrgEmployee == null ? null : (p.OrgEmployee.OrganizationShortName == null ? null : p.OrgEmployee.OrganizationShortName.Name),
p.IsActive,
p.PositionDate,
p.Reason,
@ -117,8 +124,6 @@ namespace BMA.EHR.Placement.Service.Controllers
CommandType = p.CommandType == null ? null : p.CommandType.Name,
})
.ToListAsync();
if (PlacementAdmin == true)
placementAppointments.Where(x => x.Status.Trim().ToUpper().Contains("PENDING"));
return Success(placementAppointments);
}
@ -136,36 +141,49 @@ namespace BMA.EHR.Placement.Service.Controllers
public async Task<ActionResult<ResponseObject>> GetDetailByUser(Guid id)
{
var data = await _context.PlacementAppointments.AsQueryable()
.Where(x => x.type == "EMPLOYEE")
.Where(x => x.Id == id)
.Where(x => x.Profile.ProfileType == "employee" && x.Profile.EmployeeClass == "perm")
.Select(p => new
{
p.Id,
ProfileId = p.Profile.Id,
p.CitizenId,
Prefix = p.Prefix == null ? null : p.Prefix.Name,
PrefixId = p.Prefix == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Prefix.Id,
p.Firstname,
p.Lastname,
p.DateOfBirth,
Gender = p.Gender == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Gender.Id,
p.Nationality,
p.Race,
Religion = p.Religion == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Religion.Id,
BloodGroup = p.BloodGroup == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.BloodGroup.Id,
Relationship = p.Relationship == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Relationship.Id,
p.TelephoneNumber,
p.profileId,
p.prefix,
p.firstName,
p.lastName,
p.root,
p.rootShortName,
p.child1,
p.child1ShortName,
p.child2,
p.child2ShortName,
p.child3,
p.child3ShortName,
p.child4,
p.child4ShortName,
p.posMasterNo,
p.positionName,
p.posLevelName,
p.posTypeName,
p.rootOld,
p.rootShortNameOld,
p.child1Old,
p.child1ShortNameOld,
p.child2Old,
p.child2ShortNameOld,
p.child3Old,
p.child3ShortNameOld,
p.child4Old,
p.child4ShortNameOld,
p.posMasterNoOld,
p.positionOld,
p.posLevelNameOld,
p.posTypeNameOld,
p.Status,
p.Amount,
p.RecruitDate,
OrgEmployeeId = p.OrgEmployee == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.OrgEmployee.Id,
PositionEmployeeStatusId = p.PositionEmployeeStatus == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionEmployeeStatus.Id,
PositionEmployeeLineId = p.PositionEmployeeLine == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionEmployeeLine.Id,
PositionEmployeePositionId = p.PositionEmployeePosition == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionEmployeePosition.Id,
// PositionTypeId = p.PositionType == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionType.Id,
// PositionLineId = p.PositionLine == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionLine.Id,
// PositionLevelId = p.PositionLevel == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionLevel.Id,
OrganizationPositionId = p.OrganizationPosition == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.OrganizationPosition.Id,
p.CreatedAt,
p.Reason,
p.EducationOld,
@ -175,67 +193,78 @@ namespace BMA.EHR.Placement.Service.Controllers
p.PositionNumberOld,
p.OrganizationPositionOld,
p.PositionDate,
PlacementAppointmentDocs = p.PlacementAppointmentDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
Avatar = p.Profile.Avatar == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Avatar.Id,
// PlacementAppointmentDocs = p.PlacementAppointmentDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
CommandType = p.CommandType == null ? null : p.CommandType.Name,
})
.FirstOrDefaultAsync();
if (data == null)
return Error(GlobalMessages.DataNotFound, 404);
var placementAppointmentDocs = new List<dynamic>();
foreach (var doc in data.PlacementAppointmentDocs)
{
var _doc = new
{
doc.FileName,
PathName = await _documentService.ImagesPath(doc.Id)
};
placementAppointmentDocs.Add(_doc);
}
var _data = new
{
data.Id,
data.ProfileId,
data.CitizenId,
data.Prefix,
data.PrefixId,
data.Firstname,
data.Lastname,
data.DateOfBirth,
data.Gender,
data.Nationality,
data.Race,
data.Religion,
data.BloodGroup,
data.Relationship,
data.TelephoneNumber,
data.Status,
data.Amount,
data.RecruitDate,
// data.PosNoId,
// data.PositionId,
// data.PositionPathSideId,
data.OrgEmployeeId,
data.PositionEmployeeStatusId,
data.PositionEmployeeLineId,
data.PositionEmployeePositionId,
data.OrganizationPositionId,
data.CreatedAt,
data.Reason,
data.EducationOld,
data.salary,
data.PositionTypeOld,
data.PositionLevelOld,
data.PositionNumberOld,
data.OrganizationPositionOld,
data.PositionDate,
Avatar = data.Avatar == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.Avatar),
Docs = placementAppointmentDocs,
data.CommandType,
};
// var placementAppointmentDocs = new List<dynamic>();
// foreach (var doc in data.PlacementAppointmentDocs)
// {
// var _doc = new
// {
// doc.FileName,
// PathName = await _documentService.ImagesPath(doc.Id)
// };
// placementAppointmentDocs.Add(_doc);
// }
// var _data = new
// {
// data.Id,
// data.profileId,
// data.prefix,
// data.firstName,
// data.lastName,
// data.root,
// data.rootShortName,
// data.child1,
// data.child1ShortName,
// data.child2,
// data.child2ShortName,
// data.child3,
// data.child3ShortName,
// data.child4,
// data.child4ShortName,
// data.posMasterNo,
// data.positionName,
// data.posLevelName,
// data.posTypeName,
return Success(_data);
// data.rootOld,
// data.rootShortNameOld,
// data.child1Old,
// data.child1ShortNameOld,
// data.child2Old,
// data.child2ShortNameOld,
// data.child3Old,
// data.child3ShortNameOld,
// data.child4Old,
// data.child4ShortNameOld,
// data.posMasterNoOld,
// data.positionOld,
// data.posLevelNameOld,
// data.posTypeNameOld,
// data.Status,
// data.Amount,
// data.RecruitDate,
// data.CreatedAt,
// data.Reason,
// data.EducationOld,
// data.salary,
// data.PositionTypeOld,
// data.PositionLevelOld,
// data.PositionNumberOld,
// data.OrganizationPositionOld,
// data.PositionDate,
// Docs = placementAppointmentDocs,
// data.CommandType,
// };
return Success(data);
}
/// <summary>
@ -249,42 +278,29 @@ 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.Educations)
.Include(x => x.Position)
.Include(x => x.Gender)
.Include(x => x.Prefix)
.Where(x => x.ProfileType == "employee" && x.EmployeeClass == "perm")
.FirstOrDefaultAsync(x => x.Id == req.Id);
if (profile == null)
return Error(GlobalMessages.DataNotFound, 404);
var placementAppointment = new PlacementAppointment
{
Profile = profile,
CitizenId = profile.CitizenId,
Prefix = profile.Prefix,
Firstname = profile.FirstName,
Lastname = profile.LastName,
DateOfBirth = profile.BirthDate,
Gender = profile.Gender,
Nationality = profile.Nationality,
Race = profile.Race,
Religion = await _context.Religions.FindAsync(profile.ReligionId),
BloodGroup = await _context.BloodGroups.FindAsync(profile.BloodGroupId),
Relationship = await _context.Relationships.FindAsync(profile.RelationshipId),
TelephoneNumber = profile.TelephoneNumber,
EducationOld = profile.Educations.Count() == 0 ? null : $"{profile.Educations.OrderByDescending(x => x.FinishDate).FirstOrDefault().Degree}-{profile.Educations.OrderByDescending(x => x.FinishDate).FirstOrDefault().Field}",
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}",
PositionDate = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Date,
// Profile = profile,
// CitizenId = profile.CitizenId,
// Prefix = profile.Prefix,
// Firstname = profile.FirstName,
// Lastname = profile.LastName,
// DateOfBirth = profile.BirthDate,
// Gender = profile.Gender,
// Nationality = profile.Nationality,
// Race = profile.Race,
// Religion = await _context.Religions.FindAsync(profile.ReligionId),
// BloodGroup = await _context.BloodGroups.FindAsync(profile.BloodGroupId),
// Relationship = await _context.Relationships.FindAsync(profile.RelationshipId),
// TelephoneNumber = profile.TelephoneNumber,
// EducationOld = profile.Educations.Count() == 0 ? null : $"{profile.Educations.OrderByDescending(x => x.FinishDate).FirstOrDefault().Degree}-{profile.Educations.OrderByDescending(x => x.FinishDate).FirstOrDefault().Field}",
// 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}",
// PositionDate = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Date,
type = "EMPLOYEE",
Status = "WAITTING",
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
@ -293,36 +309,76 @@ namespace BMA.EHR.Placement.Service.Controllers
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
var apiUrl = $"{_configuration["API"]}org/profile/profileempid/position/{req.Id}";
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);
placementAppointment.profileId = org.result.profileId;
placementAppointment.prefix = org.result.prefix;
placementAppointment.firstName = org.result.firstName;
placementAppointment.lastName = org.result.lastName;
placementAppointment.citizenId = org.result.citizenId;
placementAppointment.rootOld = org.result.root;
placementAppointment.rootOldId = org.result.rootId;
placementAppointment.rootShortNameOld = org.result.rootShortName;
placementAppointment.child1Old = org.result.child1;
placementAppointment.child1OldId = org.result.child1Id;
placementAppointment.child1ShortNameOld = org.result.child1ShortName;
placementAppointment.child2Old = org.result.child2;
placementAppointment.child2OldId = org.result.child2Id;
placementAppointment.child2ShortNameOld = org.result.child2ShortName;
placementAppointment.child3Old = org.result.child3;
placementAppointment.child3OldId = org.result.child3Id;
placementAppointment.child3ShortNameOld = org.result.child3ShortName;
placementAppointment.child4Old = org.result.child4;
placementAppointment.child4OldId = org.result.child4Id;
placementAppointment.child4ShortNameOld = org.result.child4ShortName;
placementAppointment.posMasterNoOld = org.result.posMasterNo;
placementAppointment.positionOld = org.result.position;
placementAppointment.posTypeOldId = org.result.posTypeId;
placementAppointment.posTypeNameOld = org.result.posTypeName;
placementAppointment.posLevelOldId = org.result.posLevelId;
placementAppointment.posLevelNameOld = org.result.posLevelName;
}
await _context.PlacementAppointments.AddAsync(placementAppointment);
await _context.SaveChangesAsync();
if (Request.Form.Files != null && Request.Form.Files.Count != 0)
{
foreach (var file in Request.Form.Files)
{
var fileExtension = Path.GetExtension(file.FileName);
// if (Request.Form.Files != null && Request.Form.Files.Count != 0)
// {
// foreach (var file in Request.Form.Files)
// {
// var fileExtension = Path.GetExtension(file.FileName);
var doc = await _documentService.UploadFileAsync(file, file.FileName);
var _doc = await _context.Documents.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == doc.Id);
if (_doc != null)
{
var placementAppointmentDoc = new PlacementAppointmentDoc
{
PlacementAppointment = placementAppointment,
Document = _doc,
CreatedFullName = FullName ?? "System Administrator",
CreatedUserId = UserId ?? "",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
await _context.PlacementAppointmentDocs.AddAsync(placementAppointmentDoc);
// var doc = await _documentService.UploadFileAsync(file, file.FileName);
// var _doc = await _context.Documents.AsQueryable()
// .FirstOrDefaultAsync(x => x.Id == doc.Id);
// if (_doc != null)
// {
// var placementAppointmentDoc = new PlacementAppointmentDoc
// {
// PlacementAppointment = placementAppointment,
// Document = _doc,
// CreatedFullName = FullName ?? "System Administrator",
// CreatedUserId = UserId ?? "",
// CreatedAt = DateTime.Now,
// LastUpdateFullName = FullName ?? "System Administrator",
// LastUpdateUserId = UserId ?? "",
// LastUpdatedAt = DateTime.Now,
// };
// await _context.PlacementAppointmentDocs.AddAsync(placementAppointmentDoc);
}
}
}
await _context.SaveChangesAsync();
// }
// }
// }
// await _context.SaveChangesAsync();
return Success();
}
@ -340,76 +396,58 @@ namespace BMA.EHR.Placement.Service.Controllers
public async Task<ActionResult<ResponseObject>> UpdatePositionPlacementAppointment([FromBody] PersonSelectPositionAppointmentEmployeeRequest req, Guid id)
{
var uppdated = await _context.PlacementAppointments
.Where(x => x.Profile.ProfileType == "employee" && x.Profile.EmployeeClass == "perm")
.FirstOrDefaultAsync(x => x.Id == id);
if (uppdated == null)
return Error(GlobalMessages.PlacementAppointmentNotFound, 404);
// if (req.PosNoId != null)
// {
// var save_posNo = await _context.PositionNumbers.FindAsync(req.PosNoId);
// if (save_posNo == null)
// return Error(GlobalMessages.PositionPosNoNotFound, 404);
// uppdated.PositionNumber = save_posNo;
// var save_orgPosition = await _context.OrganizationPositions.FirstOrDefaultAsync(x => x.PositionNumber == save_posNo);
// if (save_orgPosition == null)
// return Error(GlobalMessages.PositionPosNoNotFound, 404);
// uppdated.OrganizationPosition = save_orgPosition;
// }
var apiUrl = $"{_configuration["API"]}org/find/all";
// if (req.PositionId != null)
// {
// var save = await _context.PositionPaths.FindAsync(req.PositionId);
// if (save == null)
// return Error(GlobalMessages.PositionPathNotFound, 404);
// uppdated.PositionPath = save;
// }
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.Replace("Bearer ", ""));
var _req = new HttpRequestMessage(HttpMethod.Post, apiUrl);
var _res = await client.PostAsJsonAsync(apiUrl, new
{
node = req.node,
nodeId = req.nodeId,
});
var _result = await _res.Content.ReadAsStringAsync();
var org = JsonConvert.DeserializeObject<OrgRequest>(_result);
// if (req.PositionLevelId != null)
// {
// var save = await _context.PositionLevels.FindAsync(req.PositionLevelId);
// if (save == null)
// return Error(GlobalMessages.PositionLevelNotFound, 404);
// uppdated.PositionLevel = save;
// }
if (org == null || org.result == null)
return Error("ไม่พบหน่วยงานนี้ในระบบ", 404);
// if (req.PositionLineId != null)
// {
// var save = await _context.PositionLines.FindAsync(req.PositionLineId);
// if (save == null)
// return Error(GlobalMessages.PositionLineNotFound, 404);
// uppdated.PositionLine = save;
// }
uppdated.root = org.result.root;
uppdated.rootId = org.result.rootId;
uppdated.rootShortName = org.result.rootShortName;
uppdated.child1 = req.node <= 0 ? null : org.result.child1;
uppdated.child1Id = req.node <= 0 ? null : org.result.child1Id;
uppdated.child1ShortName = req.node <= 0 ? null : org.result.child1ShortName;
uppdated.child2 = req.node <= 1 ? null : org.result.child2;
uppdated.child2Id = req.node <= 1 ? null : org.result.child2Id;
uppdated.child2ShortName = req.node <= 1 ? null : org.result.child2ShortName;
uppdated.child3 = req.node <= 2 ? null : org.result.child3;
uppdated.child3Id = req.node <= 2 ? null : org.result.child3Id;
uppdated.child3ShortName = req.node <= 2 ? null : org.result.child3ShortName;
uppdated.child4 = req.node <= 3 ? null : org.result.child4;
uppdated.child4Id = req.node <= 3 ? null : org.result.child4Id;
uppdated.child4ShortName = req.node <= 3 ? null : org.result.child4ShortName;
}
// if (req.PositionPathSideId != null)
// {
// var save = await _context.PositionPathSides.FindAsync(req.PositionPathSideId);
// if (save == null)
// return Error(GlobalMessages.PositionPathSideNotFound, 404);
// uppdated.PositionPathSide = save;
// }
// if (req.PositionTypeId != null)
// {
// var save = await _context.PositionTypes.FindAsync(req.PositionTypeId);
// if (save == null)
// return Error(GlobalMessages.PositionTypeNotFound, 404);
// uppdated.PositionType = save;
// }
var organizationEmployee = await _context.OrganizationEmployees
.Include(x => x.PositionEmployeeStatus)
.Include(x => x.PositionEmployeeLine)
.Include(x => x.PositionEmployeePosition)
.FirstOrDefaultAsync(x => x.Id == req.OrganizationEmployeeId);
if (organizationEmployee == null)
return Error(GlobalMessages.OrganizationEmployeeNotFound, 404);
uppdated.OrgEmployee = organizationEmployee;
uppdated.PositionEmployeeStatus = organizationEmployee.PositionEmployeeStatus;
uppdated.PositionEmployeeLine = organizationEmployee.PositionEmployeeLine;
uppdated.PositionEmployeePosition = organizationEmployee.PositionEmployeePosition;
// uppdated.Amount = req.Amount;
// uppdated.RecruitDate = req.RecruitDate;
uppdated.posmasterId = req.posmasterId;
uppdated.node = req.node;
uppdated.nodeId = req.nodeId;
uppdated.orgRevisionId = req.orgRevisionId;
uppdated.positionId = req.positionId;
uppdated.posMasterNo = req.posMasterNo;
uppdated.positionName = req.positionName;
uppdated.positionField = req.positionField;
uppdated.posTypeId = req.posTypeId;
uppdated.posTypeName = req.posTypeName;
uppdated.posLevelId = req.posLevelId;
uppdated.posLevelName = req.posLevelName;
uppdated.Amount = req.Amount;
uppdated.RecruitDate = req.RecruitDate;
uppdated.Status = "PENDING";
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
uppdated.LastUpdateUserId = UserId ?? "";
@ -431,58 +469,11 @@ namespace BMA.EHR.Placement.Service.Controllers
public async Task<ActionResult<ResponseObject>> Put([FromBody] PlacementAppointmentEditRequest req, Guid id)
{
var uppdated = await _context.PlacementAppointments
.Where(x => x.Profile.ProfileType == "employee" && x.Profile.EmployeeClass == "perm")
.FirstOrDefaultAsync(x => x.Id == id);
if (uppdated == null)
return Error(GlobalMessages.PlacementAppointmentNotFound, 404);
if (req.PrefixId != null)
{
var save = await _context.Prefixes.FindAsync(req.PrefixId);
if (save == null)
return Error(GlobalMessages.PrefixNotFound, 404);
uppdated.Prefix = save;
}
// if (req.RelationshipId != null)
// {
// var save = await _context.Relationships.FindAsync(req.RelationshipId);
// if (save == null)
// return Error(GlobalMessages.RelationshipNotFound, 404);
// uppdated.Relationship = save;
// }
// if (req.ReligionId != null)
// {
// var save = await _context.Religions.FindAsync(req.ReligionId);
// if (save == null)
// return Error(GlobalMessages.ReligionNotFound, 404);
// uppdated.Religion = save;
// }
// if (req.BloodGroupId != null)
// {
// var save = await _context.BloodGroups.FindAsync(req.BloodGroupId);
// if (save == null)
// return Error(GlobalMessages.BloodGroupNotFound, 404);
// uppdated.BloodGroup = save;
// }
// if (req.GenderId != null)
// {
// var save = await _context.Genders.FindAsync(req.GenderId);
// if (save == null)
// return Error(GlobalMessages.GenderNotFound, 404);
// uppdated.Gender = save;
// }
uppdated.CitizenId = req.CitizenId;
uppdated.Firstname = req.Firstname;
uppdated.Lastname = req.Lastname;
// uppdated.DateOfBirth = req.DateOfBirth;
// uppdated.Nationality = req.Nationality;
// uppdated.Race = req.Race;
// uppdated.TelephoneNumber = req.TelephoneNumber;
uppdated.EducationOld = req.EducationOld;
uppdated.Reason = req.Reason;
uppdated.OrganizationPositionOld = req.OrganizationPositionOld;
@ -514,25 +505,24 @@ namespace BMA.EHR.Placement.Service.Controllers
var deleted = await _context.PlacementAppointments.AsQueryable()
.Include(x => x.PlacementAppointmentDocs)
.ThenInclude(x => x.Document)
.Where(x => x.Profile.ProfileType == "employee" && x.Profile.EmployeeClass == "perm")
.FirstOrDefaultAsync(x => x.Id == id);
if (deleted == null)
return NotFound();
var placementAppointmentDocs = new List<dynamic>();
foreach (var doc in deleted.PlacementAppointmentDocs)
{
if (doc.Document != null)
placementAppointmentDocs.Add(doc.Document.Id);
}
// var placementAppointmentDocs = new List<dynamic>();
// foreach (var doc in deleted.PlacementAppointmentDocs)
// {
// if (doc.Document != null)
// placementAppointmentDocs.Add(doc.Document.Id);
// }
_context.PlacementAppointmentDocs.RemoveRange(deleted.PlacementAppointmentDocs);
await _context.SaveChangesAsync();
_context.PlacementAppointments.Remove(deleted);
foreach (var doc in placementAppointmentDocs)
{
if (doc != null)
await _documentService.DeleteFileAsync(doc);
}
await _context.SaveChangesAsync();
// _context.PlacementAppointments.Remove(deleted);
// foreach (var doc in placementAppointmentDocs)
// {
// if (doc != null)
// await _documentService.DeleteFileAsync(doc);
// }
// await _context.SaveChangesAsync();
return Success();
}
@ -551,7 +541,7 @@ namespace BMA.EHR.Placement.Service.Controllers
foreach (var item in req.Id)
{
var uppdated = await _context.PlacementAppointments
.Where(x => x.Profile.ProfileType == "employee" && x.Profile.EmployeeClass == "perm")
// .Where(x => x.Profile.ProfileType == "employee" && x.Profile.EmployeeClass == "perm")
.FirstOrDefaultAsync(x => x.Id == item);
if (uppdated == null)
continue;
@ -568,24 +558,24 @@ namespace BMA.EHR.Placement.Service.Controllers
return Success();
}
/// <summary>
/// หน่วยงานที่ถูกเลือกไปแล้ว
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("use")]
public async Task<ActionResult<ResponseObject>> GetAppointmentsUse()
{
var appointments = await _context.PlacementAppointments
.Where(x => x.PositionNumber != null)
.Where(x => x.Profile.ProfileType == "employee" && x.Profile.EmployeeClass == "perm")
.Select(x => x.PositionNumber.Id)
.ToListAsync();
// /// <summary>
// /// หน่วยงานที่ถูกเลือกไปแล้ว
// /// </summary>
// /// <returns></returns>
// /// <response code="200"></response>
// /// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
// /// <response code="401">ไม่ได้ Login เข้าระบบ</response>
// /// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
// [HttpGet("use")]
// public async Task<ActionResult<ResponseObject>> GetAppointmentsUse()
// {
// var appointments = await _context.PlacementAppointments
// .Where(x => x.PositionNumber != null)
// .Where(x => x.Profile.ProfileType == "employee" && x.Profile.EmployeeClass == "perm")
// .Select(x => x.PositionNumber.Id)
// .ToListAsync();
return Success(appointments);
}
// return Success(appointments);
// }
}
}