ปรับ api ข้อมูลประวัติการศึกษา

This commit is contained in:
Harid Promsri (Bright) 2023-07-10 14:31:49 +07:00
parent b7afae1e7d
commit c6dc582254
2 changed files with 22 additions and 9 deletions

View file

@ -57,6 +57,7 @@
#region " Placement " #region " Placement "
public static readonly string CertificateNotFound = "ไม่พบข้อมูลใบประกอบอาชีพ"; public static readonly string CertificateNotFound = "ไม่พบข้อมูลใบประกอบอาชีพ";
public static readonly string EducationNotFound = "ไม่พบข้อมูลประวัติการศึกษา";
#endregion #endregion
} }
} }

View file

@ -1,6 +1,7 @@
using BMA.EHR.Application.Repositories; using BMA.EHR.Application.Repositories;
using BMA.EHR.Domain.Common; using BMA.EHR.Domain.Common;
using BMA.EHR.Domain.Extensions; using BMA.EHR.Domain.Extensions;
using BMA.EHR.Domain.Models.MetaData;
using BMA.EHR.Domain.Models.Placement; using BMA.EHR.Domain.Models.Placement;
using BMA.EHR.Domain.Shared; using BMA.EHR.Domain.Shared;
using BMA.EHR.Infrastructure.Persistence; using BMA.EHR.Infrastructure.Persistence;
@ -715,16 +716,25 @@ namespace BMA.EHR.Placement.Service.Controllers
// var education = await _context.PlacementEducations // var education = await _context.PlacementEducations
// .Include(x => x.PlacementProfile) // .Include(x => x.PlacementProfile)
// .FirstOrDefaultAsync(x => x.Id == personalId); // .FirstOrDefaultAsync(x => x.Id == personalId);
var profile = await _context.PlacementProfiles var profile = await _context.PlacementProfiles.FirstOrDefaultAsync(x => x.Id == personalId);
.FirstOrDefaultAsync(x => x.Id == personalId);
if (profile == null) if (profile == null)
return Error(GlobalMessages.DataNotFound, 404); 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) if (req.Id == null)
{ {
var data = new PlacementEducation var data = new PlacementEducation
{ {
PlacementProfile = profile, PlacementProfile = profile,
EducationLevel = educationLevel,
PositionPath = positionPath,
Institute = req.Institute, Institute = req.Institute,
Degree = req.Degree, Degree = req.Degree,
Field = req.Field, Field = req.Field,
@ -748,10 +758,12 @@ namespace BMA.EHR.Placement.Service.Controllers
} }
else else
{ {
var education = await _context.PlacementEducations var education = await _context.PlacementEducations.FirstOrDefaultAsync(x => x.Id == req.Id);
.FirstOrDefaultAsync(x => x.Id == req.Id);
if (education == null) if (education == null)
return Error(GlobalMessages.DataNotFound, 404); return Error(GlobalMessages.EducationNotFound, 404);
education.EducationLevel = educationLevel;
education.PositionPath = positionPath;
education.Institute = req.Institute; education.Institute = req.Institute;
education.Degree = req.Degree; education.Degree = req.Degree;
education.Field = req.Field; education.Field = req.Field;
@ -772,12 +784,12 @@ namespace BMA.EHR.Placement.Service.Controllers
return Success(); return Success();
} }
[HttpDelete("education/{personalId:length(36)}")] [HttpDelete("education/{educationId:length(36)}")]
public async Task<ActionResult<ResponseObject>> DeleteEducation(Guid personalId) public async Task<ActionResult<ResponseObject>> 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) if (education == null)
return Error(GlobalMessages.DataNotFound, 404); return Error(GlobalMessages.EducationNotFound, 404);
_context.PlacementEducations.Remove(education); _context.PlacementEducations.Remove(education);
_context.SaveChanges(); _context.SaveChanges();