update payment

This commit is contained in:
kittapath 2025-11-06 22:03:35 +07:00
parent 33e8d487ef
commit 577c7b289e

View file

@ -2207,18 +2207,24 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (candidate == null) if (candidate == null)
throw new Exception(GlobalMessages.ExamNotFound); throw new Exception(GlobalMessages.ExamNotFound);
if (candidate.PaymentImg != null) // เก็บ ID ของ Document เก่าไว้ก่อน
{ var oldDocumentId = candidate.PaymentImg?.Id.ToString();
await DeleteDocument(candidate.PaymentImg.Id.ToString());
}
// Upload Document ใหม่ก่อน
var doc = await _minioService.UploadFileAsync(file); var doc = await _minioService.UploadFileAsync(file);
var document = await _context.Documents.AsQueryable() var document = await _context.Documents.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == doc.Id); .FirstOrDefaultAsync(x => x.Id == doc.Id);
// กำหนด Document ใหม่ให้กับ candidate
candidate.PaymentImg = document; candidate.PaymentImg = document;
await _context.SaveChangesAsync(); await _context.SaveChangesAsync();
// ลบ Document เก่าหลังจากที่ตัด reference แล้ว
if (oldDocumentId != null)
{
await DeleteDocument(oldDocumentId);
}
} }
public async Task<RequestCardCandidate> GetsAsyncCardCandidate(string examId, string positionId) public async Task<RequestCardCandidate> GetsAsyncCardCandidate(string examId, string positionId)