From eabf9aa8d77b40624b48915fde826a1d80cb875d Mon Sep 17 00:00:00 2001 From: AnandaTon <125332905+anandaAiemvong@users.noreply.github.com> Date: Mon, 3 Apr 2023 10:35:44 +0700 Subject: [PATCH] api payment image upload --- Controllers/CandidateController.cs | 32 ++++++++++++++++++++++++++++++ Services/CandidateService.cs | 19 ++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/Controllers/CandidateController.cs b/Controllers/CandidateController.cs index f4187f4..39dcd06 100644 --- a/Controllers/CandidateController.cs +++ b/Controllers/CandidateController.cs @@ -840,6 +840,38 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers } } + /// + /// อัปเอกสารหลักฐานการชำระเงิน + /// + /// รหัสรอบสมัคร + /// + /// เมื่ออัปเอกสารหลักฐานสำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpPut("upload-payment/{examId:length(36)}"), DisableRequestSizeLimit] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> UploadPaymentCandidateService(string examId) + { + try + { + if (Request.Form.Files == null || Request.Form.Files.Count == 0) + { + return Error(GlobalMessages.NoFileToUpload); + } + + var file = Request.Form.Files[0]; + await _candidateService.UpdateAsyncPaymentImage(examId, file); + + return Success(); + } + catch (Exception ex) + { + return Error(ex); + } + } + #endregion } } diff --git a/Services/CandidateService.cs b/Services/CandidateService.cs index 9ca3b48..5441865 100644 --- a/Services/CandidateService.cs +++ b/Services/CandidateService.cs @@ -975,6 +975,25 @@ namespace BMA.EHR.Recurit.Exam.Service.Services await _context.SaveChangesAsync(); } + public async Task UpdateAsyncPaymentImage(string examId, IFormFile file) + { + var candidateId = await CreateAsyncCandidate(examId); + + var candidate = await _context.Candidates.AsQueryable() + .FirstOrDefaultAsync(x => x.Id == Guid.Parse(candidateId)); + + if (candidate == null) + throw new Exception(GlobalMessages.ExamNotFound); + + var doc = await _minioService.UploadFileAsync(file); + + var document = await _context.Documents.AsQueryable() + .FirstOrDefaultAsync(x => x.Id == doc.Id); + + candidate.PaymentImg = document; + await _context.SaveChangesAsync(); + } + #endregion } }