api ใบประกอบวิชาชีพ
This commit is contained in:
parent
e4fa2ff1c1
commit
0a626fb393
8 changed files with 104 additions and 55 deletions
|
|
@ -1,5 +1,6 @@
|
|||
using BMA.EHR.Application.Repositories;
|
||||
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;
|
||||
|
|
@ -541,16 +542,64 @@ namespace BMA.EHR.Placement.Service.Controllers
|
|||
return Success();
|
||||
}
|
||||
|
||||
[HttpGet("certificate/{personalId:length(36)}")]
|
||||
[HttpPut("certificate/{personalId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> UpdateCertificate([FromBody] PersonCertificateRequest req, Guid personalId)
|
||||
{
|
||||
var person = await _context.PlacementProfiles.FindAsync(personalId);
|
||||
var person = await _context.PlacementProfiles
|
||||
.Include(x => x.PlacementCertificates)
|
||||
.FirstOrDefaultAsync(x => x.Id == personalId);
|
||||
if (person == null)
|
||||
return Error(GlobalMessages.DataNotFound, 404);
|
||||
|
||||
person.LastUpdateFullName = FullName ?? "System Administrator";
|
||||
person.LastUpdateUserId = UserId ?? "";
|
||||
person.LastUpdatedAt = DateTime.Now;
|
||||
if (req.Id == null)
|
||||
{
|
||||
var data = new PlacementCertificate
|
||||
{
|
||||
PlacementProfile = person,
|
||||
CertificateNo = req.CertificateNo,
|
||||
Issuer = req.Issuer,
|
||||
IssueDate = req.IssueDate,
|
||||
ExpireDate = req.ExpireDate,
|
||||
CertificateType = req.CertificateType,
|
||||
CreatedUserId = FullName ?? "",
|
||||
CreatedFullName = UserId ?? "System Administrator",
|
||||
CreatedAt = DateTime.Now,
|
||||
LastUpdateFullName = FullName ?? "System Administrator",
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
var certificate = person.PlacementCertificates.FirstOrDefault(x => x.Id == req.Id);
|
||||
if (certificate == null)
|
||||
return Error(GlobalMessages.CertificateNotFound, 404);
|
||||
certificate.CertificateNo = req.CertificateNo;
|
||||
certificate.Issuer = req.Issuer;
|
||||
certificate.IssueDate = req.IssueDate;
|
||||
certificate.ExpireDate = req.ExpireDate;
|
||||
certificate.CertificateType = req.CertificateType;
|
||||
certificate.LastUpdateFullName = FullName ?? "System Administrator";
|
||||
certificate.LastUpdateUserId = UserId ?? "";
|
||||
certificate.LastUpdatedAt = DateTime.Now;
|
||||
}
|
||||
_context.SaveChanges();
|
||||
|
||||
return Success();
|
||||
}
|
||||
|
||||
[HttpDelete("certificate/{personalId:length(36)}/{certificateId:length(36)}")]
|
||||
public async Task<ActionResult<ResponseObject>> DeleteCertificate(Guid personalId, Guid certificateId)
|
||||
{
|
||||
var person = await _context.PlacementProfiles
|
||||
.Include(x => x.PlacementCertificates)
|
||||
.FirstOrDefaultAsync(x => x.Id == personalId);
|
||||
if (person == null)
|
||||
return Error(GlobalMessages.DataNotFound, 404);
|
||||
var certificate = person.PlacementCertificates.FirstOrDefault(x => x.Id == certificateId);
|
||||
if (certificate == null)
|
||||
return Error(GlobalMessages.CertificateNotFound, 404);
|
||||
_context.PlacementCertificates.Remove(certificate);
|
||||
_context.SaveChanges();
|
||||
|
||||
return Success();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue