ดิงข้อมูลหลักจาก dbกลาง

This commit is contained in:
Kittapath 2023-04-10 16:28:05 +07:00
parent 2f292d25ca
commit 4e8520eb01
44 changed files with 4642 additions and 2590 deletions

View file

@ -18,6 +18,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
#region " Fields "
private readonly ApplicationDbContext _context;
private readonly MetadataDbContext _contextMetadata;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly MinIOService _minioService;
@ -26,10 +27,12 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
#region " Constructor and Destructor "
public CMSCandidateService(ApplicationDbContext context,
MetadataDbContext contextMetadata,
IHttpContextAccessor httpContextAccessor,
MinIOService minioService)
{
_context = context;
_contextMetadata = contextMetadata;
_httpContextAccessor = httpContextAccessor;
_minioService = minioService;
}
@ -77,9 +80,6 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
.Include(x => x.LogoImg)
.Include(x => x.CMSAgencys)
.Include(x => x.CMSGovernments)
.Include(x => x.Province)
.Include(x => x.District)
.Include(x => x.SubDistrict)
.FirstOrDefaultAsync();
if (cmsCandidates == null)
{
@ -119,35 +119,38 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (updated.ProvinceId != null)
{
var province = await _context.Provinces.AsQueryable()
var province = await _contextMetadata.Provinces.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.ProvinceId));
if (province == null)
throw new Exception(GlobalMessages.ProvinceNotFound);
cms.Province = province;
cms.ProvinceId = province.Id;
cms.ProvinceName = province.Name;
}
if (updated.DistrictId != null)
{
var pistrict = await _context.Districts.AsQueryable()
var pistrict = await _contextMetadata.Districts.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.DistrictId));
if (pistrict == null)
throw new Exception(GlobalMessages.DistrictNotFound);
cms.District = pistrict;
cms.DistrictId = pistrict.Id;
cms.DistrictName = pistrict.Name;
}
if (updated.SubDistrictId != null)
{
var subDistrict = await _context.SubDistricts.AsQueryable()
var subDistrict = await _contextMetadata.SubDistricts.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.SubDistrictId));
if (subDistrict == null)
throw new Exception(GlobalMessages.SubDistrictNotFound);
cms.SubDistrict = subDistrict;
cms.SubDistrictId = subDistrict.Id;
cms.SubDistrictName = subDistrict.Name;
cms.ZipCode = subDistrict.ZipCode;
}
@ -265,7 +268,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
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),
Address = x.Address + " " + (x.SubDistrictName == null ? "" : "แขวง" + x.SubDistrictName + " ") + (x.DistrictName == null ? "" : "เขต" + x.DistrictName) + " " + (x.ProvinceName == null ? "" : x.ProvinceName) + " " + (x.ZipCode == null ? "" : x.ZipCode),
Divisions = x.CMSAgencys.Select(s => new HomePageLinkResponseItem
{
Title = s.Name,
@ -339,11 +342,11 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
Id = x.Id.ToString(),
Category = "doctor",
Category_id = "doctor",
Start = x.ExamDate.ToShortDateString(),
End = x.ExamDate.ToShortDateString(),
Exam_date = x.ExamDate.ToShortDateString(),
Announcement_date = x.AnnouncementStartDate.ToShortDateString(),
Announcement_endDate = x.AnnouncementEndDate.ToShortDateString(),
Start = x.ExamDate.ToString("MM-dd-yyyy"),
End = x.ExamDate.ToString("MM-dd-yyyy"),
Exam_date = x.ExamDate.ToString("MM-dd-yyyy"),
Announcement_date = x.AnnouncementStartDate.ToString("MM-dd-yyyy"),
Announcement_endDate = x.AnnouncementEndDate.ToString("MM-dd-yyyy"),
Title = x.Name,
Image = x.PeriodExamImages.OrderBy(o => o.CreatedAt).FirstOrDefault() == null ?
"" :
@ -378,8 +381,8 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
Id = x.Id.ToString(),
Category = "doctor",
Category_id = "doctor",
Start = x.AnnouncementStartDate.ToShortDateString(),
End = x.AnnouncementEndDate.ToShortDateString(),
Start = x.AnnouncementStartDate.ToString("MM-dd-yyyy"),
End = x.AnnouncementEndDate.ToString("MM-dd-yyyy"),
Title = x.Name,
Detail = x.Detail,
Images = x.PeriodExamImages.Select(s => new HomePageLinkResponseItem