From c6dc5822549677ac0c911513f25c10207f53e01e Mon Sep 17 00:00:00 2001 From: "Harid Promsri (Bright)" Date: Mon, 10 Jul 2023 14:31:49 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9A=20api=20?= =?UTF-8?q?=E0=B8=82=E0=B9=89=E0=B8=AD=E0=B8=A1=E0=B8=B9=E0=B8=A5=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=81?= =?UTF-8?q?=E0=B8=B2=E0=B8=A3=E0=B8=A8=E0=B8=B6=E0=B8=81=E0=B8=A9=E0=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BMA.EHR.Domain/Shared/GlobalMessages.cs | 1 + .../Controllers/PlacementController.cs | 30 +++++++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/BMA.EHR.Domain/Shared/GlobalMessages.cs b/BMA.EHR.Domain/Shared/GlobalMessages.cs index 3b9627bc..3e14f7f5 100644 --- a/BMA.EHR.Domain/Shared/GlobalMessages.cs +++ b/BMA.EHR.Domain/Shared/GlobalMessages.cs @@ -57,6 +57,7 @@ #region " Placement " public static readonly string CertificateNotFound = "ไม่พบข้อมูลใบประกอบอาชีพ"; + public static readonly string EducationNotFound = "ไม่พบข้อมูลประวัติการศึกษา"; #endregion } } diff --git a/BMA.EHR.Placement.Service/Controllers/PlacementController.cs b/BMA.EHR.Placement.Service/Controllers/PlacementController.cs index a3d585de..c08dda23 100644 --- a/BMA.EHR.Placement.Service/Controllers/PlacementController.cs +++ b/BMA.EHR.Placement.Service/Controllers/PlacementController.cs @@ -1,6 +1,7 @@ using BMA.EHR.Application.Repositories; using BMA.EHR.Domain.Common; using BMA.EHR.Domain.Extensions; +using BMA.EHR.Domain.Models.MetaData; using BMA.EHR.Domain.Models.Placement; using BMA.EHR.Domain.Shared; using BMA.EHR.Infrastructure.Persistence; @@ -715,16 +716,25 @@ namespace BMA.EHR.Placement.Service.Controllers // 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) 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); + if (req.Id == null) { var data = new PlacementEducation { PlacementProfile = profile, + EducationLevel = educationLevel, + PositionPath = positionPath, Institute = req.Institute, Degree = req.Degree, Field = req.Field, @@ -748,10 +758,12 @@ namespace BMA.EHR.Placement.Service.Controllers } else { - 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) - return Error(GlobalMessages.DataNotFound, 404); + return Error(GlobalMessages.EducationNotFound, 404); + + education.EducationLevel = educationLevel; + education.PositionPath = positionPath; education.Institute = req.Institute; education.Degree = req.Degree; education.Field = req.Field; @@ -772,12 +784,12 @@ namespace BMA.EHR.Placement.Service.Controllers return Success(); } - [HttpDelete("education/{personalId:length(36)}")] - public async Task> DeleteEducation(Guid personalId) + [HttpDelete("education/{educationId:length(36)}")] + public async Task> DeleteEducation(Guid educationId) { - var education = await _context.PlacementEducations.FirstOrDefaultAsync(x => x.Id == personalId); + var education = await _context.PlacementEducations.FirstOrDefaultAsync(x => x.Id == educationId); if (education == null) - return Error(GlobalMessages.DataNotFound, 404); + return Error(GlobalMessages.EducationNotFound, 404); _context.PlacementEducations.Remove(education); _context.SaveChanges();