From 577c7b289eee126c293e94451a9ce6f25dc5f612 Mon Sep 17 00:00:00 2001 From: kittapath Date: Thu, 6 Nov 2025 22:03:35 +0700 Subject: [PATCH] update payment --- Services/CandidateService.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Services/CandidateService.cs b/Services/CandidateService.cs index 17ec119..63469ff 100644 --- a/Services/CandidateService.cs +++ b/Services/CandidateService.cs @@ -2207,18 +2207,24 @@ namespace BMA.EHR.Recurit.Exam.Service.Services if (candidate == null) throw new Exception(GlobalMessages.ExamNotFound); - if (candidate.PaymentImg != null) - { - await DeleteDocument(candidate.PaymentImg.Id.ToString()); - } + // เก็บ ID ของ Document เก่าไว้ก่อน + var oldDocumentId = candidate.PaymentImg?.Id.ToString(); + // Upload Document ใหม่ก่อน var doc = await _minioService.UploadFileAsync(file); var document = await _context.Documents.AsQueryable() .FirstOrDefaultAsync(x => x.Id == doc.Id); + // กำหนด Document ใหม่ให้กับ candidate candidate.PaymentImg = document; await _context.SaveChangesAsync(); + + // ลบ Document เก่าหลังจากที่ตัด reference แล้ว + if (oldDocumentId != null) + { + await DeleteDocument(oldDocumentId); + } } public async Task GetsAsyncCardCandidate(string examId, string positionId)