633 lines
31 KiB
C#
633 lines
31 KiB
C#
using BMA.EHR.Application.Repositories;
|
|
using BMA.EHR.Domain.Common;
|
|
using BMA.EHR.Domain.Extensions;
|
|
using BMA.EHR.Domain.Models.MetaData;
|
|
using BMA.EHR.Domain.Models.Retirement;
|
|
using BMA.EHR.Domain.Shared;
|
|
using BMA.EHR.Infrastructure.Persistence;
|
|
using BMA.EHR.Retirement.Service.Requests;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Swashbuckle.AspNetCore.Annotations;
|
|
using System.Security.Claims;
|
|
using System.Security.Cryptography;
|
|
|
|
namespace BMA.EHR.Retirement.Service.Controllers
|
|
{
|
|
[Route("api/v{version:apiVersion}/retirement/resign")]
|
|
[ApiVersion("1.0")]
|
|
[ApiController]
|
|
[Produces("application/json")]
|
|
[Authorize]
|
|
[SwaggerTag("ระบบลาออก")]
|
|
public class RetirementResignController : BaseController
|
|
{
|
|
private readonly RetirementRepository _repository;
|
|
private readonly ApplicationDBContext _context;
|
|
private readonly MinIOService _documentService;
|
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
|
|
public RetirementResignController(RetirementRepository repository,
|
|
ApplicationDBContext context,
|
|
MinIOService documentService,
|
|
IHttpContextAccessor httpContextAccessor)
|
|
{
|
|
_repository = repository;
|
|
_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;
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// list รายการลาออกของ User
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("user")]
|
|
public async Task<ActionResult<ResponseObject>> GetListByProfile()
|
|
{
|
|
var profile = await _context.Profiles
|
|
.FirstOrDefaultAsync(x => x.KeycloakId == Guid.Parse(UserId));
|
|
if (profile == null)
|
|
return Error(GlobalMessages.DataNotFound, 404);
|
|
|
|
var retirementResigns = await _context.RetirementResigns.AsQueryable()
|
|
.Where(x => x.Profile == profile)
|
|
.OrderByDescending(x => x.CreatedAt)
|
|
.Select(p => new
|
|
{
|
|
p.Id,
|
|
p.Location,
|
|
p.SendDate,
|
|
p.ActiveDate,
|
|
p.Reason,
|
|
p.ApproveReason,
|
|
p.RejectReason,
|
|
p.Status,
|
|
p.IsActive,
|
|
})
|
|
.ToListAsync();
|
|
|
|
return Success(retirementResigns);
|
|
}
|
|
|
|
/// <summary>
|
|
/// list รายการลาออกของ Admin
|
|
/// </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 retirementResigns = await _context.RetirementResigns.AsQueryable()
|
|
.OrderByDescending(x => x.CreatedAt)
|
|
.Select(p => new
|
|
{
|
|
p.Id,
|
|
ProfileId = p.Profile.Id,
|
|
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name,
|
|
p.Profile.FirstName,
|
|
p.Profile.LastName,
|
|
p.Location,
|
|
p.SendDate,
|
|
p.ActiveDate,
|
|
p.Reason,
|
|
p.Status,
|
|
salary = p.AmountOld,
|
|
p.PositionTypeOld,
|
|
p.PositionLevelOld,
|
|
p.PositionNumberOld,
|
|
p.OrganizationPositionOld,
|
|
p.ApproveReason,
|
|
p.RejectReason,
|
|
p.IsActive,
|
|
p.CreatedAt,
|
|
})
|
|
.ToListAsync();
|
|
|
|
return Success(retirementResigns);
|
|
}
|
|
|
|
/// <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.RetirementResigns.AsQueryable()
|
|
.Where(x => x.Id == id)
|
|
.Select(p => new
|
|
{
|
|
p.Id,
|
|
Prefix = p.Profile.Prefix == null ? null : p.Profile.Prefix.Name,
|
|
PrefixId = p.Profile.Prefix == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.Profile.Prefix.Id,
|
|
p.Profile.FirstName,
|
|
p.Profile.LastName,
|
|
ProfileId = p.Profile.Id,
|
|
p.Location,
|
|
p.SendDate,
|
|
p.ActiveDate,
|
|
p.Reason,
|
|
p.Status,
|
|
salary = p.AmountOld,
|
|
p.ApproveReason,
|
|
p.RejectReason,
|
|
p.IsActive,
|
|
p.CreatedAt,
|
|
p.PositionTypeOld,
|
|
p.PositionLevelOld,
|
|
p.PositionNumberOld,
|
|
p.OrganizationPositionOld,
|
|
RetirementResignDocs = p.RetirementResignDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
|
|
})
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(GlobalMessages.RetirementResignNotFound, 404);
|
|
|
|
var retirementResignDocs = new List<dynamic>();
|
|
foreach (var doc in data.RetirementResignDocs)
|
|
{
|
|
var _doc = new
|
|
{
|
|
FileName = doc.FileName,
|
|
PathName = await _documentService.ImagesPath(doc.Id)
|
|
};
|
|
retirementResignDocs.Add(_doc);
|
|
}
|
|
var _data = new
|
|
{
|
|
data.Id,
|
|
data.ProfileId,
|
|
data.Prefix,
|
|
data.PrefixId,
|
|
data.FirstName,
|
|
data.LastName,
|
|
data.Location,
|
|
data.SendDate,
|
|
data.ActiveDate,
|
|
data.Reason,
|
|
data.Status,
|
|
data.salary,
|
|
data.PositionTypeOld,
|
|
data.PositionLevelOld,
|
|
data.PositionNumberOld,
|
|
data.OrganizationPositionOld,
|
|
data.ApproveReason,
|
|
data.RejectReason,
|
|
data.IsActive,
|
|
data.CreatedAt,
|
|
Docs = retirementResignDocs,
|
|
};
|
|
|
|
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] RetirementResignRequest 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.KeycloakId == Guid.Parse(UserId));
|
|
if (profile == null)
|
|
return Error(GlobalMessages.DataNotFound, 404);
|
|
|
|
var retirementResign = new RetirementResign
|
|
{
|
|
Profile = profile,
|
|
Location = req.Location,
|
|
SendDate = req.SendDate,
|
|
ActiveDate = req.ActiveDate,
|
|
Reason = req.Reason,
|
|
AmountOld = profile.Salaries.Count() == 0 ? null : profile.Salaries.OrderByDescending(x => x.Order).FirstOrDefault().PositionSalaryAmount,
|
|
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",
|
|
IsActive = true,
|
|
CreatedUserId = FullName ?? "",
|
|
CreatedFullName = UserId ?? "System Administrator",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
await _context.RetirementResigns.AddAsync(retirementResign);
|
|
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 retirementResignDoc = new RetirementResignDoc
|
|
{
|
|
RetirementResign = retirementResign,
|
|
Document = _doc,
|
|
CreatedUserId = FullName ?? "",
|
|
CreatedFullName = UserId ?? "System Administrator",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
await _context.RetirementResignDocs.AddAsync(retirementResignDoc);
|
|
}
|
|
}
|
|
}
|
|
await _context.SaveChangesAsync();
|
|
|
|
return Success(retirementResign);
|
|
}
|
|
|
|
/// <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([FromForm] RetirementResignRequest req, Guid id)
|
|
{
|
|
var updated = await _context.RetirementResigns
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
if (updated == null)
|
|
return Error(GlobalMessages.RetirementResignNotFound, 404);
|
|
|
|
updated.Location = req.Location;
|
|
updated.SendDate = req.SendDate;
|
|
updated.ActiveDate = req.ActiveDate;
|
|
updated.Reason = req.Reason;
|
|
updated.OrganizationPositionOld = req.OrganizationPositionOld;
|
|
updated.PositionTypeOld = req.PositionTypeOld;
|
|
updated.PositionLevelOld = req.PositionLevelOld;
|
|
updated.PositionNumberOld = req.PositionNumberOld;
|
|
updated.AmountOld = req.AmountOld;
|
|
updated.LastUpdateFullName = FullName ?? "System Administrator";
|
|
updated.LastUpdateUserId = UserId ?? "";
|
|
updated.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.RetirementResigns.AsQueryable()
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
if (deleted == null)
|
|
return Error(GlobalMessages.RetirementResignNotFound, 404);
|
|
var retirementResignDocs = new List<dynamic>();
|
|
foreach (var doc in deleted.RetirementResignDocs)
|
|
{
|
|
if (doc.Document != null)
|
|
retirementResignDocs.Add(doc.Document.Id);
|
|
}
|
|
_context.RetirementResignDocs.RemoveRange(deleted.RetirementResignDocs);
|
|
await _context.SaveChangesAsync();
|
|
_context.RetirementResigns.Remove(deleted);
|
|
foreach (var doc in retirementResignDocs)
|
|
{
|
|
if (doc != null)
|
|
await _documentService.DeleteFileAsync(doc);
|
|
}
|
|
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("confirm/{id:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> AdminConfirm([FromBody] RetirementReasonRequest req, Guid id)
|
|
{
|
|
var updated = await _context.RetirementResigns
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
if (updated == null)
|
|
return Error(GlobalMessages.RetirementResignNotFound, 404);
|
|
|
|
updated.Status = "APPROVE";
|
|
updated.ApproveReason = req.Reason;
|
|
updated.LastUpdateFullName = FullName ?? "System Administrator";
|
|
updated.LastUpdateUserId = UserId ?? "";
|
|
updated.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>
|
|
[HttpPut("reject/{id:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> AdminReject([FromBody] RetirementReasonRequest req, Guid id)
|
|
{
|
|
var updated = await _context.RetirementResigns
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
if (updated == null)
|
|
return Error(GlobalMessages.RetirementResignNotFound, 404);
|
|
|
|
updated.Status = "REJECT";
|
|
updated.RejectReason = req.Reason;
|
|
updated.LastUpdateFullName = FullName ?? "System Administrator";
|
|
updated.LastUpdateUserId = UserId ?? "";
|
|
updated.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>
|
|
[HttpPost("report")]
|
|
public async Task<ActionResult<ResponseObject>> PostToReport([FromBody] RetirementProfileRequest req)
|
|
{
|
|
foreach (var item in req.Id)
|
|
{
|
|
var uppdated = await _context.RetirementResigns
|
|
.FirstOrDefaultAsync(x => x.Id == item);
|
|
if (uppdated == null)
|
|
continue;
|
|
uppdated.Status = "REPORT";
|
|
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
|
|
uppdated.LastUpdateUserId = UserId ?? "";
|
|
uppdated.LastUpdatedAt = DateTime.Now;
|
|
}
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
return Success();
|
|
}
|
|
|
|
/// <summary>
|
|
/// list แบบสอบถามหลังลาออก
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
/// <response code="200"></response>
|
|
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
|
|
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
|
|
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
|
|
[HttpGet("questionnaire")]
|
|
public async Task<ActionResult<ResponseObject>> GetListQuestion()
|
|
{
|
|
var data = await _context.RetirementQuestions.AsQueryable()
|
|
.OrderByDescending(x => x.CreatedAt)
|
|
.Select(p => new
|
|
{
|
|
Id = p.Id,
|
|
ReasonWork = p.ReasonWork == null ? p.ReasonWork : Newtonsoft.Json.JsonConvert.DeserializeObject(p.ReasonWork),
|
|
ReasonWorkOther = p.ReasonWorkOther,
|
|
TimeThink = p.TimeThink == null ? p.TimeThink : Newtonsoft.Json.JsonConvert.DeserializeObject(p.TimeThink),
|
|
ExitFactor = p.ExitFactor == null ? p.ExitFactor : Newtonsoft.Json.JsonConvert.DeserializeObject(p.ExitFactor),
|
|
ExitFactorOther = p.ExitFactorOther,
|
|
Adjust = p.Adjust == null ? p.Adjust : Newtonsoft.Json.JsonConvert.DeserializeObject(p.Adjust),
|
|
AdjustOther = p.AdjustOther,
|
|
RealReason = p.RealReason,
|
|
NotExitFactor = p.NotExitFactor,
|
|
Havejob = p.Havejob,
|
|
HavejobReason = p.HavejobReason,
|
|
SuggestFriends = p.SuggestFriends,
|
|
SuggestFriendsReason = p.SuggestFriendsReason,
|
|
FutureWork = p.FutureWork,
|
|
FutureWorkReason = p.FutureWorkReason,
|
|
Suggestion = p.Suggestion,
|
|
LastUpdatedAt = p.LastUpdatedAt,
|
|
CreatedAt = p.CreatedAt,
|
|
})
|
|
.ToListAsync();
|
|
return Success(data);
|
|
}
|
|
|
|
/// <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("questionnaire/{id:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> GetByIdQuestion(Guid id)
|
|
{
|
|
var data = await _context.RetirementQuestions.AsQueryable()
|
|
.Where(x => x.Id == id)
|
|
.Select(p => new
|
|
{
|
|
Id = p.Id,
|
|
ReasonWork = p.ReasonWork == null ? p.ReasonWork : Newtonsoft.Json.JsonConvert.DeserializeObject(p.ReasonWork),
|
|
ReasonWorkOther = p.ReasonWorkOther,
|
|
TimeThink = p.TimeThink == null ? p.TimeThink : Newtonsoft.Json.JsonConvert.DeserializeObject(p.TimeThink),
|
|
ExitFactor = p.ExitFactor == null ? p.ExitFactor : Newtonsoft.Json.JsonConvert.DeserializeObject(p.ExitFactor),
|
|
ExitFactorOther = p.ExitFactorOther,
|
|
Adjust = p.Adjust == null ? p.Adjust : Newtonsoft.Json.JsonConvert.DeserializeObject(p.Adjust),
|
|
AdjustOther = p.AdjustOther,
|
|
RealReason = p.RealReason,
|
|
NotExitFactor = p.NotExitFactor,
|
|
Havejob = p.Havejob,
|
|
HavejobReason = p.HavejobReason,
|
|
SuggestFriends = p.SuggestFriends,
|
|
SuggestFriendsReason = p.SuggestFriendsReason,
|
|
FutureWork = p.FutureWork,
|
|
FutureWorkReason = p.FutureWorkReason,
|
|
Suggestion = p.Suggestion,
|
|
LastUpdatedAt = p.LastUpdatedAt,
|
|
CreatedAt = p.CreatedAt,
|
|
})
|
|
.FirstOrDefaultAsync();
|
|
if (data == null)
|
|
return Error(GlobalMessages.RetirementQuestionNotFound, 404);
|
|
|
|
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("questionnaire")]
|
|
public async Task<ActionResult<ResponseObject>> PostQuestion([FromForm] RetirementQuestionRequest req)
|
|
{
|
|
var retirementResign = await _context.RetirementResigns.AsQueryable()
|
|
.FirstOrDefaultAsync(x => x.Id == req.RetirementResignId);
|
|
if (retirementResign == null)
|
|
return Error(GlobalMessages.RetirementResignNotFound);
|
|
|
|
var period = new RetirementQuestion
|
|
{
|
|
RetirementResign = retirementResign,
|
|
ReasonWork = Newtonsoft.Json.JsonConvert.SerializeObject(req.ReasonWork),
|
|
ReasonWorkOther = req.ReasonWorkOther,
|
|
TimeThink = Newtonsoft.Json.JsonConvert.SerializeObject(req.TimeThink),
|
|
ExitFactor = Newtonsoft.Json.JsonConvert.SerializeObject(req.ExitFactor),
|
|
ExitFactorOther = req.ExitFactorOther,
|
|
Adjust = Newtonsoft.Json.JsonConvert.SerializeObject(req.Adjust),
|
|
AdjustOther = req.AdjustOther,
|
|
RealReason = req.RealReason,
|
|
NotExitFactor = req.NotExitFactor,
|
|
Havejob = req.Havejob,
|
|
HavejobReason = req.HavejobReason,
|
|
SuggestFriends = req.SuggestFriends,
|
|
SuggestFriendsReason = req.SuggestFriendsReason,
|
|
FutureWork = req.FutureWork,
|
|
FutureWorkReason = req.FutureWorkReason,
|
|
Suggestion = req.Suggestion,
|
|
CreatedUserId = FullName ?? "",
|
|
CreatedFullName = UserId ?? "System Administrator",
|
|
CreatedAt = DateTime.Now,
|
|
LastUpdateFullName = FullName ?? "System Administrator",
|
|
LastUpdateUserId = UserId ?? "",
|
|
LastUpdatedAt = DateTime.Now,
|
|
};
|
|
await _context.RetirementQuestions.AddAsync(period);
|
|
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("questionnaire/{id:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> DeleteQuestion(Guid id)
|
|
{
|
|
var deleted = await _context.RetirementQuestions.AsQueryable()
|
|
.Where(x => x.Id == id)
|
|
.FirstOrDefaultAsync();
|
|
|
|
if (deleted == null)
|
|
return Error(GlobalMessages.RetirementQuestionNotFound);
|
|
_context.RetirementQuestions.Remove(deleted);
|
|
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("questionnaire/{id:length(36)}")]
|
|
public async Task<ActionResult<ResponseObject>> PutQuestion([FromForm] RetirementQuestionRequest req, Guid id)
|
|
{
|
|
var uppdated = await _context.RetirementQuestions.AsQueryable()
|
|
.FirstOrDefaultAsync(x => x.Id == id);
|
|
if (uppdated == null)
|
|
return Error(GlobalMessages.RetirementQuestionNotFound);
|
|
|
|
var retirementResign = await _context.RetirementResigns.AsQueryable()
|
|
.FirstOrDefaultAsync(x => x.Id == req.RetirementResignId);
|
|
if (retirementResign == null)
|
|
return Error(GlobalMessages.InsigniaNotFound);
|
|
|
|
// uppdated.RetirementResign = retirementResign;
|
|
uppdated.ReasonWork = Newtonsoft.Json.JsonConvert.SerializeObject(req.ReasonWork);
|
|
uppdated.ReasonWorkOther = req.ReasonWorkOther;
|
|
uppdated.TimeThink = Newtonsoft.Json.JsonConvert.SerializeObject(req.TimeThink);
|
|
uppdated.ExitFactor = Newtonsoft.Json.JsonConvert.SerializeObject(req.ExitFactor);
|
|
uppdated.ExitFactorOther = req.ExitFactorOther;
|
|
uppdated.Adjust = Newtonsoft.Json.JsonConvert.SerializeObject(req.Adjust);
|
|
uppdated.AdjustOther = req.AdjustOther;
|
|
uppdated.RealReason = req.RealReason;
|
|
uppdated.NotExitFactor = req.NotExitFactor;
|
|
uppdated.Havejob = req.Havejob;
|
|
uppdated.HavejobReason = req.HavejobReason;
|
|
uppdated.SuggestFriends = req.SuggestFriends;
|
|
uppdated.SuggestFriendsReason = req.SuggestFriendsReason;
|
|
uppdated.FutureWork = req.FutureWork;
|
|
uppdated.FutureWorkReason = req.FutureWorkReason;
|
|
uppdated.Suggestion = req.Suggestion;
|
|
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
|
|
uppdated.LastUpdateUserId = UserId ?? "";
|
|
uppdated.LastUpdatedAt = DateTime.Now;
|
|
|
|
await _context.SaveChangesAsync();
|
|
|
|
return Success();
|
|
}
|
|
}
|
|
}
|