แก้apiประวัติศิกษาบรรจุ

This commit is contained in:
Kittapath 2023-07-13 19:37:19 +07:00
parent dcc1dd9666
commit 8c50baaf5f

View file

@ -793,8 +793,8 @@ namespace BMA.EHR.Placement.Service.Controllers
return Success(); return Success();
} }
[HttpPut("certificate/{personalId:length(36)}")] [HttpPost("certificate/{personalId:length(36)}")]
public async Task<ActionResult<ResponseObject>> UpdateCertificate([FromBody] PersonCertificateRequest req, Guid personalId) public async Task<ActionResult<ResponseObject>> CreateCertificate([FromBody] PersonCertificateRequest req, Guid personalId)
{ {
var person = await _context.PlacementProfiles var person = await _context.PlacementProfiles
.Include(x => x.PlacementCertificates) .Include(x => x.PlacementCertificates)
@ -802,8 +802,6 @@ namespace BMA.EHR.Placement.Service.Controllers
if (person == null) if (person == null)
return Error(GlobalMessages.DataNotFound, 404); return Error(GlobalMessages.DataNotFound, 404);
if (req.Id == null)
{
var data = new PlacementCertificate var data = new PlacementCertificate
{ {
PlacementProfile = person, PlacementProfile = person,
@ -820,9 +818,20 @@ namespace BMA.EHR.Placement.Service.Controllers
LastUpdatedAt = DateTime.Now, LastUpdatedAt = DateTime.Now,
}; };
await _context.PlacementCertificates.AddAsync(data); await _context.PlacementCertificates.AddAsync(data);
_context.SaveChanges();
return Success();
} }
else
[HttpPut("certificate/{personalId:length(36)}")]
public async Task<ActionResult<ResponseObject>> UpdateCertificate([FromBody] PersonCertificateRequest req, Guid personalId)
{ {
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 == req.Id); var certificate = person.PlacementCertificates.FirstOrDefault(x => x.Id == req.Id);
if (certificate == null) if (certificate == null)
return Error(GlobalMessages.CertificateNotFound, 404); return Error(GlobalMessages.CertificateNotFound, 404);
@ -834,7 +843,6 @@ namespace BMA.EHR.Placement.Service.Controllers
certificate.LastUpdateFullName = FullName ?? "System Administrator"; certificate.LastUpdateFullName = FullName ?? "System Administrator";
certificate.LastUpdateUserId = UserId ?? ""; certificate.LastUpdateUserId = UserId ?? "";
certificate.LastUpdatedAt = DateTime.Now; certificate.LastUpdatedAt = DateTime.Now;
}
_context.SaveChanges(); _context.SaveChanges();
return Success(); return Success();
@ -857,12 +865,9 @@ namespace BMA.EHR.Placement.Service.Controllers
return Success(); return Success();
} }
[HttpPut("education/{personalId:length(36)}")] [HttpPost("education/{personalId:length(36)}")]
public async Task<ActionResult<ResponseObject>> UpdateEducation([FromBody] PersonEducationRequest req, Guid personalId) public async Task<ActionResult<ResponseObject>> CreateEducation([FromBody] PersonEducationRequest req, Guid personalId)
{ {
// var education = await _context.PlacementEducations
// .Include(x => x.PlacementProfile)
// .FirstOrDefaultAsync(x => x.Id == personalId);
var profile = await _context.PlacementProfiles.FirstOrDefaultAsync(x => x.Id == personalId); var profile = await _context.PlacementProfiles.FirstOrDefaultAsync(x => x.Id == personalId);
if (profile == null) if (profile == null)
return Error(GlobalMessages.DataNotFound, 404); return Error(GlobalMessages.DataNotFound, 404);
@ -875,8 +880,6 @@ namespace BMA.EHR.Placement.Service.Controllers
if (positionPath == null && req.PositionPathId != null) if (positionPath == null && req.PositionPathId != null)
return Error(GlobalMessages.DataNotFound, 404); return Error(GlobalMessages.DataNotFound, 404);
if (req.Id == null)
{
var data = new PlacementEducation var data = new PlacementEducation
{ {
PlacementProfile = profile, PlacementProfile = profile,
@ -902,9 +905,25 @@ namespace BMA.EHR.Placement.Service.Controllers
LastUpdatedAt = DateTime.Now, LastUpdatedAt = DateTime.Now,
}; };
await _context.PlacementEducations.AddAsync(data); await _context.PlacementEducations.AddAsync(data);
await _context.SaveChangesAsync();
return Success();
} }
else
[HttpPut("education/{personalId:length(36)}")]
public async Task<ActionResult<ResponseObject>> UpdateEducation([FromBody] PersonEducationRequest req, Guid personalId)
{ {
var profile = await _context.PlacementProfiles.FirstOrDefaultAsync(x => x.Id == personalId);
if (profile == null)
return Error(GlobalMessages.DataNotFound, 404);
var educationLevel = await _context.EducationLevels.FirstOrDefaultAsync(x => x.Id == req.EducationLevelId);
if (educationLevel == null && req.EducationLevelId != null)
return Error(GlobalMessages.DataNotFound, 404);
var positionPath = await _context.PositionPaths.FirstOrDefaultAsync(x => x.Id == req.PositionPathId);
if (positionPath == null && req.PositionPathId != null)
return Error(GlobalMessages.DataNotFound, 404);
var education = await _context.PlacementEducations.FirstOrDefaultAsync(x => x.Id == req.Id); var education = await _context.PlacementEducations.FirstOrDefaultAsync(x => x.Id == req.Id);
if (education == null) if (education == null)
return Error(GlobalMessages.EducationNotFound, 404); return Error(GlobalMessages.EducationNotFound, 404);
@ -926,7 +945,6 @@ namespace BMA.EHR.Placement.Service.Controllers
education.LastUpdateFullName = FullName ?? "System Administrator"; education.LastUpdateFullName = FullName ?? "System Administrator";
education.LastUpdateUserId = UserId ?? ""; education.LastUpdateUserId = UserId ?? "";
education.LastUpdatedAt = DateTime.Now; education.LastUpdatedAt = DateTime.Now;
}
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
return Success(); return Success();
} }