ลบรับโอน ขอโอน

This commit is contained in:
Kittapath 2023-08-05 17:53:07 +07:00
parent c56e3b06b9
commit 61ddd26c0e
11 changed files with 26700 additions and 175 deletions

View file

@ -15,7 +15,7 @@ using System.Security.Cryptography;
namespace BMA.EHR.Placement.Service.Controllers
{
[Route("api/v{version:apiVersion}/placement/receive")]
[Route("api/v{version:apiVersion}/placement/Receive")]
[ApiVersion("1.0")]
[ApiController]
[Produces("application/json")]
@ -50,119 +50,167 @@ namespace BMA.EHR.Placement.Service.Controllers
#endregion
/// <summary>
/// list รอบเครื่องราช
/// list รายการรับโอน
/// </summary>
/// <param name="type">ประเภทเครื่องราช(insignia=เครื่องราช,coin=เหรียญ)</param>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("{type}")]
public async Task<ActionResult<ResponseObject>> GetList(string type)
[HttpGet()]
public async Task<ActionResult<ResponseObject>> GetListByAdmin()
{
var insigniaPeriods = await _context.InsigniaPeriods.AsQueryable()
.Where(x => x.Type == type)
.OrderByDescending(x => x.Year)
.ThenByDescending(x => x.StartDate)
var placementReceives = await _context.PlacementReceives.AsQueryable()
.OrderByDescending(x => x.CreatedAt)
.Select(p => new
{
period_id = p.Id,
period_amount = p.Amount,
period_name = p.Name,
period_start = p.StartDate,
period_end = p.EndDate,
period_year = p.Year,
period_doc = p.ReliefDoc == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.ReliefDoc.Id,
p.Id,
p.CitizenId,
Prefix = p.Prefix.Name,
p.Firstname,
p.Lastname,
p.DateOfBirth,
Gender = p.Gender == null ? null : p.Gender.Name,
p.Status,
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,
p.IsActive,
p.CreatedAt,
})
.ToListAsync();
var data = new List<dynamic>();
foreach (var insigniaPeriod in insigniaPeriods)
{
var _data = new
{
period_id = insigniaPeriod.period_id,
period_amount = insigniaPeriod.period_amount,
period_name = insigniaPeriod.period_name,
period_start = insigniaPeriod.period_start,
period_end = insigniaPeriod.period_end,
period_year = insigniaPeriod.period_year,
period_doc = insigniaPeriod.period_doc == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(insigniaPeriod.period_doc),
};
data.Add(_data);
}
if (PlacementAdmin == true)
placementReceives.Where(x => x.Status.Trim().ToUpper().Contains("DONE"));
return Success(data);
return Success(placementReceives);
}
/// <summary>
/// get รายละเอียดรอบเครื่องราช
/// get รายละเอียดรับโอน
/// </summary>
/// <param name="id">Id เครื่องราช</param>
/// <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>> GetById(Guid id)
public async Task<ActionResult<ResponseObject>> GetDetailByUser(Guid id)
{
var data = await _context.InsigniaPeriods.AsQueryable()
var data = await _context.PlacementReceives.AsQueryable()
.Where(x => x.Id == id)
.Select(p => new
{
period_id = p.Id,
period_amount = p.Amount,
period_name = p.Name,
period_start = p.StartDate,
period_end = p.EndDate,
period_year = p.Year,
period_doc = p.ReliefDoc == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.ReliefDoc.Id,
p.Id,
p.CitizenId,
Prefix = 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.RecruitDate,
PositionNumber = p.PositionNumber == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionNumber.Id,
PositionPath = p.PositionPath == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionPath.Id,
PositionPathSide = p.PositionPathSide == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionPathSide.Id,
PositionType = p.PositionType == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionType.Id,
PositionLine = p.PositionLine == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionLine.Id,
PositionLevel = p.PositionLevel == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.PositionLevel.Id,
OrganizationPosition = p.OrganizationPosition == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.OrganizationPosition.Id,
p.CreatedAt,
PlacementReceiveDocs = p.PlacementReceiveDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
})
.FirstOrDefaultAsync();
if (data == null)
return Error(GlobalMessages.DataNotFound, 404);
var placementReceiveDocs = new List<dynamic>();
foreach (var doc in data.PlacementReceiveDocs)
{
var _doc = new
{
doc.FileName,
PathName = await _documentService.ImagesPath(doc.Id)
};
placementReceiveDocs.Add(_doc);
}
var _data = new
{
period_id = data.period_id,
period_amount = data.period_amount,
period_name = data.period_name,
period_start = data.period_start,
period_end = data.period_end,
period_year = data.period_year,
period_doc = data.period_doc == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.period_doc),
data.Id,
data.CitizenId,
data.Prefix,
data.Firstname,
data.Lastname,
data.DateOfBirth,
data.Gender,
data.Nationality,
data.Race,
data.Religion,
data.BloodGroup,
data.Relationship,
data.TelephoneNumber,
data.Status,
data.RecruitDate,
data.PositionNumber,
data.PositionPath,
data.PositionPathSide,
data.PositionType,
data.PositionLine,
data.PositionLevel,
data.OrganizationPosition,
data.CreatedAt,
Docs = placementReceiveDocs,
};
return Success(_data);
}
/// <summary>
/// สร้างรอบเครื่องราช
/// สร้างรับโอน
/// </summary>
/// <param name="type">ประเภทเครื่องราช(insignia=เครื่องราช,coin=เหรียญ)</param>
/// <param name="req.Name">ชื่อรอบ</param>
/// <param name="req.Year">ปีที่เสนอ</param>
/// <param name="req.StartDate">วันที่เริ่มต้น</param>
/// <param name="req.EndDate">วันที่สิ้นสุด</param>
/// <param name="req.Amount">จำนวนวันแจ้งเตือน</param>
/// <param name="req.File">เอกสารประกอบ</param>
/// <returns></returns>
/// <response code="200"></response>
/// <response code="400">ค่าตัวแปรที่ส่งมาไม่ถูกต้อง</response>
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpPost("{type}")]
public async Task<ActionResult<ResponseObject>> Post([FromForm] InsigniaPeriodRequest req, string type)
[HttpPost()]
public async Task<ActionResult<ResponseObject>> Post([FromForm] PlacementReceiveRequest req)
{
var period = new InsigniaPeriod
var profile = await _context.Profiles
.FirstOrDefaultAsync(x => x.KeycloakId == Guid.Parse(UserId));
if (profile == null)
return Error(GlobalMessages.DataNotFound, 404);
var prefix = await _context.Prefixes.FindAsync(req.Prefix);
if (prefix == null)
return Error(GlobalMessages.PrefixNotFound, 404);
var placementReceive = new PlacementReceive
{
Name = Request.Form.ContainsKey("Name") ? Request.Form["Name"] : "",
Year = Request.Form.ContainsKey("Year") ? Int32.Parse(Request.Form["Year"]) : DateTime.Now.Year,
StartDate = Request.Form.ContainsKey("StartDate") ? DateTime.Parse(Request.Form["StartDate"]) : DateTime.Now,
EndDate = Request.Form.ContainsKey("EndDate") ? DateTime.Parse(Request.Form["EndDate"]) : DateTime.Now,
Amount = Request.Form.ContainsKey("Amount") ? Request.Form["Amount"] : "",
Type = type.Trim().ToUpper(),
CitizenId = req.CitizenId,
Prefix = prefix,
Firstname = req.Firstname,
Lastname = req.Lastname,
DateOfBirth = req.DateOfBirth,
Gender = await _context.Genders.FindAsync(req.Gender),
Nationality = req.Nationality,
Race = req.Race,
Religion = await _context.Religions.FindAsync(req.Religion),
BloodGroup = await _context.BloodGroups.FindAsync(req.BloodGroup),
Relationship = await _context.Relationships.FindAsync(req.Relationship),
TelephoneNumber = req.TelephoneNumber,
Status = "PENDING",
CreatedUserId = FullName ?? "",
CreatedFullName = UserId ?? "System Administrator",
CreatedAt = DateTime.Now,
@ -170,27 +218,153 @@ namespace BMA.EHR.Placement.Service.Controllers
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
await _context.InsigniaPeriods.AddAsync(period);
await _context.PlacementReceives.AddAsync(placementReceive);
await _context.SaveChangesAsync();
if (Request.Form.Files != null && Request.Form.Files.Count != 0)
{
var file = Request.Form.Files[0];
var fileExtension = Path.GetExtension(file.FileName);
foreach (var file in Request.Form.Files)
{
var fileExtension = Path.GetExtension(file.FileName);
var doc = await _documentService.UploadFileAsync(file, file.FileName);
period.ReliefDoc = doc;
var doc = await _documentService.UploadFileAsync(file, file.FileName);
var _doc = await _context.Documents.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == doc.Id);
if (_doc != null)
{
var placementReceiveDoc = new PlacementReceiveDoc
{
PlacementReceive = placementReceive,
Document = _doc,
CreatedUserId = FullName ?? "",
CreatedFullName = UserId ?? "System Administrator",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
await _context.PlacementReceiveDocs.AddAsync(placementReceiveDoc);
}
}
}
// await _context.InsigniaPeriods.AddAsync(period);
await _context.SaveChangesAsync();
return Success();
}
/// <summary>
/// ลบรอบเครื่องราช
/// เลือกหน่วยงาน
/// </summary>
/// <param name="id">Id เครื่องราช</param>
/// <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>> UpdatePositionPlacementReceive([FromBody] PersonSelectPositionReceiveRequest req, Guid id)
{
var uppdated = await _context.PlacementReceives
.FirstOrDefaultAsync(x => x.Id == id);
if (uppdated == null)
return Error(GlobalMessages.PlacementReceiveNotFound, 404);
var organization = await _context.Organizations
.FirstOrDefaultAsync(x => x.Id == id);
if (organization == null)
return Error(GlobalMessages.OrganizationNotFound, 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.RecruitDate = req.RecruitDate;
uppdated.Status = "DONE";
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
uppdated.LastUpdateUserId = UserId ?? "";
uppdated.LastUpdatedAt = DateTime.Now;
await _context.SaveChangesAsync();
return Success();
}
// /// <summary>
// /// View หน่วยงาน
// /// </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("position/{id:length(36)}")]
// public async Task<ActionResult<ResponseObject>> GetPositionPlacementReceive(Guid id)
// {
// var uppdated = await _context.PlacementReceives
// .FirstOrDefaultAsync(x => x.Id == id);
// if (uppdated == null)
// return Error(GlobalMessages.PlacementReceiveNotFound, 404);
// uppdated.Status = "DONE";
// 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>
@ -199,73 +373,29 @@ namespace BMA.EHR.Placement.Service.Controllers
[HttpDelete("{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> Delete(Guid id)
{
var deleted = await _context.InsigniaPeriods.AsQueryable()
.Include(x => x.ReliefDoc)
var deleted = await _context.PlacementReceives.AsQueryable()
.Include(x => x.PlacementReceiveDocs)
.ThenInclude(x => x.Document)
.FirstOrDefaultAsync(x => x.Id == id);
if (deleted == null)
return NotFound();
_context.InsigniaPeriods.Remove(deleted);
await _context.SaveChangesAsync();
if (deleted.ReliefDoc != null)
await _documentService.DeleteFileAsync(deleted.ReliefDoc.Id);
return Success();
}
/// <summary>
/// แก้ไขรอบเครื่องราช
/// </summary>
/// <param name="id">Id เครื่องราช</param>
/// <param name="req.Name">ชื่อรอบ</param>
/// <param name="req.Year">ปีที่เสนอ</param>
/// <param name="req.StartDate">วันที่เริ่มต้น</param>
/// <param name="req.EndDate">วันที่สิ้นสุด</param>
/// <param name="req.Amount">จำนวนวันแจ้งเตือน</param>
/// <param name="req.File">เอกสารประกอบ</param>
/// <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] InsigniaPeriodRequest req, Guid id)
{
if (req == null)
return BadRequest();
var uppdated = await _context.InsigniaPeriods.AsQueryable()
.Include(x => x.ReliefDoc)
.FirstOrDefaultAsync(x => x.Id == id);
if (uppdated == null)
return NotFound();
uppdated.Name = Request.Form.ContainsKey("Name") ? Request.Form["Name"] : "";
uppdated.Year = Request.Form.ContainsKey("Year") ? Int32.Parse(Request.Form["Year"]) : DateTime.Now.Year;
uppdated.StartDate = Request.Form.ContainsKey("StartDate") ? DateTime.Parse(Request.Form["StartDate"]) : DateTime.Now;
uppdated.EndDate = Request.Form.ContainsKey("EndDate") ? DateTime.Parse(Request.Form["EndDate"]) : DateTime.Now;
uppdated.Amount = Request.Form.ContainsKey("Amount") ? Request.Form["Amount"] : "";
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
uppdated.LastUpdateUserId = UserId ?? "";
uppdated.LastUpdatedAt = DateTime.Now;
if (Request.Form.Files != null && Request.Form.Files.Count != 0)
var placementReceiveDocs = new List<dynamic>();
foreach (var doc in deleted.PlacementReceiveDocs)
{
if (uppdated.ReliefDoc != null)
await _documentService.DeleteFileAsync(uppdated.ReliefDoc.Id);
var file = Request.Form.Files[0];
var fileExtension = Path.GetExtension(file.FileName);
var doc = await _documentService.UploadFileAsync(file, file.FileName);
uppdated.ReliefDoc = doc;
if (doc.Document != null)
placementReceiveDocs.Add(doc.Document.Id);
}
_context.PlacementReceiveDocs.RemoveRange(deleted.PlacementReceiveDocs);
await _context.SaveChangesAsync();
_context.PlacementReceives.Remove(deleted);
foreach (var doc in placementReceiveDocs)
{
if (doc != null)
await _documentService.DeleteFileAsync(doc);
}
await _context.SaveChangesAsync();
return Success();
}
}
}

View file

@ -50,7 +50,7 @@ namespace BMA.EHR.Placement.Service.Controllers
#endregion
/// <summary>
/// list คำขอโอนของ User
/// list รายการคำขอโอนของ User
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
@ -67,6 +67,7 @@ namespace BMA.EHR.Placement.Service.Controllers
var placementTransfers = await _context.PlacementTransfers.AsQueryable()
.Where(x => x.Profile == profile)
.OrderByDescending(x => x.CreatedAt)
.Select(p => new
{
p.Id,
@ -86,7 +87,7 @@ namespace BMA.EHR.Placement.Service.Controllers
}
/// <summary>
/// list คำขอโอนของ Admin
/// list รายการคำขอโอนของ Admin
/// </summary>
/// <returns></returns>
/// <response code="200"></response>
@ -98,6 +99,7 @@ namespace BMA.EHR.Placement.Service.Controllers
{
var placementTransfers = await _context.PlacementTransfers.AsQueryable()
.OrderByDescending(x => x.CreatedAt)
.Select(p => new
{
p.Id,
@ -112,6 +114,8 @@ namespace BMA.EHR.Placement.Service.Controllers
p.IsActive,
})
.ToListAsync();
if (PlacementAdmin == true)
placementTransfers.Where(x => x.Status.Trim().ToUpper().Contains("DONE"));
return Success(placementTransfers);
}
@ -142,12 +146,22 @@ namespace BMA.EHR.Placement.Service.Controllers
Status = p.Status,
Organization = p.Organization,
CreatedAt = p.CreatedAt,
// doc = p.ReliefDoc == null ? Guid.Parse("00000000-0000-0000-0000-000000000000") : p.ReliefDoc.Id,
PlacementTransferDocs = p.PlacementTransferDocs.Where(d => d.Document != null).Select(d => new { d.Document.Id, d.Document.FileName }),
})
.FirstOrDefaultAsync();
if (data == null)
return Error(GlobalMessages.DataNotFound, 404)
return Error(GlobalMessages.DataNotFound, 404);
var placementTransferDocs = new List<dynamic>();
foreach (var doc in data.PlacementTransferDocs)
{
var _doc = new
{
FileName = doc.FileName,
PathName = await _documentService.ImagesPath(doc.Id)
};
placementTransferDocs.Add(_doc);
}
var _data = new
{
Id = data.Id,
@ -155,7 +169,7 @@ namespace BMA.EHR.Placement.Service.Controllers
Status = data.Status,
Organization = data.Organization,
CreatedAt = data.CreatedAt,
// period_doc = data.period_doc == Guid.Parse("00000000-0000-0000-0000-000000000000") ? null : await _documentService.ImagesPath(data.period_doc),
Docs = placementTransferDocs,
};
return Success(_data);
@ -199,18 +213,24 @@ namespace BMA.EHR.Placement.Service.Controllers
var fileExtension = Path.GetExtension(file.FileName);
var doc = await _documentService.UploadFileAsync(file, file.FileName);
var placementTransferDoc = new PlacementTransferDoc
var _doc = await _context.Documents.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == doc.Id);
if (_doc != null)
{
PlacementTransfer = placementTransfer,
Document = doc,
CreatedUserId = FullName ?? "",
CreatedFullName = UserId ?? "System Administrator",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
await _context.PlacementTransferDocs.AddAsync(placementTransferDoc);
var placementTransferDoc = new PlacementTransferDoc
{
PlacementTransfer = placementTransfer,
Document = _doc,
CreatedUserId = FullName ?? "",
CreatedFullName = UserId ?? "System Administrator",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
await _context.PlacementTransferDocs.AddAsync(placementTransferDoc);
}
}
}
await _context.SaveChangesAsync();
@ -219,7 +239,7 @@ namespace BMA.EHR.Placement.Service.Controllers
}
/// <summary>
/// แก้ไขคำขอโอน
/// อนุมัติคำขอโอน
/// </summary>
/// <param name="id">Id คำขอโอน</param>
/// <returns></returns>
@ -228,38 +248,54 @@ namespace BMA.EHR.Placement.Service.Controllers
/// <response code="401">ไม่ได้ Login เข้าระบบ</response>
/// <response code="500">เมื่อเกิดข้อผิดพลาดในการทำงาน</response>
[HttpGet("confirm/{id:length(36)}")]
public async Task<ActionResult<ResponseObject>> Confirm(Guid id)
public async Task<ActionResult<ResponseObject>> AdminConfirm(Guid id)
{
if (req == null)
return BadRequest();
var uppdated = await _context.InsigniaPeriods.AsQueryable()
.Include(x => x.ReliefDoc)
var uppdated = await _context.PlacementTransfers
.FirstOrDefaultAsync(x => x.Id == id);
if (uppdated == null)
return NotFound();
return Error(GlobalMessages.PlacementTransferNotFound, 404);
uppdated.Name = Request.Form.ContainsKey("Name") ? Request.Form["Name"] : "";
uppdated.Year = Request.Form.ContainsKey("Year") ? Int32.Parse(Request.Form["Year"]) : DateTime.Now.Year;
uppdated.StartDate = Request.Form.ContainsKey("StartDate") ? DateTime.Parse(Request.Form["StartDate"]) : DateTime.Now;
uppdated.EndDate = Request.Form.ContainsKey("EndDate") ? DateTime.Parse(Request.Form["EndDate"]) : DateTime.Now;
uppdated.Amount = Request.Form.ContainsKey("Amount") ? Request.Form["Amount"] : "";
uppdated.Status = "DONE";
uppdated.LastUpdateFullName = FullName ?? "System Administrator";
uppdated.LastUpdateUserId = UserId ?? "";
uppdated.LastUpdatedAt = DateTime.Now;
await _context.SaveChangesAsync();
if (Request.Form.Files != null && Request.Form.Files.Count != 0)
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.PlacementTransfers.AsQueryable()
.Include(x => x.PlacementTransferDocs)
.ThenInclude(x => x.Document)
.FirstOrDefaultAsync(x => x.Id == id);
if (deleted == null)
return NotFound();
var placementTransferDocs = new List<dynamic>();
foreach (var doc in deleted.PlacementTransferDocs)
{
if (uppdated.ReliefDoc != null)
await _documentService.DeleteFileAsync(uppdated.ReliefDoc.Id);
var file = Request.Form.Files[0];
var fileExtension = Path.GetExtension(file.FileName);
var doc = await _documentService.UploadFileAsync(file, file.FileName);
uppdated.ReliefDoc = doc;
if (doc.Document != null)
placementTransferDocs.Add(doc.Document.Id);
}
_context.PlacementTransferDocs.RemoveRange(deleted.PlacementTransferDocs);
await _context.SaveChangesAsync();
_context.PlacementTransfers.Remove(deleted);
foreach (var doc in placementTransferDocs)
{
if (doc != null)
await _documentService.DeleteFileAsync(doc);
}
await _context.SaveChangesAsync();
return Success();

View file

@ -0,0 +1,16 @@
using BMA.EHR.Domain.Models.MetaData;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Placement.Service.Requests
{
public class PersonSelectPositionReceiveRequest
{
public DateTime? RecruitDate { get; set; }
public Guid? PosNoId { get; set; }
public Guid? PositionId { get; set; }
public Guid? PositionLevelId { get; set; }
public Guid? PositionLineId { get; set; }
public Guid? PositionPathSideId { get; set; }
public Guid? PositionTypeId { get; set; }
}
}

View file

@ -0,0 +1,22 @@
using Microsoft.AspNetCore.Http;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Placement.Service.Requests
{
public class PlacementReceiveRequest
{
public string CitizenId { get; set; }
public Guid Prefix { get; set; }
public string Firstname { get; set; }
public string Lastname { get; set; }
public DateTime DateOfBirth { get; set; }
public Guid? Gender { get; set; }
public string? Nationality { get; set; }
public string? Race { get; set; }
public Guid? Religion { get; set; }
public Guid? BloodGroup { get; set; }
public Guid? Relationship { get; set; }
public string? TelephoneNumber { get; set; }
public List<FormFile>? File { get; set; }
}
}