api ปฏิเสธจ่ายเงิน get ไฟล์สมัครสอบ
This commit is contained in:
parent
9486ad160d
commit
5abeada4a6
32 changed files with 7513 additions and 394 deletions
|
|
@ -49,6 +49,13 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
public async Task<CMSCandidate> GetsAsync()
|
||||
{
|
||||
var cms = await createCMS();
|
||||
|
||||
if (cms.LogoImg != null)
|
||||
cms.LogoImg.Detail = _minioService.ImagesPath(cms.LogoImg.Id).Result;
|
||||
|
||||
if (cms.BannerImg != null)
|
||||
cms.BannerImg.Detail = _minioService.ImagesPath(cms.BannerImg.Id).Result;
|
||||
|
||||
return cms;
|
||||
}
|
||||
|
||||
|
|
@ -82,6 +89,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
var cms = await createCMS();
|
||||
|
||||
cms.NameTh = updated.NameTh;
|
||||
cms.ShortName = updated.ShortName;
|
||||
cms.NameEn = updated.NameEn;
|
||||
cms.Description = updated.Description;
|
||||
cms.LastUpdatedAt = DateTime.Now;
|
||||
|
|
@ -129,9 +137,9 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
cms.ZipCode = subDistrict.ZipCode;
|
||||
}
|
||||
|
||||
cms.NameTh = updated.About;
|
||||
cms.NameEn = updated.Address;
|
||||
cms.Description = updated.Telephone;
|
||||
cms.About = updated.About;
|
||||
cms.Address = updated.Address;
|
||||
cms.Telephone = updated.Telephone;
|
||||
cms.LastUpdatedAt = DateTime.Now;
|
||||
cms.LastUpdateUserId = UserId ?? "";
|
||||
cms.LastUpdateFullName = FullName ?? "";
|
||||
|
|
@ -231,6 +239,168 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task<HomePageResponseItem> GetHomePageAsync()
|
||||
{
|
||||
var cms = await createCMS();
|
||||
|
||||
var cmsCandidates = await _context.CMSCandidates.AsQueryable()
|
||||
.Select(x => new HomePageResponseItem
|
||||
{
|
||||
Logo_url = x.LogoImg == null ? "" : x.LogoImg.Id.ToString(),
|
||||
Title = x.NameTh,
|
||||
Subtitle = x.NameEn,
|
||||
Supervised = x.ShortName,
|
||||
Telephone = x.Telephone,
|
||||
Address = x.Address + " " + (x.SubDistrict == null ? "" : "แขวง" + x.SubDistrict.Name + " ") + (x.District == null ? "" : "เขต" + x.District.Name) + " " + (x.Province == null ? "" : x.Province.Name) + " " + (x.SubDistrict == null ? "" : x.SubDistrict.ZipCode),
|
||||
Divisions = x.CMSAgencys.Select(s => new HomePageLinkResponseItem
|
||||
{
|
||||
Title = s.Name,
|
||||
Url = s.Link,
|
||||
}).ToList(),
|
||||
Institutes = x.CMSGovernments.Select(s => new HomePageLinkResponseItem
|
||||
{
|
||||
Title = s.Name,
|
||||
Url = s.Link,
|
||||
}).ToList(),
|
||||
})
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (cmsCandidates == null)
|
||||
throw new Exception(GlobalMessages.CMSNotFound);
|
||||
|
||||
if (cmsCandidates.Logo_url != null && cmsCandidates.Logo_url != "")
|
||||
cmsCandidates.Logo_url = _minioService.ImagesPath(Guid.Parse(cmsCandidates.Logo_url)).Result;
|
||||
|
||||
return cmsCandidates;
|
||||
}
|
||||
|
||||
public async Task<HomePageContentResponseItem> GetHomePageContentAsync()
|
||||
{
|
||||
var cms = await createCMS();
|
||||
|
||||
var cmsCandidates = await _context.CMSCandidates.AsQueryable()
|
||||
.Select(x => new HomePageContentResponseItem
|
||||
{
|
||||
Content = x.Description,
|
||||
Image = x.BannerImg == null ? "" : x.BannerImg.Id.ToString(),
|
||||
})
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (cmsCandidates == null)
|
||||
throw new Exception(GlobalMessages.CMSNotFound);
|
||||
|
||||
if (cmsCandidates.Image != null && cmsCandidates.Image != "")
|
||||
cmsCandidates.Image = _minioService.ImagesPath(Guid.Parse(cmsCandidates.Image)).Result;
|
||||
|
||||
return cmsCandidates;
|
||||
}
|
||||
|
||||
public async Task<AboutPageContentResponseItem> GetAboutPageContentAsync()
|
||||
{
|
||||
var cms = await createCMS();
|
||||
|
||||
var cmsCandidates = await _context.CMSCandidates.AsQueryable()
|
||||
.Select(x => new AboutPageContentResponseItem
|
||||
{
|
||||
Content = x.About,
|
||||
})
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (cmsCandidates == null)
|
||||
throw new Exception(GlobalMessages.CMSNotFound);
|
||||
|
||||
return cmsCandidates;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<CMSExamResponseItem?>> GetsCMSExamsAsync(int limit)
|
||||
{
|
||||
var cms = await createCMS();
|
||||
|
||||
var periodExams = await _context.PeriodExams.AsQueryable()
|
||||
.Where(x => x.AnnouncementStartDate <= DateTime.Now)
|
||||
.Where(x => x.AnnouncementEndDate >= DateTime.Now)
|
||||
.Include(x => x.PeriodExamImages)
|
||||
.Select(x => new CMSExamResponseItem
|
||||
{
|
||||
Id = x.Id.ToString(),
|
||||
Category = "doctor",
|
||||
Category_id = "doctor",
|
||||
Start = x.ExamDate,
|
||||
End = x.ExamDate,
|
||||
Exam_date = x.ExamDate,
|
||||
Announcement_date = x.AnnouncementStartDate,
|
||||
Title = x.Name,
|
||||
Image = x.PeriodExamImages.OrderBy(o => o.CreatedAt).FirstOrDefault() == null ?
|
||||
"" :
|
||||
x.PeriodExamImages.OrderBy(o => o.CreatedAt).FirstOrDefault().Document.Id.ToString(),
|
||||
})
|
||||
.ToListAsync();
|
||||
if (limit > 0)
|
||||
periodExams = periodExams.Take(limit).ToList();
|
||||
|
||||
var i = 0;
|
||||
foreach (var item in periodExams)
|
||||
{
|
||||
if (periodExams[i].Image != null && periodExams[i].Image != "")
|
||||
periodExams[i].Image = _minioService.ImagesPath(Guid.Parse(periodExams[i].Image)).Result;
|
||||
i++;
|
||||
}
|
||||
|
||||
return periodExams;
|
||||
}
|
||||
|
||||
public async Task<CMSExamResponseItem> GetCMSExamsAsync(string examId)
|
||||
{
|
||||
var cms = await createCMS();
|
||||
|
||||
var periodExam = await _context.PeriodExams.AsQueryable()
|
||||
.Where(x => x.Id == Guid.Parse(examId))
|
||||
.Include(x => x.PeriodExamImages)
|
||||
.Select(x => new CMSExamResponseItem
|
||||
{
|
||||
Id = x.Id.ToString(),
|
||||
Category = "doctor",
|
||||
Category_id = "doctor",
|
||||
Start = x.ExamDate,
|
||||
Title = x.Name,
|
||||
Detail = x.Detail,
|
||||
Images = x.PeriodExamImages.Select(s => new HomePageLinkResponseItem
|
||||
{
|
||||
Title = s.Document.FileName,
|
||||
Url = s.Document.Id.ToString(),
|
||||
}).ToList(),
|
||||
Files = x.PeriodExamDocuments.Select(s => new HomePageLinkResponseItem
|
||||
{
|
||||
Title = s.Document.FileName,
|
||||
Url = s.Document.Id.ToString(),
|
||||
}).ToList(),
|
||||
Positions = x.PositionExam.Select(s => new HomePageLinkResponseItem
|
||||
{
|
||||
Title = s.Id.ToString(),
|
||||
Url = $"{x.Id}/{s.Id}",
|
||||
}).ToList(),
|
||||
})
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (periodExam == null)
|
||||
throw new Exception(GlobalMessages.ExamNotFound);
|
||||
|
||||
var i = 0;
|
||||
foreach (var item in periodExam.Images)
|
||||
{
|
||||
if (periodExam.Images[i].Url != null && periodExam.Images[i].Url != "")
|
||||
periodExam.Images[i].Url = _minioService.ImagesPath(Guid.Parse(periodExam.Images[i].Url)).Result;
|
||||
i++;
|
||||
}
|
||||
i = 0;
|
||||
foreach (var item in periodExam.Files)
|
||||
{
|
||||
if (periodExam.Files[i].Url != null && periodExam.Files[i].Url != "")
|
||||
periodExam.Files[i].Url = _minioService.ImagesPath(Guid.Parse(periodExam.Files[i].Url)).Result;
|
||||
i++;
|
||||
}
|
||||
return periodExam;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -414,7 +414,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
if (candidate == null)
|
||||
throw new Exception(GlobalMessages.CandidateNotFound);
|
||||
|
||||
return await _context.CandidateDocuments.AsQueryable()
|
||||
var document = await _context.CandidateDocuments.AsQueryable()
|
||||
.Where(x => x.Candidate == candidate)
|
||||
.Select(x => new FileListResponse
|
||||
{
|
||||
|
|
@ -422,8 +422,19 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
FileName = x.Document == null ? "" : x.Document.FileName,
|
||||
FileType = x.Document == null ? "" : x.Document.FileType,
|
||||
FileSize = x.Document == null ? 0 : x.Document.FileSize,
|
||||
Detail = x.Document == null ? "" : x.Document.Id.ToString(),
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
var i = 0;
|
||||
foreach (var item in document)
|
||||
{
|
||||
if (document[i].Detail != null && document[i].Detail != "")
|
||||
document[i].Detail = _minioService.ImagesPath(Guid.Parse(document[i].Detail)).Result;
|
||||
i++;
|
||||
}
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
public async Task<string> GetsAsyncProfileImage(string examId, string positionId)
|
||||
|
|
@ -456,10 +467,13 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
if (candidate == null)
|
||||
throw new Exception(GlobalMessages.CandidateNotFound);
|
||||
|
||||
return candidate.ProfileImg == null ? "" : candidate.ProfileImg.Id.ToString();
|
||||
if (candidate.ProfileImg != null)
|
||||
candidate.ProfileImg.Detail = _minioService.ImagesPath(candidate.ProfileImg.Id).Result;
|
||||
|
||||
return candidate.ProfileImg == null ? "" : candidate.ProfileImg.Detail;
|
||||
}
|
||||
|
||||
public async Task<string> GetsAsyncPaymentImg(string examId, string positionId)
|
||||
public async Task<PaymentImgResponse> GetsAsyncPaymentImg(string examId, string positionId)
|
||||
{
|
||||
var exam = await _context.PeriodExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
|
||||
|
|
@ -489,7 +503,10 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
if (candidate == null)
|
||||
throw new Exception(GlobalMessages.CandidateNotFound);
|
||||
|
||||
return candidate.PaymentImg == null ? "" : candidate.PaymentImg.Id.ToString();
|
||||
if (candidate.PaymentImg != null)
|
||||
candidate.PaymentImg.Detail = _minioService.ImagesPath(candidate.PaymentImg.Id).Result;
|
||||
|
||||
return new PaymentImgResponse { PaymentImg = candidate.PaymentImg == null ? "" : candidate.PaymentImg.Detail, RejectDetail = candidate.RejectDetail };
|
||||
}
|
||||
|
||||
public async Task<string> GetsAsyncPaymentImgCandidate(string candidateId)
|
||||
|
|
@ -502,7 +519,10 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
if (candidate == null)
|
||||
throw new Exception(GlobalMessages.CandidateNotFound);
|
||||
|
||||
return candidate.PaymentImg == null ? "" : candidate.PaymentImg.Id.ToString();
|
||||
if (candidate.PaymentImg != null)
|
||||
candidate.PaymentImg.Detail = _minioService.ImagesPath(candidate.PaymentImg.Id).Result;
|
||||
|
||||
return candidate.PaymentImg == null ? "" : candidate.PaymentImg.Detail.ToString();
|
||||
}
|
||||
|
||||
public async Task<RequestStatusRegistry> GetsAsyncRegisterExam(string examId, string positionId)
|
||||
|
|
@ -873,7 +893,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
|
||||
if (candidate.ProfileImg != null)
|
||||
{
|
||||
await DeleteAsyncDocument(candidate.ProfileImg.Id.ToString());
|
||||
await DeleteDocument(candidate.ProfileImg.Id.ToString());
|
||||
}
|
||||
|
||||
var doc = await _minioService.UploadFileAsync(file);
|
||||
|
|
@ -1078,11 +1098,28 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task DeleteAsyncDocument(string documentId)
|
||||
public async Task DeleteDocument(string documentId)
|
||||
{
|
||||
await _minioService.DeleteFileAsync(Guid.Parse(documentId));
|
||||
}
|
||||
|
||||
public async Task DeleteAsyncDocument(string examId, string positionId, string documentId)
|
||||
{
|
||||
var exam = await _context.PeriodExams.AsQueryable()
|
||||
.Include(x => x.PositionExam)
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
|
||||
|
||||
if (exam == null)
|
||||
throw new Exception(GlobalMessages.ExamNotFound);
|
||||
|
||||
var position = exam.PositionExam.Where(x => x.Id == Guid.Parse(positionId)).FirstOrDefault();
|
||||
|
||||
if (position == null)
|
||||
throw new Exception(GlobalMessages.PositionExamNotFound);
|
||||
|
||||
await _minioService.DeleteFileAsync(Guid.Parse(documentId));
|
||||
}
|
||||
|
||||
public async Task CreateAsyncCareer(string examId, string positionId, CandidateCareerResponseItem updated)
|
||||
{
|
||||
var candidateId = await CreateAsyncCandidate(examId, positionId);
|
||||
|
|
@ -1219,7 +1256,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task<string> GetStatusCandidateService(string examId, string positionId)
|
||||
public async Task<CandidateStatusResponse> GetStatusCandidateService(string examId, string positionId)
|
||||
{
|
||||
var exam = await _context.PeriodExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
|
||||
|
|
@ -1245,7 +1282,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
if (candidate == null)
|
||||
throw new Exception(GlobalMessages.CandidateNotFound);
|
||||
|
||||
return candidate.Status;
|
||||
return new CandidateStatusResponse { Status = candidate.Status, RejectDetail = candidate.RejectDetail };
|
||||
}
|
||||
|
||||
public async Task UserCheckCandidateService(string examId, string positionId, string status)
|
||||
|
|
@ -1358,7 +1395,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
|
||||
if (candidate.PaymentImg != null)
|
||||
{
|
||||
await DeleteAsyncDocument(candidate.PaymentImg.Id.ToString());
|
||||
await DeleteDocument(candidate.PaymentImg.Id.ToString());
|
||||
}
|
||||
|
||||
var doc = await _minioService.UploadFileAsync(file);
|
||||
|
|
|
|||
|
|
@ -46,6 +46,17 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
this._bucketName = _configuration["MinIO:BucketName"] ?? "bma-recruit";
|
||||
}
|
||||
|
||||
public static IConfigurationRoot Configuration
|
||||
{
|
||||
get
|
||||
{
|
||||
return new ConfigurationBuilder()
|
||||
.SetBasePath(Directory.GetCurrentDirectory())
|
||||
.AddJsonFile("appsettings.json")
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Methods "
|
||||
|
|
@ -185,6 +196,34 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
}
|
||||
}
|
||||
|
||||
public async Task<string> ImagesPath(Guid fileId)
|
||||
{
|
||||
if (fileId == null)
|
||||
return "";
|
||||
|
||||
var doc = await _context.Documents.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == fileId);
|
||||
|
||||
if (doc == null)
|
||||
throw new Exception(GlobalMessages.FileNotFoundOnServer);
|
||||
var config = new AmazonS3Config
|
||||
{
|
||||
ServiceURL = Configuration.GetValue<string>("MinIO:Endpoint"),
|
||||
ForcePathStyle = true
|
||||
};
|
||||
|
||||
DateTime expires = DateTime.UtcNow.AddHours(6);
|
||||
GetPreSignedUrlRequest request = new GetPreSignedUrlRequest
|
||||
{
|
||||
BucketName = _bucketName,
|
||||
Key = doc?.ObjectRefId.ToString("D"),
|
||||
Expires = expires,
|
||||
};
|
||||
string path = _s3Client.GetPreSignedURL(request);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
@ -49,12 +49,46 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
public async Task<IEnumerable<PeriodExamCandidateResponseItem>> GetsAsync(bool showAll = true)
|
||||
{
|
||||
return await _context.PeriodExams.AsQueryable()
|
||||
.Include(x => x.PositionExam)
|
||||
.Include(x => x.BankExam)
|
||||
.Where(p => p.IsActive)
|
||||
.OrderBy(d => d.Name)
|
||||
.Select(x => new PeriodExamCandidateResponseItem
|
||||
{
|
||||
ExamDate = x.ExamDate,
|
||||
AnnouncementEndDate = x.AnnouncementEndDate,
|
||||
AnnouncementStartDate = x.AnnouncementStartDate,
|
||||
CheckDisability = x.CheckDisability,
|
||||
CheckDocument = x.CheckDocument,
|
||||
Detail = x.Detail,
|
||||
Fee = x.Fee,
|
||||
Id = x.Id,
|
||||
IsActive = x.IsActive,
|
||||
Name = x.Name,
|
||||
Note = x.Note,
|
||||
OrganizationCodeId = x.OrganizationCodeId,
|
||||
OrganizationCodeName = x.OrganizationCodeName,
|
||||
OrganizationId = x.OrganizationId,
|
||||
OrganizationName = x.OrganizationName,
|
||||
PaymentEndDate = x.PaymentEndDate,
|
||||
PaymentKrungThai = x.PaymentKrungThai,
|
||||
PaymentStartDate = x.PaymentStartDate,
|
||||
RegisterEndDate = x.RegisterEndDate,
|
||||
RegisterStartDate = x.RegisterStartDate,
|
||||
Round = x.Round,
|
||||
SetSeat = x.SetSeat,
|
||||
Year = x.Year,
|
||||
})
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<PeriodExamCandidateResponseItem?> GetsExamAndCandidateAsync(string examId, bool showAll = true)
|
||||
{
|
||||
var periodExam = await _context.PeriodExams.AsQueryable()
|
||||
.Include(x => x.PositionExam)
|
||||
.Include(x => x.BankExam)
|
||||
.Include(x => x.PeriodExamDocuments)
|
||||
.Select(x => new PeriodExamCandidateResponseItem
|
||||
{
|
||||
ExamDate = x.ExamDate,
|
||||
AnnouncementEndDate = x.AnnouncementEndDate,
|
||||
AnnouncementStartDate = x.AnnouncementStartDate,
|
||||
CheckDisability = x.CheckDisability,
|
||||
|
|
@ -98,19 +132,37 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
FileName = b.Document == null ? "" : b.Document.FileName,
|
||||
FileSize = b.Document == null ? 0 : b.Document.FileSize,
|
||||
FileType = b.Document == null ? "" : b.Document.FileType,
|
||||
Detail = b.Document == null ? "" : b.Document.Id.ToString(),
|
||||
}).ToList(),
|
||||
Images = x.PeriodExamImages.OrderBy(o => o.CreatedAt).Select(b => new FileListResponse
|
||||
{
|
||||
Id = b.Document == null ? "" : b.Document.Id.ToString(),
|
||||
FileName = b.Document == null ? "" : b.Document.FileName,
|
||||
FileSize = b.Document == null ? 0 : b.Document.FileSize,
|
||||
FileType = b.Document == null ? "" : b.Document.FileType,
|
||||
Detail = b.Document == null ? "" : b.Document.Id.ToString(),
|
||||
}).ToList(),
|
||||
})
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<PeriodExam?> GetsExamAndCandidateAsync(string examId, bool showAll = true)
|
||||
{
|
||||
var periodExam = await _context.PeriodExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
|
||||
|
||||
if (periodExam == null)
|
||||
throw new Exception(GlobalMessages.ExamNotFound);
|
||||
|
||||
var i = 0;
|
||||
foreach (var item in periodExam.Images)
|
||||
{
|
||||
if (periodExam.Images[i].Detail != null && periodExam.Images[i].Detail != "")
|
||||
periodExam.Images[i].Detail = _minioService.ImagesPath(Guid.Parse(periodExam.Images[i].Detail)).Result;
|
||||
i++;
|
||||
}
|
||||
i = 0;
|
||||
foreach (var item in periodExam.Documents)
|
||||
{
|
||||
if (periodExam.Documents[i].Detail != null && periodExam.Documents[i].Detail != "")
|
||||
periodExam.Documents[i].Detail = _minioService.ImagesPath(Guid.Parse(periodExam.Documents[i].Detail)).Result;
|
||||
i++;
|
||||
}
|
||||
|
||||
return periodExam;
|
||||
}
|
||||
|
||||
|
|
@ -157,7 +209,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
}
|
||||
}
|
||||
|
||||
public async Task CreateAsync(RequestPeriodExam inserted, IFormFileCollection files)
|
||||
public async Task<Guid> CreateAsync(RequestPeriodExam inserted)
|
||||
{
|
||||
var periodExam = new PeriodExam
|
||||
{
|
||||
|
|
@ -172,6 +224,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
PaymentStartDate = inserted.PaymentStartDate,
|
||||
PaymentEndDate = inserted.PaymentEndDate,
|
||||
AnnouncementStartDate = inserted.AnnouncementStartDate,
|
||||
ExamDate = inserted.ExamDate,
|
||||
AnnouncementEndDate = inserted.AnnouncementEndDate,
|
||||
OrganizationCodeId = inserted.OrganizationCodeId,
|
||||
OrganizationCodeName = inserted.OrganizationCodeName,
|
||||
|
|
@ -225,35 +278,18 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
await _context.PositionExams.AddAsync(positionExam);
|
||||
}
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
var doc = await _minioService.UploadFileAsync(file);
|
||||
|
||||
var document = await _context.Documents.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == doc.Id);
|
||||
|
||||
if (document == null)
|
||||
throw new Exception(GlobalMessages.NoFileToUpload);
|
||||
|
||||
var periodExamDocument = new PeriodExamDocument
|
||||
{
|
||||
PeriodExam = periodExam,
|
||||
Document = document,
|
||||
};
|
||||
|
||||
await _context.PeriodExamDocuments.AddAsync(periodExamDocument);
|
||||
}
|
||||
|
||||
await _context.PeriodExams.AddAsync(periodExam);
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
|
||||
return periodExam.Id;
|
||||
}
|
||||
|
||||
public async Task UpdateAsync(string examId, RequestPeriodExam updated, IFormFileCollection files)
|
||||
public async Task UpdateAsync(string examId, RequestPeriodExam updated)
|
||||
{
|
||||
var periodExam = await _context.PeriodExams.AsQueryable()
|
||||
.Include(x => x.BankExam)
|
||||
.Include(x => x.PositionExam)
|
||||
.Include(x => x.Candidate)
|
||||
.Include(x => x.PeriodExamDocuments)
|
||||
.ThenInclude(x => x.Document)
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
|
||||
|
|
@ -272,6 +308,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
periodExam.PaymentStartDate = updated.PaymentStartDate;
|
||||
periodExam.PaymentEndDate = updated.PaymentEndDate;
|
||||
periodExam.AnnouncementStartDate = updated.AnnouncementStartDate;
|
||||
periodExam.ExamDate = updated.ExamDate;
|
||||
periodExam.AnnouncementEndDate = updated.AnnouncementEndDate;
|
||||
periodExam.OrganizationCodeId = updated.OrganizationCodeId;
|
||||
periodExam.OrganizationCodeName = updated.OrganizationCodeName;
|
||||
|
|
@ -284,20 +321,54 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
periodExam.LastUpdateUserId = UserId ?? "";
|
||||
periodExam.LastUpdateFullName = FullName ?? "";
|
||||
|
||||
foreach (var bank in periodExam.BankExam)
|
||||
if (updated.PaymentKrungThai != "payment2")
|
||||
{
|
||||
var bankData = updated.BankExam
|
||||
.FirstOrDefault(x => x.Id == bank.Id);
|
||||
if (bankData != null)
|
||||
foreach (var bank in periodExam.BankExam)
|
||||
{
|
||||
bank.AccountName = bankData.AccountName;
|
||||
bank.AccountNumber = bankData.AccountNumber;
|
||||
bank.BankName = bankData.BankName;
|
||||
bank.LastUpdatedAt = DateTime.Now;
|
||||
bank.LastUpdateUserId = UserId ?? "";
|
||||
bank.LastUpdateFullName = FullName ?? "";
|
||||
var bankData = updated.BankExam
|
||||
.FirstOrDefault(x => x.Id == bank.Id);
|
||||
if (bankData != null)
|
||||
{
|
||||
bank.AccountName = bankData.AccountName;
|
||||
bank.AccountNumber = bankData.AccountNumber;
|
||||
bank.BankName = bankData.BankName;
|
||||
bank.LastUpdatedAt = DateTime.Now;
|
||||
bank.LastUpdateUserId = UserId ?? "";
|
||||
bank.LastUpdateFullName = FullName ?? "";
|
||||
}
|
||||
else
|
||||
{
|
||||
var bankDelete = await _context.BankExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == bank.Id);
|
||||
|
||||
if (bankDelete != null)
|
||||
_context.BankExams.Remove(bankDelete);
|
||||
}
|
||||
}
|
||||
else
|
||||
var bankAdd = updated.BankExam
|
||||
.Where(x => x.Id == Guid.Parse("00000000-0000-0000-0000-000000000000"))
|
||||
.ToList();
|
||||
foreach (var bank in bankAdd)
|
||||
{
|
||||
var bankExam = new BankExam
|
||||
{
|
||||
PeriodExam = periodExam,
|
||||
AccountName = bank.AccountName,
|
||||
AccountNumber = bank.AccountNumber,
|
||||
BankName = bank.BankName,
|
||||
CreatedAt = DateTime.Now,
|
||||
CreatedUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
CreatedFullName = FullName ?? "",
|
||||
LastUpdateFullName = FullName ?? "",
|
||||
};
|
||||
await _context.BankExams.AddAsync(bankExam);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var bank in periodExam.BankExam)
|
||||
{
|
||||
var bankDelete = await _context.BankExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == bank.Id);
|
||||
|
|
@ -327,31 +398,14 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
.FirstOrDefaultAsync(x => x.Id == position.Id);
|
||||
|
||||
if (positionDelete != null)
|
||||
{
|
||||
if (periodExam.Candidate.Count() > 0)
|
||||
throw new Exception("รอบนี้มีการสมัครแล้วไม่สามารถลบตำแหน่งได้");
|
||||
_context.PositionExams.Remove(positionDelete);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var bankAdd = updated.BankExam
|
||||
.Where(x => x.Id == Guid.Parse("00000000-0000-0000-0000-000000000000"))
|
||||
.ToList();
|
||||
foreach (var bank in bankAdd)
|
||||
{
|
||||
var bankExam = new BankExam
|
||||
{
|
||||
PeriodExam = periodExam,
|
||||
AccountName = bank.AccountName,
|
||||
AccountNumber = bank.AccountNumber,
|
||||
BankName = bank.BankName,
|
||||
CreatedAt = DateTime.Now,
|
||||
CreatedUserId = UserId ?? "",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
LastUpdateUserId = UserId ?? "",
|
||||
CreatedFullName = FullName ?? "",
|
||||
LastUpdateFullName = FullName ?? "",
|
||||
};
|
||||
await _context.BankExams.AddAsync(bankExam);
|
||||
}
|
||||
|
||||
var positionAdd = updated.PositionExam
|
||||
.Where(x => x.Id == Guid.Parse("00000000-0000-0000-0000-000000000000"))
|
||||
.ToList();
|
||||
|
|
@ -374,13 +428,16 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
await _context.PositionExams.AddAsync(positionExam);
|
||||
}
|
||||
|
||||
foreach (var doc in periodExam.PeriodExamDocuments)
|
||||
{
|
||||
if (doc.Id != null)
|
||||
{
|
||||
await DeleteAsyncDocument(doc.Id.ToString());
|
||||
}
|
||||
}
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task UpdateDocAsync(string examId, IFormFileCollection files)
|
||||
{
|
||||
var periodExam = await _context.PeriodExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
|
||||
|
||||
if (periodExam == null)
|
||||
throw new Exception(GlobalMessages.ExamNotFound);
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
|
|
@ -404,8 +461,50 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task DeleteAsyncDocument(string documentId)
|
||||
public async Task UpdateImgAsync(string examId, IFormFileCollection files)
|
||||
{
|
||||
var periodExam = await _context.PeriodExams.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
|
||||
|
||||
if (periodExam == null)
|
||||
throw new Exception(GlobalMessages.ExamNotFound);
|
||||
|
||||
foreach (var file in files)
|
||||
{
|
||||
var doc = await _minioService.UploadFileAsync(file);
|
||||
|
||||
var document = await _context.Documents.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == doc.Id);
|
||||
|
||||
if (document == null)
|
||||
throw new Exception(GlobalMessages.NoFileToUpload);
|
||||
|
||||
var periodExamImage = new PeriodExamImage
|
||||
{
|
||||
PeriodExam = periodExam,
|
||||
Document = document,
|
||||
};
|
||||
|
||||
await _context.PeriodExamImages.AddAsync(periodExamImage);
|
||||
}
|
||||
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task DeleteDocument(string documentId)
|
||||
{
|
||||
await _minioService.DeleteFileAsync(Guid.Parse(documentId));
|
||||
}
|
||||
|
||||
public async Task DeleteAsyncDocument(string examId, string documentId)
|
||||
{
|
||||
var exam = await _context.PeriodExams.AsQueryable()
|
||||
.Include(x => x.PositionExam)
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
|
||||
|
||||
if (exam == null)
|
||||
throw new Exception(GlobalMessages.ExamNotFound);
|
||||
|
||||
await _minioService.DeleteFileAsync(Guid.Parse(documentId));
|
||||
}
|
||||
|
||||
|
|
@ -445,7 +544,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
|
||||
public async Task<CandidateInformationResponseItem?> GetsAsyncInformation(string candidateId)
|
||||
{
|
||||
return await _context.Candidates.AsQueryable()
|
||||
var candidate = await _context.Candidates.AsQueryable()
|
||||
.Where(x => x.Id == Guid.Parse(candidateId))
|
||||
.Select(x => new CandidateInformationResponseItem
|
||||
{
|
||||
|
|
@ -467,8 +566,17 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
Telephone = x.Telephone,
|
||||
MobilePhone = x.MobilePhone,
|
||||
Knowledge = x.Knowledge,
|
||||
ProfileImg = x.ProfileImg == null ? "" : x.ProfileImg.Id.ToString(),
|
||||
})
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (candidate == null)
|
||||
return candidate;
|
||||
|
||||
if (candidate.ProfileImg != null && candidate.ProfileImg != "")
|
||||
candidate.ProfileImg = _minioService.ImagesPath(Guid.Parse(candidate.ProfileImg)).Result;
|
||||
|
||||
return candidate;
|
||||
}
|
||||
|
||||
public async Task<CandidateOccupationResponseItem?> GetsAsyncOccupation(string candidateId)
|
||||
|
|
@ -560,6 +668,37 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<FileListResponse?>> GetsAsyncDocument(string candidateId)
|
||||
{
|
||||
var candidate = await _context.Candidates.AsQueryable()
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(candidateId));
|
||||
|
||||
if (candidate == null)
|
||||
throw new Exception(GlobalMessages.CandidateNotFound);
|
||||
|
||||
var document = await _context.CandidateDocuments.AsQueryable()
|
||||
.Where(x => x.Candidate == candidate)
|
||||
.Select(x => new FileListResponse
|
||||
{
|
||||
Id = x.Document == null ? "" : x.Document.Id.ToString(),
|
||||
FileName = x.Document == null ? "" : x.Document.FileName,
|
||||
FileType = x.Document == null ? "" : x.Document.FileType,
|
||||
FileSize = x.Document == null ? 0 : x.Document.FileSize,
|
||||
Detail = x.Document == null ? "" : x.Document.Id.ToString(),
|
||||
})
|
||||
.ToListAsync();
|
||||
|
||||
var i = 0;
|
||||
foreach (var item in document)
|
||||
{
|
||||
if (document[i].Detail != null && document[i].Detail != "")
|
||||
document[i].Detail = _minioService.ImagesPath(Guid.Parse(document[i].Detail)).Result;
|
||||
i++;
|
||||
}
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
private async Task<List<RequestImportSeat>> ReadExcelCandidate(IFormFile formFile)
|
||||
{
|
||||
var list = new List<RequestImportSeat>();
|
||||
|
|
@ -726,16 +865,22 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
return stream;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<BankExam?>> GetsPaymentExamAsync(string examId)
|
||||
public async Task<PeriodExam> GetsPaymentExamAsync(string examId)
|
||||
{
|
||||
var periodExam = await _context.PeriodExams.AsQueryable()
|
||||
.Include(x => x.BankExam)
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
|
||||
.Where(x => x.Id == Guid.Parse(examId))
|
||||
.Select(x => new PeriodExam
|
||||
{
|
||||
BankExam = x.BankExam,
|
||||
Fee = x.Fee,
|
||||
})
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (periodExam == null)
|
||||
throw new Exception(GlobalMessages.ExamNotFound);
|
||||
|
||||
return periodExam.BankExam;
|
||||
return periodExam;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue