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();