อัพโหลดเอกสารสร้างรอบสมัคร
This commit is contained in:
parent
9f115e3c72
commit
c986fc1500
13 changed files with 2278 additions and 315 deletions
|
|
@ -542,6 +542,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
Status = candidate == null ? null : candidate.Status,
|
||||
PositionExam = candidatePosition?.PositionExam,
|
||||
Bank = exam.BankExam.Count() > 0,
|
||||
Payment = exam.Fee > 0,
|
||||
Position = candidatePosition == null ? false : true
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,10 @@ using System.Text.Json;
|
|||
using BMA.EHR.Recurit.Exam.Service.Core;
|
||||
using BMA.EHR.Recurit.Exam.Service.Data;
|
||||
using BMA.EHR.Recurit.Exam.Service.Models;
|
||||
using BMA.EHR.Recurit.Exam.Service.Models.Documents;
|
||||
using BMA.EHR.Recurit.Exam.Service.Request;
|
||||
using BMA.EHR.Recurit.Exam.Service.Response;
|
||||
using BMA.EHR.Recurit.Exam.Service.Responses.Document;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using OfficeOpenXml;
|
||||
|
|
@ -17,16 +19,19 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
|
||||
private readonly ApplicationDbContext _context;
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
private readonly MinIOService _minioService;
|
||||
|
||||
#endregion
|
||||
|
||||
#region " Constructor and Destructor "
|
||||
|
||||
public PeriodExamService(ApplicationDbContext context,
|
||||
IHttpContextAccessor httpContextAccessor)
|
||||
IHttpContextAccessor httpContextAccessor,
|
||||
MinIOService minioService)
|
||||
{
|
||||
_context = context;
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
_minioService = minioService;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
|
@ -41,61 +46,61 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
|
||||
#region " Methods "
|
||||
|
||||
public async Task<IEnumerable<PeriodExam>> GetsAsync(bool showAll = true)
|
||||
public async Task<IEnumerable<PeriodExamCandidateResponseItem>> GetsAsync(bool showAll = true)
|
||||
{
|
||||
if (showAll)
|
||||
return await _context.PeriodExams.AsQueryable()
|
||||
.Include(x => x.PositionExam)
|
||||
.Include(x => x.BankExam)
|
||||
.OrderBy(d => d.Name)
|
||||
.ToListAsync();
|
||||
else
|
||||
return await _context.PeriodExams.AsQueryable()
|
||||
.Include(x => x.PositionExam)
|
||||
.Include(x => x.BankExam)
|
||||
.Where(p => p.IsActive)
|
||||
.OrderBy(d => d.Name)
|
||||
.Select(x => new PeriodExam
|
||||
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
|
||||
{
|
||||
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,
|
||||
BankExam = x.BankExam.OrderBy(o => o.CreatedAt).Select(b => new BankExam
|
||||
{
|
||||
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,
|
||||
BankExam = x.BankExam.OrderBy(o => o.CreatedAt).Select(b => new BankExam
|
||||
{
|
||||
Id = b.Id,
|
||||
AccountName = b.AccountName,
|
||||
AccountNumber = b.AccountNumber,
|
||||
BankName = b.BankName,
|
||||
}).ToList(),
|
||||
PositionExam = x.PositionExam.OrderBy(o => o.CreatedAt).Select(b => new PositionExam
|
||||
{
|
||||
Id = b.Id,
|
||||
TypeId = b.TypeId,
|
||||
TypeName = b.TypeName,
|
||||
PositionId = b.PositionId,
|
||||
PositionName = b.PositionName,
|
||||
}).ToList(),
|
||||
})
|
||||
.ToListAsync();
|
||||
Id = b.Id,
|
||||
AccountName = b.AccountName,
|
||||
AccountNumber = b.AccountNumber,
|
||||
BankName = b.BankName,
|
||||
}).ToList(),
|
||||
PositionExam = x.PositionExam.OrderBy(o => o.CreatedAt).Select(b => new PositionExam
|
||||
{
|
||||
Id = b.Id,
|
||||
TypeId = b.TypeId,
|
||||
TypeName = b.TypeName,
|
||||
PositionId = b.PositionId,
|
||||
PositionName = b.PositionName,
|
||||
}).ToList(),
|
||||
Documents = x.PeriodExamDocuments.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,
|
||||
}).ToList(),
|
||||
})
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task<PeriodExam?> GetsExamAndCandidateAsync(string examId, bool showAll = true)
|
||||
|
|
@ -152,7 +157,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
|
|||
}
|
||||
}
|
||||
|
||||
public async Task CreateAsync(RequestPeriodExam inserted)
|
||||
public async Task CreateAsync(RequestPeriodExam inserted, IFormFileCollection files)
|
||||
{
|
||||
var periodExam = new PeriodExam
|
||||
{
|
||||
|
|
@ -220,16 +225,37 @@ 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();
|
||||
}
|
||||
|
||||
public async Task UpdateAsync(string examId, RequestPeriodExam updated)
|
||||
public async Task UpdateAsync(string examId, RequestPeriodExam updated, IFormFileCollection files)
|
||||
{
|
||||
var periodExam = await _context.PeriodExams.AsQueryable()
|
||||
.Include(x => x.BankExam)
|
||||
.Include(x => x.PositionExam)
|
||||
.Include(x => x.PeriodExamDocuments)
|
||||
.ThenInclude(x => x.Document)
|
||||
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(examId));
|
||||
|
||||
if (periodExam == null)
|
||||
|
|
@ -348,9 +374,41 @@ 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());
|
||||
}
|
||||
}
|
||||
|
||||
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.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public async Task DeleteAsyncDocument(string documentId)
|
||||
{
|
||||
await _minioService.DeleteFileAsync(Guid.Parse(documentId));
|
||||
}
|
||||
|
||||
public async Task DeleteAsync(string examId)
|
||||
{
|
||||
var periodExam = await _context.PeriodExams.AsQueryable()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue