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

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

View file

@ -793,6 +793,36 @@ namespace BMA.EHR.Placement.Service.Controllers
return Success(); return Success();
} }
[HttpPost("certificate/{personalId:length(36)}")]
public async Task<ActionResult<ResponseObject>> CreateCertificate([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 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,
};
await _context.PlacementCertificates.AddAsync(data);
_context.SaveChanges();
return Success();
}
[HttpPut("certificate/{personalId:length(36)}")] [HttpPut("certificate/{personalId:length(36)}")]
public async Task<ActionResult<ResponseObject>> UpdateCertificate([FromBody] PersonCertificateRequest req, Guid personalId) public async Task<ActionResult<ResponseObject>> UpdateCertificate([FromBody] PersonCertificateRequest req, Guid personalId)
{ {
@ -802,39 +832,17 @@ 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 certificate = person.PlacementCertificates.FirstOrDefault(x => x.Id == req.Id);
{ if (certificate == null)
var data = new PlacementCertificate return Error(GlobalMessages.CertificateNotFound, 404);
{ certificate.CertificateNo = req.CertificateNo;
PlacementProfile = person, certificate.Issuer = req.Issuer;
CertificateNo = req.CertificateNo, certificate.IssueDate = req.IssueDate;
Issuer = req.Issuer, certificate.ExpireDate = req.ExpireDate;
IssueDate = req.IssueDate, certificate.CertificateType = req.CertificateType;
ExpireDate = req.ExpireDate, certificate.LastUpdateFullName = FullName ?? "System Administrator";
CertificateType = req.CertificateType, certificate.LastUpdateUserId = UserId ?? "";
CreatedUserId = FullName ?? "", certificate.LastUpdatedAt = DateTime.Now;
CreatedFullName = UserId ?? "System Administrator",
CreatedAt = DateTime.Now,
LastUpdateFullName = FullName ?? "System Administrator",
LastUpdateUserId = UserId ?? "",
LastUpdatedAt = DateTime.Now,
};
await _context.PlacementCertificates.AddAsync(data);
}
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(); _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,58 +880,71 @@ 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,
{ EducationLevel = educationLevel,
PlacementProfile = profile, PositionPath = positionPath,
EducationLevel = educationLevel, Institute = req.Institute,
PositionPath = positionPath, Degree = req.Degree,
Institute = req.Institute, Field = req.Field,
Degree = req.Degree, Gpa = req.Gpa,
Field = req.Field, Country = req.Country,
Gpa = req.Gpa, Duration = req.Duration,
Country = req.Country, DurationYear = req.DurationYear,
Duration = req.Duration, Other = req.Other,
DurationYear = req.DurationYear, FundName = req.FundName,
Other = req.Other, FinishDate = req.FinishDate,
FundName = req.FundName, StartDate = req.StartDate,
FinishDate = req.FinishDate, EndDate = req.EndDate,
StartDate = req.StartDate, CreatedUserId = FullName ?? "",
EndDate = req.EndDate, CreatedFullName = UserId ?? "System Administrator",
CreatedUserId = FullName ?? "", CreatedAt = DateTime.Now,
CreatedFullName = UserId ?? "System Administrator", LastUpdateFullName = FullName ?? "System Administrator",
CreatedAt = DateTime.Now, LastUpdateUserId = UserId ?? "",
LastUpdateFullName = FullName ?? "System Administrator", LastUpdatedAt = DateTime.Now,
LastUpdateUserId = UserId ?? "", };
LastUpdatedAt = DateTime.Now, await _context.PlacementEducations.AddAsync(data);
}; await _context.SaveChangesAsync();
await _context.PlacementEducations.AddAsync(data); return Success();
} }
else
{
var education = await _context.PlacementEducations.FirstOrDefaultAsync(x => x.Id == req.Id);
if (education == null)
return Error(GlobalMessages.EducationNotFound, 404);
education.EducationLevel = educationLevel; [HttpPut("education/{personalId:length(36)}")]
education.PositionPath = positionPath; public async Task<ActionResult<ResponseObject>> UpdateEducation([FromBody] PersonEducationRequest req, Guid personalId)
education.Institute = req.Institute; {
education.Degree = req.Degree; var profile = await _context.PlacementProfiles.FirstOrDefaultAsync(x => x.Id == personalId);
education.Field = req.Field; if (profile == null)
education.Gpa = req.Gpa; return Error(GlobalMessages.DataNotFound, 404);
education.Country = req.Country;
education.Duration = req.Duration; var educationLevel = await _context.EducationLevels.FirstOrDefaultAsync(x => x.Id == req.EducationLevelId);
education.DurationYear = req.DurationYear; if (educationLevel == null && req.EducationLevelId != null)
education.Other = req.Other; return Error(GlobalMessages.DataNotFound, 404);
education.FundName = req.FundName;
education.FinishDate = req.FinishDate; var positionPath = await _context.PositionPaths.FirstOrDefaultAsync(x => x.Id == req.PositionPathId);
education.StartDate = req.StartDate; if (positionPath == null && req.PositionPathId != null)
education.EndDate = req.EndDate; return Error(GlobalMessages.DataNotFound, 404);
education.LastUpdateFullName = FullName ?? "System Administrator";
education.LastUpdateUserId = UserId ?? ""; var education = await _context.PlacementEducations.FirstOrDefaultAsync(x => x.Id == req.Id);
education.LastUpdatedAt = DateTime.Now; if (education == null)
} return Error(GlobalMessages.EducationNotFound, 404);
education.EducationLevel = educationLevel;
education.PositionPath = positionPath;
education.Institute = req.Institute;
education.Degree = req.Degree;
education.Field = req.Field;
education.Gpa = req.Gpa;
education.Country = req.Country;
education.Duration = req.Duration;
education.DurationYear = req.DurationYear;
education.Other = req.Other;
education.FundName = req.FundName;
education.FinishDate = req.FinishDate;
education.StartDate = req.StartDate;
education.EndDate = req.EndDate;
education.LastUpdateFullName = FullName ?? "System Administrator";
education.LastUpdateUserId = UserId ?? "";
education.LastUpdatedAt = DateTime.Now;
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
return Success(); return Success();
} }