From 8c50baaf5f10362285b2f742295e40d9007b2a1d Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 13 Jul 2023 19:37:19 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89api=E0=B8=9B?= =?UTF-8?q?=E0=B8=A3=E0=B8=B0=E0=B8=A7=E0=B8=B1=E0=B8=95=E0=B8=B4=E0=B8=A8?= =?UTF-8?q?=E0=B8=B4=E0=B8=81=E0=B8=A9=E0=B8=B2=E0=B8=9A=E0=B8=A3=E0=B8=A3?= =?UTF-8?q?=E0=B8=88=E0=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/PlacementController.cs | 194 ++++++++++-------- 1 file changed, 106 insertions(+), 88 deletions(-) diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementController.cs index 2a116fae..17d536ed 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementController.cs @@ -793,6 +793,36 @@ namespace BMA.EHR.Placement.Service.Controllers return Success(); } + [HttpPost("certificate/{personalId:length(36)}")] + public async Task> 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)}")] public async Task> UpdateCertificate([FromBody] PersonCertificateRequest req, Guid personalId) { @@ -802,39 +832,17 @@ namespace BMA.EHR.Placement.Service.Controllers if (person == null) return Error(GlobalMessages.DataNotFound, 404); - 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, - }; - 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; - } + 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(); @@ -857,12 +865,9 @@ namespace BMA.EHR.Placement.Service.Controllers return Success(); } - [HttpPut("education/{personalId:length(36)}")] - public async Task> UpdateEducation([FromBody] PersonEducationRequest req, Guid personalId) + [HttpPost("education/{personalId:length(36)}")] + public async Task> 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); if (profile == null) return Error(GlobalMessages.DataNotFound, 404); @@ -875,58 +880,71 @@ namespace BMA.EHR.Placement.Service.Controllers if (positionPath == null && req.PositionPathId != null) return Error(GlobalMessages.DataNotFound, 404); - if (req.Id == null) + var data = new PlacementEducation { - var data = new PlacementEducation - { - PlacementProfile = profile, - EducationLevel = educationLevel, - PositionPath = positionPath, - Institute = req.Institute, - Degree = req.Degree, - Field = req.Field, - Gpa = req.Gpa, - Country = req.Country, - Duration = req.Duration, - DurationYear = req.DurationYear, - Other = req.Other, - FundName = req.FundName, - FinishDate = req.FinishDate, - StartDate = req.StartDate, - EndDate = req.EndDate, - CreatedUserId = FullName ?? "", - CreatedFullName = UserId ?? "System Administrator", - CreatedAt = DateTime.Now, - LastUpdateFullName = FullName ?? "System Administrator", - LastUpdateUserId = UserId ?? "", - LastUpdatedAt = DateTime.Now, - }; - await _context.PlacementEducations.AddAsync(data); - } - else - { - var education = await _context.PlacementEducations.FirstOrDefaultAsync(x => x.Id == req.Id); - if (education == null) - return Error(GlobalMessages.EducationNotFound, 404); + PlacementProfile = profile, + EducationLevel = educationLevel, + PositionPath = positionPath, + Institute = req.Institute, + Degree = req.Degree, + Field = req.Field, + Gpa = req.Gpa, + Country = req.Country, + Duration = req.Duration, + DurationYear = req.DurationYear, + Other = req.Other, + FundName = req.FundName, + FinishDate = req.FinishDate, + StartDate = req.StartDate, + EndDate = req.EndDate, + CreatedUserId = FullName ?? "", + CreatedFullName = UserId ?? "System Administrator", + CreatedAt = DateTime.Now, + LastUpdateFullName = FullName ?? "System Administrator", + LastUpdateUserId = UserId ?? "", + LastUpdatedAt = DateTime.Now, + }; + await _context.PlacementEducations.AddAsync(data); + await _context.SaveChangesAsync(); + return Success(); + } - 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; - } + [HttpPut("education/{personalId:length(36)}")] + public async Task> 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); + 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(); return Success(); }