diff --git a/Services/CandidateService.cs b/Services/CandidateService.cs index f0e7e9e..ae41bb6 100644 --- a/Services/CandidateService.cs +++ b/Services/CandidateService.cs @@ -1259,9 +1259,13 @@ namespace BMA.EHR.Recurit.Exam.Service.Services if (candidate == null) throw new Exception(GlobalMessages.ExamNotFound); + string profileImgId = candidate.ProfileImg.Id.ToString(); if (candidate.ProfileImg != null) { - await DeleteDocument(candidate.ProfileImg.Id.ToString()); + //ลบ FK ในเบสก่อนแล้วค่อยไปลบที่ minIo + candidate.ProfileImg = null; + await _context.SaveChangesAsync(); + await DeleteDocument(profileImgId); } var doc = await _minioService.UploadFileAsync(file); @@ -1282,9 +1286,13 @@ namespace BMA.EHR.Recurit.Exam.Service.Services if (candidate == null) throw new Exception(GlobalMessages.ExamNotFound); + string profileImgId = candidate.ProfileImg.Id.ToString(); if (candidate.ProfileImg != null) { - await DeleteDocument(candidate.ProfileImg.Id.ToString()); + //ลบ FK ในเบสก่อนแล้วค่อยไปลบที่ minIo + candidate.ProfileImg = null; + await _context.SaveChangesAsync(); + await DeleteDocument(profileImgId); } var doc = await _minioService.UploadFileAsync(file);