api แต่งตั้งลูกจ้าง
This commit is contained in:
parent
15054de97f
commit
4b9c3a2bc7
7 changed files with 576 additions and 0 deletions
|
|
@ -328,6 +328,7 @@ namespace BMA.EHR.Application.Repositories.Commands
|
|||
OldPositionNumber = pf.PosNo == null ? "" : pf.PosNo.Name.ToThaiNumber(),
|
||||
// OldSalary = pf.Salaries == null || pf.Salaries.Count == 0 ? "" : pf.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Amount.Value.ToNumericNoDecimalText().ToThaiNumber(),
|
||||
OldSalary = p.AmountOld == null ? "" : p.AmountOld.Value.ToNumericNoDecimalText().ToThaiNumber(),
|
||||
OldSalaryDate = pf.Salaries == null || pf.Salaries.Count == 0 ? "" : pf.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().Date.Value.ToThaiShortDate2().ToThaiNumber(),
|
||||
NewOc = _organizationCommonRepository.GetOrganizationNameFullPath(p.OrganizationPosition!.Organization!.Id, false, false, "/"),
|
||||
NewPositionName = p.PositionPath == null ? "" : p.PositionPath!.Name,
|
||||
NewPositionLevel = p.PositionLevel == null ? "" : p.PositionLevel.Name,
|
||||
|
|
|
|||
|
|
@ -40,5 +40,6 @@ namespace BMA.EHR.Application.Responses.Reports
|
|||
public string? Reason { get; set; } = string.Empty;
|
||||
public string? LeaveDate { get; set; } = string.Empty;
|
||||
public string? MilitaryDate { get; set; } = string.Empty;
|
||||
public string? OldSalaryDate { get; set; } = string.Empty;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ namespace BMA.EHR.Placement.Service.Controllers
|
|||
{
|
||||
|
||||
var placementAppointments = await _context.PlacementAppointments.AsQueryable()
|
||||
.Where(x => (x.Profile.ProfileType == "EMPLOYEE" && x.Profile.EmployeeType == "PREM") || (x.Profile.ProfileType == "OFFICER"))
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.Select(p => new
|
||||
{
|
||||
|
|
@ -123,6 +124,7 @@ namespace BMA.EHR.Placement.Service.Controllers
|
|||
public async Task<ActionResult<ResponseObject>> GetDetailByUser(Guid id)
|
||||
{
|
||||
var data = await _context.PlacementAppointments.AsQueryable()
|
||||
.Where(x => (x.Profile.ProfileType == "EMPLOYEE" && x.Profile.EmployeeType == "PREM") || (x.Profile.ProfileType == "OFFICER"))
|
||||
.Where(x => x.Id == id)
|
||||
.Select(p => new
|
||||
{
|
||||
|
|
@ -242,6 +244,7 @@ namespace BMA.EHR.Placement.Service.Controllers
|
|||
.Include(x => x.Position)
|
||||
.Include(x => x.Gender)
|
||||
.Include(x => x.Prefix)
|
||||
.Where(x => (x.ProfileType == "EMPLOYEE" && x.EmployeeType == "PREM") || (x.ProfileType == "OFFICER"))
|
||||
.FirstOrDefaultAsync(x => x.Id == req.Id);
|
||||
if (profile == null)
|
||||
return Error(GlobalMessages.DataNotFound, 404);
|
||||
|
|
@ -323,6 +326,7 @@ namespace BMA.EHR.Placement.Service.Controllers
|
|||
public async Task<ActionResult<ResponseObject>> UpdatePositionPlacementAppointment([FromBody] PersonSelectPositionAppointmentRequest req, Guid id)
|
||||
{
|
||||
var uppdated = await _context.PlacementAppointments
|
||||
.Where(x => (x.Profile.ProfileType == "EMPLOYEE" && x.Profile.EmployeeType == "PREM") || (x.Profile.ProfileType == "OFFICER"))
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
if (uppdated == null)
|
||||
return Error(GlobalMessages.PlacementAppointmentNotFound, 404);
|
||||
|
|
@ -402,6 +406,7 @@ 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.EmployeeType == "PREM") || (x.Profile.ProfileType == "OFFICER"))
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
if (uppdated == null)
|
||||
return Error(GlobalMessages.PlacementAppointmentNotFound, 404);
|
||||
|
|
@ -484,6 +489,7 @@ 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.EmployeeType == "PREM") || (x.Profile.ProfileType == "OFFICER"))
|
||||
.FirstOrDefaultAsync(x => x.Id == id);
|
||||
if (deleted == null)
|
||||
return NotFound();
|
||||
|
|
@ -520,6 +526,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.EmployeeType == "PREM") || (x.Profile.ProfileType == "OFFICER"))
|
||||
.FirstOrDefaultAsync(x => x.Id == item);
|
||||
if (uppdated == null)
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,567 @@
|
|||
using BMA.EHR.Application.Repositories;
|
||||
using BMA.EHR.Application.Repositories.MessageQueue;
|
||||
using BMA.EHR.Domain.Common;
|
||||
using BMA.EHR.Domain.Models.Placement;
|
||||
using BMA.EHR.Domain.Shared;
|
||||
using BMA.EHR.Infrastructure.Persistence;
|
||||
using BMA.EHR.Placement.Service.Requests;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Swashbuckle.AspNetCore.Annotations;
|
||||
using System.Security.Claims;
|
||||
|
||||
namespace BMA.EHR.Placement.Service.Controllers
|
||||
{
|
||||
[Route("api/v{version:apiVersion}/placement/appointment/temp")]
|
||||
[ApiVersion("1.0")]
|
||||
[ApiController]
|
||||
[Produces("application/json")]
|
||||
[Authorize]
|
||||
[SwaggerTag("ระบบแต่งตั้ง-เลื่อน")]
|
||||
public class PlacementAppointmentEmployeeController : BaseController
|
||||
{
|
||||
private readonly PlacementRepository _repository;
|
||||
private readonly NotificationRepository _repositoryNoti;
|
||||
private readonly ApplicationDBContext _context;
|
||||
private readonly MinIOService _documentService;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
public PlacementAppointmentEmployeeController(PlacementRepository repository,
|
||||
NotificationRepository repositoryNoti,
|
||||
ApplicationDBContext context,
|
||||
MinIOService documentService,
|
||||
IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_repository = repository;
|
||||
_repositoryNoti = repositoryNoti;
|
||||
_context = context;
|
||||
_documentService = documentService;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
|
||||
#region " Properties "
|
||||
|
||||
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
|
||||
|
||||
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
|
||||
|
||||
private bool? PlacementAdmin => _httpContextAccessor?.HttpContext?.User?.IsInRole("placement1");
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// list รายการแต่งตั้ง-เลื่อน
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet()]
|
||||
public async Task<ActionResult<ResponseObject>> GetListByAdmin()
|
||||
{
|
||||
|
||||
var placementAppointments = await _context.PlacementAppointments.AsQueryable()
|
||||
.OrderByDescending(x => x.CreatedAt)
|
||||
.Where(x => x.Profile.ProfileType == "EMPLOYEE" && x.Profile.EmployeeType == "TEMP")
|
||||
.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.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,
|
||||
|
||||
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)),////
|
||||
OrganizationShortName = p.OrganizationPosition == null ? null : (p.OrganizationPosition.Organization == null ? null : (p.OrganizationPosition.Organization.OrganizationShortName == null ? null : p.OrganizationPosition.Organization.OrganizationShortName.Name)),////
|
||||
p.IsActive,
|
||||
p.PositionDate,
|
||||
p.Reason,
|
||||
p.EducationOld,
|
||||
salary = p.AmountOld,
|
||||
p.PositionTypeOld,
|
||||
p.PositionLevelOld,
|
||||
p.PositionNumberOld,
|
||||
p.OrganizationPositionOld,
|
||||
p.CreatedAt,
|
||||
CommandType = p.CommandType == null ? null : p.CommandType.Name,
|
||||
})
|
||||
.ToListAsync();
|
||||
if (PlacementAdmin == true)
|
||||
placementAppointments.Where(x => x.Status.Trim().ToUpper().Contains("PENDING"));
|
||||
|
||||
return Success(placementAppointments);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get รายละเอียดแต่งตั้ง-เลื่อน
|
||||
/// </summary>
|
||||
/// <param name="id">Id แต่งตั้ง-เลื่อน</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpGet("{id:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> GetDetailByUser(Guid id)
|
||||
{
|
||||
var data = await _context.PlacementAppointments.AsQueryable()
|
||||
.Where(x => x.Id == id)
|
||||
.Where(x => x.Profile.ProfileType == "EMPLOYEE" && x.Profile.EmployeeType == "TEMP")
|
||||
.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.Status,
|
||||
p.Amount,
|
||||
p.RecruitDate,
|
||||
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,
|
||||
OrganizationPositionId = p.OrganizationPosition == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.OrganizationPosition.Id,
|
||||
p.CreatedAt,
|
||||
p.Reason,
|
||||
p.EducationOld,
|
||||
salary = p.AmountOld,
|
||||
p.PositionTypeOld,
|
||||
p.PositionLevelOld,
|
||||
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,
|
||||
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.PositionTypeId,
|
||||
data.PositionLineId,
|
||||
data.PositionLevelId,
|
||||
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,
|
||||
};
|
||||
|
||||
return Success(_data);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// สร้างแต่งตั้ง-เลื่อน
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[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.EmployeeType == "TEMP")
|
||||
.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,
|
||||
Status = "WAITTING",
|
||||
CreatedUserId = UserId ?? "System Administrator",
|
||||
CreatedFullName = FullName ?? "",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
};
|
||||
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);
|
||||
|
||||
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,
|
||||
CreatedUserId = UserId ?? "System Administrator",
|
||||
CreatedFullName = FullName ?? "",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
};
|
||||
await _context.PlacementAppointmentDocs.AddAsync(placementAppointmentDoc);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// เลือกหน่วยงาน
|
||||
/// </summary>
|
||||
/// <param name="id">Id แต่งตั้ง-เลื่อน</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPut("position/{id:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> UpdatePositionPlacementAppointment([FromBody] PersonSelectPositionAppointmentRequest req, Guid id)
|
||||
{
|
||||
var uppdated = await _context.PlacementAppointments
|
||||
.Where(x => x.Profile.ProfileType == "EMPLOYEE" && x.Profile.EmployeeType == "TEMP")
|
||||
.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;
|
||||
}
|
||||
|
||||
if (req.PositionId != null)
|
||||
{
|
||||
var save = await _context.PositionPaths.FindAsync(req.PositionId);
|
||||
if (save == null)
|
||||
return Error(GlobalMessages.PositionPathNotFound, 404);
|
||||
uppdated.PositionPath = save;
|
||||
}
|
||||
|
||||
if (req.PositionLevelId != null)
|
||||
{
|
||||
var save = await _context.PositionLevels.FindAsync(req.PositionLevelId);
|
||||
if (save == null)
|
||||
return Error(GlobalMessages.PositionLevelNotFound, 404);
|
||||
uppdated.PositionLevel = save;
|
||||
}
|
||||
|
||||
if (req.PositionLineId != null)
|
||||
{
|
||||
var save = await _context.PositionLines.FindAsync(req.PositionLineId);
|
||||
if (save == null)
|
||||
return Error(GlobalMessages.PositionLineNotFound, 404);
|
||||
uppdated.PositionLine = save;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
uppdated.Amount = req.Amount;
|
||||
uppdated.RecruitDate = req.RecruitDate;
|
||||
uppdated.Status = "PENDING";
|
||||
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
|
||||
uppdated.LastUpdateUserId = UserId ?? "";
|
||||
uppdated.LastUpdatedAt = DateTime.Now;
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// แก้ไขแต่งตั้ง-เลื่อน
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPut("{id:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> Put([FromBody] PlacementAppointmentEditRequest req, Guid id)
|
||||
{
|
||||
var uppdated = await _context.PlacementAppointments
|
||||
.Where(x => x.Profile.ProfileType == "EMPLOYEE" && x.Profile.EmployeeType == "TEMP")
|
||||
.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;
|
||||
uppdated.PositionTypeOld = req.PositionTypeOld;
|
||||
uppdated.PositionLevelOld = req.PositionLevelOld;
|
||||
uppdated.PositionNumberOld = req.PositionNumberOld;
|
||||
uppdated.AmountOld = req.AmountOld;
|
||||
uppdated.PositionDate = req.PositionDate;
|
||||
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
|
||||
uppdated.LastUpdateUserId = UserId ?? "";
|
||||
uppdated.LastUpdatedAt = DateTime.Now;
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// ลบแต่งตั้ง-เลื่อน
|
||||
/// </summary>
|
||||
/// <param name="id">Id แต่งตั้ง-เลื่อน</param>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpDelete("{id:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> Delete(Guid id)
|
||||
{
|
||||
var deleted = await _context.PlacementAppointments.AsQueryable()
|
||||
.Include(x => x.PlacementAppointmentDocs)
|
||||
.ThenInclude(x => x.Document)
|
||||
.Where(x => x.Profile.ProfileType == "EMPLOYEE" && x.Profile.EmployeeType == "TEMP")
|
||||
.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);
|
||||
}
|
||||
_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();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// สั่งรายชื่อไปออกคำสั่ง
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
||||
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
||||
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
||||
[HttpPut("report/{commandTypeId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> PostToReport([FromBody] PlacementProfileRequest req, Guid commandTypeId)
|
||||
{
|
||||
foreach (var item in req.Id)
|
||||
{
|
||||
var uppdated = await _context.PlacementAppointments
|
||||
.Where(x => x.Profile.ProfileType == "EMPLOYEE" && x.Profile.EmployeeType == "TEMP")
|
||||
.FirstOrDefaultAsync(x => x.Id == item);
|
||||
if (uppdated == null)
|
||||
continue;
|
||||
|
||||
uppdated.CommandType = await _context.CommandTypes.FindAsync(commandTypeId);
|
||||
uppdated.Status = "REPORT";
|
||||
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
|
||||
uppdated.LastUpdateUserId = UserId ?? "";
|
||||
uppdated.LastUpdatedAt = DateTime.Now;
|
||||
}
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
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)
|
||||
.Select(x => x.PositionNumber.Id)
|
||||
.ToListAsync();
|
||||
|
||||
return Success(appointments);
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue