diff --git a/Controllers/CandidateController.cs b/Controllers/CandidateController.cs index b3fff43..23c1ff6 100644 --- a/Controllers/CandidateController.cs +++ b/Controllers/CandidateController.cs @@ -777,6 +777,58 @@ namespace BMA.EHR.Recurit.Exam.Service.Controllers } } + /// + /// get id รูปถ่าย + /// + /// รหัสรอบสมัคร + /// + /// เมื่อ get id รูปถ่ายสำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet("profile-img/{examId:length(36)}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> GetsAsyncProfileImage(string examId) + { + try + { + var doc = await _candidateService.GetsAsyncProfileImage(examId); + + return Success(doc); + } + catch (Exception ex) + { + return Error(ex); + } + } + + /// + /// get id หลักฐานชำระ + /// + /// รหัสรอบสมัคร + /// + /// เมื่อ get id หลักฐานชำระสำเร็จ + /// ไม่ได้ Login เข้าระบบ + /// เมื่อเกิดข้อผิดพลาดในการทำงาน + [HttpGet("payment-img/{examId:length(36)}")] + [ProducesResponseType(StatusCodes.Status200OK)] + [ProducesResponseType(StatusCodes.Status401Unauthorized)] + [ProducesResponseType(StatusCodes.Status500InternalServerError)] + public async Task> GetsAsyncPaymentImg(string examId) + { + try + { + var doc = await _candidateService.GetsAsyncPaymentImg(examId); + + return Success(doc); + } + catch (Exception ex) + { + return Error(ex); + } + } + /// /// อัปโหลดเอกสารหลักฐาน /// diff --git a/Services/CandidateService.cs b/Services/CandidateService.cs index 670af61..79ab2a7 100644 --- a/Services/CandidateService.cs +++ b/Services/CandidateService.cs @@ -249,6 +249,42 @@ namespace BMA.EHR.Recurit.Exam.Service.Services .ToListAsync(); ; } + public async Task GetsAsyncProfileImage(string examId) + { + var exam = await _context.PeriodExams.AsQueryable() + .FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId)); + + if (exam == null) + throw new Exception(GlobalMessages.ExamNotFound); + + var candidate = await _context.Candidates.AsQueryable() + .Where(x => x.PeriodExam == exam && x.UserId == UserId) + .FirstOrDefaultAsync(); + + if (candidate == null) + throw new Exception(GlobalMessages.CandidateNotFound); + + return candidate.ProfileImg == null ? "" : candidate.ProfileImg.Id.ToString(); + } + + public async Task GetsAsyncPaymentImg(string examId) + { + var exam = await _context.PeriodExams.AsQueryable() + .FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId)); + + if (exam == null) + throw new Exception(GlobalMessages.ExamNotFound); + + var candidate = await _context.Candidates.AsQueryable() + .Where(x => x.PeriodExam == exam && x.UserId == UserId) + .FirstOrDefaultAsync(); + + if (candidate == null) + throw new Exception(GlobalMessages.CandidateNotFound); + + return candidate.PaymentImg == null ? "" : candidate.PaymentImg.Id.ToString(); + } + public async Task GetsAsyncRegisterExam(string examId) { var exam = await _context.PeriodExams.AsQueryable()