ดิงข้อมูลหลักจาก 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

View file

@ -15,6 +15,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;
@ -23,10 +24,12 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
#region " Constructor and Destructor "
public CandidateService(ApplicationDbContext context,
MetadataDbContext contextMetadata,
IHttpContextAccessor httpContextAccessor,
MinIOService minioService)
{
_context = context;
_contextMetadata = contextMetadata;
_httpContextAccessor = httpContextAccessor;
_minioService = minioService;
}
@ -46,19 +49,6 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task<Candidate> GetsAsync(string candidateId)
{
var candidate = await _context.Candidates.AsQueryable()
.Include(x => x.Prefix)
.Include(x => x.Relationship)
.Include(x => x.CitizenProvince)
.Include(x => x.CitizenDistrict)
.Include(x => x.RegistProvince)
.Include(x => x.RegistDistrict)
.Include(x => x.RegistSubDistrict)
.Include(x => x.CurrentProvince)
.Include(x => x.CurrentDistrict)
.Include(x => x.CurrentSubDistrict)
.Include(x => x.MarryPrefix)
.Include(x => x.FatherPrefix)
.Include(x => x.MotherPrefix)
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(candidateId));
if (candidate == null)
@ -87,18 +77,18 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
.Where(x => x.PeriodExam == exam && x.UserId == UserId && x.PositionExam == position)
.Select(x => new CandidateInformationResponseItem
{
Prefix = x.Prefix,
PrefixId = x.Prefix != null ? x.Prefix.Id.ToString() : null,
Prefix = x.PrefixName,
PrefixId = x.PrefixId != null ? x.PrefixId.ToString() : null,
FirstName = x.FirstName,
LastName = x.LastName,
Nationality = x.Nationality,
DateOfBirth = x.DateOfBirth,
Relationship = x.Relationship,
RelationshipId = x.Relationship != null ? x.Relationship.Id.ToString() : null,
CitizenProvince = x.CitizenProvince,
CitizenProvinceId = x.CitizenProvince != null ? x.CitizenProvince.Id.ToString() : null,
CitizenDistrict = x.CitizenDistrict,
CitizenDistrictId = x.CitizenDistrict != null ? x.CitizenDistrict.Id.ToString() : null,
Relationship = x.RelationshipName,
RelationshipId = x.RelationshipId != null ? x.RelationshipId.ToString() : null,
CitizenProvince = x.CitizenProvinceName,
CitizenProvinceId = x.CitizenProvinceId != null ? x.CitizenProvinceId.ToString() : null,
CitizenDistrict = x.CitizenDistrictName,
CitizenDistrictId = x.CitizenDistrictId != null ? x.CitizenDistrictId.ToString() : null,
CitizenDate = x.CitizenDate,
Email = x.Email,
CitizenId = x.CitizenId,
@ -114,18 +104,18 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
.Where(x => x.PeriodExam == exam && x.UserId == UserId)
.Select(x => new CandidateInformationResponseItem
{
Prefix = x.Prefix,
PrefixId = x.Prefix != null ? x.Prefix.Id.ToString() : null,
Prefix = x.PrefixName,
PrefixId = x.PrefixId != null ? x.PrefixId.ToString() : null,
FirstName = x.FirstName,
LastName = x.LastName,
Nationality = x.Nationality,
DateOfBirth = x.DateOfBirth,
Relationship = x.Relationship,
RelationshipId = x.Relationship != null ? x.Relationship.Id.ToString() : null,
CitizenProvince = x.CitizenProvince,
CitizenProvinceId = x.CitizenProvince != null ? x.CitizenProvince.Id.ToString() : null,
CitizenDistrict = x.CitizenDistrict,
CitizenDistrictId = x.CitizenDistrict != null ? x.CitizenDistrict.Id.ToString() : null,
Relationship = x.RelationshipName,
RelationshipId = x.RelationshipId != null ? x.RelationshipId.ToString() : null,
CitizenProvince = x.CitizenProvinceName,
CitizenProvinceId = x.CitizenProvinceId != null ? x.CitizenProvinceId.ToString() : null,
CitizenDistrict = x.CitizenDistrictName,
CitizenDistrictId = x.CitizenDistrictId != null ? x.CitizenDistrictId.ToString() : null,
CitizenDate = x.CitizenDate,
Email = x.Email,
CitizenId = x.CitizenId,
@ -158,21 +148,21 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
.Select(x => new CandidateAddressResponseItem
{
RegistAddress = x.RegistAddress,
RegistProvince = x.RegistProvince,
RegistProvinceId = x.RegistProvince != null ? x.RegistProvince.Id.ToString() : null,
RegistDistrict = x.RegistDistrict,
RegistDistrictId = x.RegistDistrict != null ? x.RegistDistrict.Id.ToString() : null,
RegistSubDistrict = x.RegistSubDistrict,
RegistSubDistrictId = x.RegistSubDistrict != null ? x.RegistSubDistrict.Id.ToString() : null,
RegistProvince = x.RegistProvinceName,
RegistProvinceId = x.RegistProvinceId != null ? x.RegistProvinceId.ToString() : null,
RegistDistrict = x.RegistDistrictName,
RegistDistrictId = x.RegistDistrictId != null ? x.RegistDistrictId.ToString() : null,
RegistSubDistrict = x.RegistSubDistrictName,
RegistSubDistrictId = x.RegistSubDistrictId != null ? x.RegistSubDistrictId.ToString() : null,
RegistZipCode = x.RegistZipCode,
RegistSame = x.RegistSame,
CurrentAddress = x.CurrentAddress,
CurrentProvince = x.CurrentProvince,
CurrentProvinceId = x.CurrentProvince != null ? x.CurrentProvince.Id.ToString() : null,
CurrentDistrict = x.CurrentDistrict,
CurrentDistrictId = x.CurrentDistrict != null ? x.CurrentDistrict.Id.ToString() : null,
CurrentSubDistrict = x.CurrentSubDistrict,
CurrentSubDistrictId = x.CurrentSubDistrict != null ? x.CurrentSubDistrict.Id.ToString() : null,
CurrentProvince = x.CurrentProvinceName,
CurrentProvinceId = x.CurrentProvinceId != null ? x.CurrentProvinceId.ToString() : null,
CurrentDistrict = x.CurrentDistrictName,
CurrentDistrictId = x.CurrentDistrictId != null ? x.CurrentDistrictId.ToString() : null,
CurrentSubDistrict = x.CurrentSubDistrictName,
CurrentSubDistrictId = x.CurrentSubDistrictId != null ? x.CurrentSubDistrictId.ToString() : null,
CurrentZipCode = x.CurrentZipCode,
})
.FirstOrDefaultAsync();
@ -184,21 +174,21 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
.Select(x => new CandidateAddressResponseItem
{
RegistAddress = x.RegistAddress,
RegistProvince = x.RegistProvince,
RegistProvinceId = x.RegistProvince != null ? x.RegistProvince.Id.ToString() : null,
RegistDistrict = x.RegistDistrict,
RegistDistrictId = x.RegistDistrict != null ? x.RegistDistrict.Id.ToString() : null,
RegistSubDistrict = x.RegistSubDistrict,
RegistSubDistrictId = x.RegistSubDistrict != null ? x.RegistSubDistrict.Id.ToString() : null,
RegistProvince = x.RegistProvinceName,
RegistProvinceId = x.RegistProvinceId != null ? x.RegistProvinceId.ToString() : null,
RegistDistrict = x.RegistDistrictName,
RegistDistrictId = x.RegistDistrictId != null ? x.RegistDistrictId.ToString() : null,
RegistSubDistrict = x.RegistSubDistrictName,
RegistSubDistrictId = x.RegistSubDistrictId != null ? x.RegistSubDistrictId.ToString() : null,
RegistZipCode = x.RegistZipCode,
RegistSame = x.RegistSame,
CurrentAddress = x.CurrentAddress,
CurrentProvince = x.CurrentProvince,
CurrentProvinceId = x.CurrentProvince != null ? x.CurrentProvince.Id.ToString() : null,
CurrentDistrict = x.CurrentDistrict,
CurrentDistrictId = x.CurrentDistrict != null ? x.CurrentDistrict.Id.ToString() : null,
CurrentSubDistrict = x.CurrentSubDistrict,
CurrentSubDistrictId = x.CurrentSubDistrict != null ? x.CurrentSubDistrict.Id.ToString() : null,
CurrentProvince = x.CurrentProvinceName,
CurrentProvinceId = x.CurrentProvinceId != null ? x.CurrentProvinceId.ToString() : null,
CurrentDistrict = x.CurrentDistrictName,
CurrentDistrictId = x.CurrentDistrictId != null ? x.CurrentDistrictId.ToString() : null,
CurrentSubDistrict = x.CurrentSubDistrictName,
CurrentSubDistrictId = x.CurrentSubDistrictId != null ? x.CurrentSubDistrictId.ToString() : null,
CurrentZipCode = x.CurrentZipCode,
})
.FirstOrDefaultAsync();
@ -226,20 +216,20 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
.Select(x => new CandidateFamilyResponseItem
{
Marry = x.Marry,
MarryPrefix = x.MarryPrefix,
MarryPrefixId = x.MarryPrefix != null ? x.MarryPrefix.Id.ToString() : null,
MarryPrefix = x.MarryPrefixName,
MarryPrefixId = x.MarryPrefixId != null ? x.MarryPrefixId.ToString() : null,
MarryFirstName = x.MarryFirstName,
MarryLastName = x.MarryLastName,
MarryOccupation = x.MarryOccupation,
MarryNationality = x.MarryNationality,
FatherPrefix = x.FatherPrefix,
FatherPrefixId = x.FatherPrefix != null ? x.FatherPrefix.Id.ToString() : null,
FatherPrefix = x.FatherPrefixName,
FatherPrefixId = x.FatherPrefixId != null ? x.FatherPrefixId.ToString() : null,
FatherFirstName = x.FatherFirstName,
FatherLastName = x.FatherLastName,
FatherOccupation = x.FatherOccupation,
FatherNationality = x.FatherNationality,
MotherPrefix = x.MotherPrefix,
MotherPrefixId = x.MotherPrefix != null ? x.MotherPrefix.Id.ToString() : null,
MotherPrefix = x.MotherPrefixName,
MotherPrefixId = x.MotherPrefixId != null ? x.MotherPrefixId.ToString() : null,
MotherFirstName = x.MotherFirstName,
MotherLastName = x.MotherLastName,
MotherOccupation = x.MotherOccupation,
@ -254,20 +244,20 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
.Select(x => new CandidateFamilyResponseItem
{
Marry = x.Marry,
MarryPrefix = x.MarryPrefix,
MarryPrefixId = x.MarryPrefix != null ? x.MarryPrefix.Id.ToString() : null,
MarryPrefix = x.MarryPrefixName,
MarryPrefixId = x.MarryPrefixId != null ? x.MarryPrefixId.ToString() : null,
MarryFirstName = x.MarryFirstName,
MarryLastName = x.MarryLastName,
MarryOccupation = x.MarryOccupation,
MarryNationality = x.MarryNationality,
FatherPrefix = x.FatherPrefix,
FatherPrefixId = x.FatherPrefix != null ? x.FatherPrefix.Id.ToString() : null,
FatherPrefix = x.FatherPrefixName,
FatherPrefixId = x.FatherPrefixId != null ? x.FatherPrefixId.ToString() : null,
FatherFirstName = x.FatherFirstName,
FatherLastName = x.FatherLastName,
FatherOccupation = x.FatherOccupation,
FatherNationality = x.FatherNationality,
MotherPrefix = x.MotherPrefix,
MotherPrefixId = x.MotherPrefix != null ? x.MotherPrefix.Id.ToString() : null,
MotherPrefix = x.MotherPrefixName,
MotherPrefixId = x.MotherPrefixId != null ? x.MotherPrefixId.ToString() : null,
MotherFirstName = x.MotherFirstName,
MotherLastName = x.MotherLastName,
MotherOccupation = x.MotherOccupation,
@ -382,7 +372,6 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
throw new Exception(GlobalMessages.CandidateNotFound);
return await _context.Educations.AsQueryable()
.Include(x => x.EducationLevel)
.Where(x => x.Candidate == candidate)
.OrderBy(d => d.DurationStart)
.ToListAsync();
@ -630,147 +619,160 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (updated.PrefixId != null)
{
var prefix = await _context.Prefixes.AsQueryable()
var prefix = await _contextMetadata.Prefixes.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.PrefixId));
if (prefix == null)
throw new Exception(GlobalMessages.PrefixNotFound);
candidate.Prefix = prefix;
candidate.PrefixId = prefix.Id;
candidate.PrefixName = prefix.Name;
}
if (updated.RelationshipId != null)
{
var relationship = await _context.Relationships.AsQueryable()
var relationship = await _contextMetadata.Relationships.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.RelationshipId));
if (relationship == null)
throw new Exception(GlobalMessages.RelationshipNotFound);
candidate.Relationship = relationship;
candidate.RelationshipId = relationship.Id;
candidate.RelationshipName = relationship.Name;
}
if (updated.CitizenProvinceId != null)
{
var citizenProvince = await _context.Provinces.AsQueryable()
var citizenProvince = await _contextMetadata.Provinces.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.CitizenProvinceId));
if (citizenProvince == null)
throw new Exception(GlobalMessages.ProvinceNotFound);
candidate.CitizenProvince = citizenProvince;
candidate.CitizenProvinceId = citizenProvince.Id;
candidate.CitizenProvinceName = citizenProvince.Name;
}
if (updated.CitizenDistrictId != null)
{
var citizenDistrict = await _context.Districts.AsQueryable()
var citizenDistrict = await _contextMetadata.Districts.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.CitizenDistrictId));
if (citizenDistrict == null)
throw new Exception(GlobalMessages.DistrictNotFound);
candidate.CitizenDistrict = citizenDistrict;
candidate.CitizenDistrictId = citizenDistrict.Id;
candidate.CitizenDistrictName = citizenDistrict.Name;
}
if (updated.RegistProvinceId != null)
{
var registProvince = await _context.Provinces.AsQueryable()
var registProvince = await _contextMetadata.Provinces.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.RegistProvinceId));
if (registProvince == null)
throw new Exception(GlobalMessages.ProvinceNotFound);
candidate.RegistProvince = registProvince;
candidate.RegistProvinceId = registProvince.Id;
candidate.RegistProvinceName = registProvince.Name;
}
if (updated.RegistDistrictId != null)
{
var registDistrict = await _context.Districts.AsQueryable()
var registDistrict = await _contextMetadata.Districts.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.RegistDistrictId));
if (registDistrict == null)
throw new Exception(GlobalMessages.DistrictNotFound);
candidate.RegistDistrict = registDistrict;
candidate.RegistDistrictId = registDistrict.Id;
candidate.RegistDistrictName = registDistrict.Name;
}
if (updated.RegistSubDistrictId != null)
{
var registSubDistrict = await _context.SubDistricts.AsQueryable()
var registSubDistrict = await _contextMetadata.SubDistricts.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.RegistSubDistrictId));
if (registSubDistrict == null)
throw new Exception(GlobalMessages.SubDistrictNotFound);
candidate.RegistSubDistrict = registSubDistrict;
candidate.RegistSubDistrictId = registSubDistrict.Id;
candidate.RegistSubDistrictName = registSubDistrict.Name;
candidate.RegistZipCode = registSubDistrict.ZipCode;
}
if (updated.CurrentProvinceId != null)
{
var currentProvince = await _context.Provinces.AsQueryable()
var currentProvince = await _contextMetadata.Provinces.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.CurrentProvinceId));
if (currentProvince == null)
throw new Exception(GlobalMessages.ProvinceNotFound);
candidate.CurrentProvince = currentProvince;
candidate.CurrentProvinceId = currentProvince.Id;
candidate.CurrentProvinceName = currentProvince.Name;
}
if (updated.CurrentDistrictId != null)
{
var currentDistrict = await _context.Districts.AsQueryable()
var currentDistrict = await _contextMetadata.Districts.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.CurrentDistrictId));
if (currentDistrict == null)
throw new Exception(GlobalMessages.DistrictNotFound);
candidate.CurrentDistrict = currentDistrict;
candidate.CurrentDistrictId = currentDistrict.Id;
candidate.CurrentDistrictName = currentDistrict.Name;
}
if (updated.CurrentSubDistrictId != null)
{
var currentSubDistrict = await _context.SubDistricts.AsQueryable()
var currentSubDistrict = await _contextMetadata.SubDistricts.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.CurrentSubDistrictId));
if (currentSubDistrict == null)
throw new Exception(GlobalMessages.SubDistrictNotFound);
candidate.CurrentSubDistrict = currentSubDistrict;
candidate.CurrentSubDistrictId = currentSubDistrict.Id;
candidate.CurrentSubDistrictName = currentSubDistrict.Name;
candidate.CurrentZipCode = currentSubDistrict.ZipCode;
}
if (updated.MarryPrefixId != null)
{
var prefix = await _context.Prefixes.AsQueryable()
var prefix = await _contextMetadata.Prefixes.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.MarryPrefixId));
if (prefix == null)
throw new Exception(GlobalMessages.PrefixNotFound);
candidate.MarryPrefix = prefix;
candidate.MarryPrefixId = prefix.Id;
candidate.MarryPrefixName = prefix.Name;
}
if (updated.FatherPrefixId != null)
{
var prefix = await _context.Prefixes.AsQueryable()
var prefix = await _contextMetadata.Prefixes.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.FatherPrefixId));
if (prefix == null)
throw new Exception(GlobalMessages.PrefixNotFound);
candidate.FatherPrefix = prefix;
candidate.FatherPrefixId = prefix.Id;
candidate.FatherPrefixName = prefix.Name;
}
if (updated.MotherPrefixId != null)
{
var prefix = await _context.Prefixes.AsQueryable()
var prefix = await _contextMetadata.Prefixes.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.MotherPrefixId));
if (prefix == null)
throw new Exception(GlobalMessages.PrefixNotFound);
candidate.MotherPrefix = prefix;
candidate.MotherPrefixId = prefix.Id;
candidate.MotherPrefixName = prefix.Name;
}
candidate.FirstName = updated.FirstName;
@ -824,46 +826,50 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (updated.PrefixId != null)
{
var prefix = await _context.Prefixes.AsQueryable()
var prefix = await _contextMetadata.Prefixes.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.PrefixId));
if (prefix == null)
throw new Exception(GlobalMessages.PrefixNotFound);
candidate.Prefix = prefix;
candidate.PrefixId = prefix.Id;
candidate.PrefixName = prefix.Name;
}
if (updated.RelationshipId != null)
{
var relationship = await _context.Relationships.AsQueryable()
var relationship = await _contextMetadata.Relationships.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.RelationshipId));
if (relationship == null)
throw new Exception(GlobalMessages.RelationshipNotFound);
candidate.Relationship = relationship;
candidate.RelationshipId = relationship.Id;
candidate.RelationshipName = relationship.Name;
}
if (updated.CitizenProvinceId != null)
{
var citizenProvince = await _context.Provinces.AsQueryable()
var citizenProvince = await _contextMetadata.Provinces.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.CitizenProvinceId));
if (citizenProvince == null)
throw new Exception(GlobalMessages.ProvinceNotFound);
candidate.CitizenProvince = citizenProvince;
candidate.CitizenProvinceId = citizenProvince.Id;
candidate.CitizenProvinceName = citizenProvince.Name;
}
if (updated.CitizenDistrictId != null)
{
var citizenDistrict = await _context.Districts.AsQueryable()
var citizenDistrict = await _contextMetadata.Districts.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.CitizenDistrictId));
if (citizenDistrict == null)
throw new Exception(GlobalMessages.DistrictNotFound);
candidate.CitizenDistrict = citizenDistrict;
candidate.CitizenDistrictId = citizenDistrict.Id;
candidate.CitizenDistrictName = citizenDistrict.Name;
}
candidate.FirstName = updated.FirstName;
@ -917,69 +923,75 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (updated.RegistProvinceId != null)
{
var registProvince = await _context.Provinces.AsQueryable()
var registProvince = await _contextMetadata.Provinces.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.RegistProvinceId));
if (registProvince == null)
throw new Exception(GlobalMessages.ProvinceNotFound);
candidate.RegistProvince = registProvince;
candidate.RegistProvinceId = registProvince.Id;
candidate.RegistProvinceName = registProvince.Name;
}
if (updated.RegistDistrictId != null)
{
var registDistrict = await _context.Districts.AsQueryable()
var registDistrict = await _contextMetadata.Districts.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.RegistDistrictId));
if (registDistrict == null)
throw new Exception(GlobalMessages.DistrictNotFound);
candidate.RegistDistrict = registDistrict;
candidate.RegistDistrictId = registDistrict.Id;
candidate.RegistDistrictName = registDistrict.Name;
}
if (updated.RegistSubDistrictId != null)
{
var registSubDistrict = await _context.SubDistricts.AsQueryable()
var registSubDistrict = await _contextMetadata.SubDistricts.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.RegistSubDistrictId));
if (registSubDistrict == null)
throw new Exception(GlobalMessages.SubDistrictNotFound);
candidate.RegistSubDistrict = registSubDistrict;
candidate.RegistSubDistrictId = registSubDistrict.Id;
candidate.RegistSubDistrictName = registSubDistrict.Name;
candidate.RegistZipCode = registSubDistrict.ZipCode;
}
if (updated.CurrentProvinceId != null)
{
var currentProvince = await _context.Provinces.AsQueryable()
var currentProvince = await _contextMetadata.Provinces.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.CurrentProvinceId));
if (currentProvince == null)
throw new Exception(GlobalMessages.ProvinceNotFound);
candidate.CurrentProvince = currentProvince;
candidate.CurrentProvinceId = currentProvince.Id;
candidate.CurrentProvinceName = currentProvince.Name;
}
if (updated.CurrentDistrictId != null)
{
var currentDistrict = await _context.Districts.AsQueryable()
var currentDistrict = await _contextMetadata.Districts.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.CurrentDistrictId));
if (currentDistrict == null)
throw new Exception(GlobalMessages.DistrictNotFound);
candidate.CurrentDistrict = currentDistrict;
candidate.CurrentDistrictId = currentDistrict.Id;
candidate.CurrentDistrictName = currentDistrict.Name;
}
if (updated.CurrentSubDistrictId != null)
{
var currentSubDistrict = await _context.SubDistricts.AsQueryable()
var currentSubDistrict = await _contextMetadata.SubDistricts.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.CurrentSubDistrictId));
if (currentSubDistrict == null)
throw new Exception(GlobalMessages.SubDistrictNotFound);
candidate.CurrentSubDistrict = currentSubDistrict;
candidate.CurrentSubDistrictId = currentSubDistrict.Id;
candidate.CurrentSubDistrictName = currentSubDistrict.Name;
candidate.CurrentZipCode = currentSubDistrict.ZipCode;
}
@ -1002,35 +1014,38 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (updated.MarryPrefixId != null)
{
var prefix = await _context.Prefixes.AsQueryable()
var prefix = await _contextMetadata.Prefixes.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.MarryPrefixId));
if (prefix == null)
throw new Exception(GlobalMessages.PrefixNotFound);
candidate.MarryPrefix = prefix;
candidate.MarryPrefixId = prefix.Id;
candidate.MarryPrefixName = prefix.Name;
}
if (updated.FatherPrefixId != null)
{
var prefix = await _context.Prefixes.AsQueryable()
var prefix = await _contextMetadata.Prefixes.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.FatherPrefixId));
if (prefix == null)
throw new Exception(GlobalMessages.PrefixNotFound);
candidate.FatherPrefix = prefix;
candidate.FatherPrefixId = prefix.Id;
candidate.FatherPrefixName = prefix.Name;
}
if (updated.MotherPrefixId != null)
{
var prefix = await _context.Prefixes.AsQueryable()
var prefix = await _contextMetadata.Prefixes.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.MotherPrefixId));
if (prefix == null)
throw new Exception(GlobalMessages.PrefixNotFound);
candidate.MotherPrefix = prefix;
candidate.MotherPrefixId = prefix.Id;
candidate.MotherPrefixName = prefix.Name;
}
candidate.Marry = updated.Marry == null ? null : updated.Marry;
@ -1155,7 +1170,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
var candidate = await _context.Candidates.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(candidateId));
var educationLevel = await _context.EducationLevels.AsQueryable()
var educationLevel = await _contextMetadata.EducationLevels.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.EducationLevelId));
if (educationLevel == null)
@ -1164,7 +1179,8 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
var education = new Education
{
Candidate = candidate,
EducationLevel = educationLevel,
EducationLevelId = educationLevel.Id,
EducationLevelName = educationLevel.Name,
Major = updated.Major,
Scores = updated.Scores,
Name = updated.Name,
@ -1224,13 +1240,14 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (education == null)
throw new Exception(GlobalMessages.EducationNotFound);
var educationLevel = await _context.EducationLevels.AsQueryable()
var educationLevel = await _contextMetadata.EducationLevels.AsQueryable()
.FirstOrDefaultAsync(x => x.Id == Guid.Parse(updated.EducationLevelId));
if (educationLevel == null)
throw new Exception(GlobalMessages.EducationLevelNotFound);
education.EducationLevel = educationLevel;
education.EducationLevelId = educationLevel.Id;
education.EducationLevelName = educationLevel.Name;
education.Major = updated.Major;
education.Scores = updated.Scores;
education.Name = updated.Name;
@ -1416,7 +1433,6 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
throw new Exception(GlobalMessages.ExamNotFound);
var candidate = await _context.Candidates.AsQueryable()
.Include(x => x.Prefix)
.Where(x => x.PeriodExam == exam && x.UserId == UserId)
.FirstOrDefaultAsync();
@ -1429,7 +1445,6 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
throw new Exception(GlobalMessages.PositionExamNotFound);
candidate = await _context.Candidates.AsQueryable()
.Include(x => x.Prefix)
.Where(x => x.PeriodExam == exam && x.UserId == UserId && x.PositionExam == position)
.FirstOrDefaultAsync();
}
@ -1441,7 +1456,7 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
{
FirstName = candidate.FirstName,
LastName = candidate.LastName,
Prefix = candidate.Prefix?.Name,
Prefix = candidate.PrefixName,
CitizenId = candidate.CitizenId,
ExamIdenNumber = candidate.ExamIdenNumber,
SeatNumber = candidate.SeatNumber,

View file

@ -1,101 +0,0 @@
using System.Security.Claims;
using BMA.EHR.Recurit.Exam.Service.Data;
using BMA.EHR.Recurit.Exam.Service.Models;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Recurit.Exam.Service.Services
{
public class DistrictService
{
#region " Fields "
private readonly ApplicationDbContext _context;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
#region " Constructor and Destructor "
public DistrictService(ApplicationDbContext context,
IHttpContextAccessor httpContextAccessor)
{
_context = context;
_httpContextAccessor = httpContextAccessor;
}
#endregion
#region " Properties "
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
#endregion
#region " Methods "
public async Task<IEnumerable<District>> GetsAsync(string provinceId, bool showAll = true)
{
if (showAll)
return await _context.Districts.AsQueryable()
.Where(x => x.Province.Id == Guid.Parse(provinceId))
.OrderBy(d => d.Name)
.ToListAsync();
else
return await _context.Districts.AsQueryable()
.Where(x => x.Province.Id == Guid.Parse(provinceId))
.Where(p => p.IsActive)
.OrderBy(d => d.Name)
.ToListAsync();
}
public async Task<District?> GetByIdAsync(Guid id)
{
return await _context.Districts.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task UpdateAsync(Guid id, District updated)
{
var existData = await _context.Districts.FirstOrDefaultAsync(x => x.Id == id);
if (existData != null)
{
if (existData.Name != updated.Name)
{
existData.Name = updated.Name;
existData.LastUpdatedAt = DateTime.Now;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
}
if (existData.IsActive != updated.IsActive)
{
existData.IsActive = updated.IsActive;
existData.LastUpdatedAt = DateTime.Now;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
}
await _context.SaveChangesAsync();
}
}
public async Task CreateAsync(District inserted, string provinceId)
{
var province = await _context.Provinces.FirstOrDefaultAsync(x => x.Id == Guid.Parse(provinceId));
inserted.CreatedUserId = UserId ?? "";
inserted.CreatedFullName = FullName ?? "System Administrator";
inserted.CreatedAt = DateTime.Now;
inserted.LastUpdatedAt = DateTime.Now;
inserted.LastUpdateFullName = FullName ?? "System Administrator";
inserted.LastUpdateUserId = UserId ?? "";
inserted.Province = province;
await _context.Districts.AddAsync(inserted);
await _context.SaveChangesAsync();
}
#endregion
}
}

View file

@ -1,98 +0,0 @@
using System.Security.Claims;
using BMA.EHR.Recurit.Exam.Service.Data;
using BMA.EHR.Recurit.Exam.Service.Models;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Recurit.Exam.Service.Services
{
public class EducationLevelService
{
#region " Fields "
private readonly ApplicationDbContext _context;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
#region " Constructor and Destructor "
public EducationLevelService(ApplicationDbContext context,
IHttpContextAccessor httpContextAccessor)
{
_context = context;
_httpContextAccessor = httpContextAccessor;
}
#endregion
#region " Properties "
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
#endregion
#region " Methods "
public async Task<IEnumerable<EducationLevel>> GetsAsync(bool showAll = true)
{
if (showAll)
return await _context.EducationLevels.AsQueryable()
.OrderBy(d => d.Name)
.ToListAsync();
else
return await _context.EducationLevels.AsQueryable()
.Where(p => p.IsActive)
.OrderBy(d => d.Name)
.ToListAsync();
}
public async Task<EducationLevel?> GetByIdAsync(Guid id)
{
return await _context.EducationLevels.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task UpdateAsync(Guid id, EducationLevel updated)
{
var existData = await _context.EducationLevels.FirstOrDefaultAsync(x => x.Id == id);
if (existData != null)
{
if (existData.Name != updated.Name)
{
existData.Name = updated.Name;
existData.LastUpdatedAt = DateTime.Now;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
}
if (existData.IsActive != updated.IsActive)
{
existData.IsActive = updated.IsActive;
existData.LastUpdatedAt = DateTime.Now;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
}
await _context.SaveChangesAsync();
}
}
public async Task CreateAsync(EducationLevel inserted)
{
inserted.CreatedUserId = UserId ?? "";
inserted.CreatedFullName = FullName ?? "System Administrator";
inserted.CreatedAt = DateTime.Now;
inserted.LastUpdatedAt = DateTime.Now;
inserted.LastUpdateFullName = FullName ?? "System Administrator";
inserted.LastUpdateUserId = UserId ?? "";
await _context.EducationLevels.AddAsync(inserted);
await _context.SaveChangesAsync();
}
#endregion
}
}

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 PeriodExamService(ApplicationDbContext context,
MetadataDbContext contextMetadata,
IHttpContextAccessor httpContextAccessor,
MinIOService minioService)
{
_context = context;
_contextMetadata = contextMetadata;
_httpContextAccessor = httpContextAccessor;
_minioService = minioService;
}
@ -530,15 +533,33 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
if (status == "all")
{
return await _context.Candidates.AsQueryable()
var candidate = await _context.Candidates.AsQueryable()
.Include(x => x.ProfileImg)
.Where(x => x.PeriodExam == periodExam && x.Status != "register" && x.Status != "rejectRegister")
.ToListAsync();
var i = 0;
foreach (var item in candidate)
{
if (candidate[i].ProfileImg != null)
candidate[i].ProfileImg.Detail = _minioService.ImagesPath(candidate[i].ProfileImg.Id).Result;
i++;
}
return candidate;
}
else
{
return await _context.Candidates.AsQueryable()
var candidate = await _context.Candidates.AsQueryable()
.Include(x => x.ProfileImg)
.Where(x => x.PeriodExam == periodExam && x.Status == status)
.ToListAsync();
var i = 0;
foreach (var item in candidate)
{
if (candidate[i].ProfileImg != null)
candidate[i].ProfileImg.Detail = _minioService.ImagesPath(candidate[i].ProfileImg.Id).Result;
i++;
}
return candidate;
}
}
@ -548,18 +569,18 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
.Where(x => x.Id == Guid.Parse(candidateId))
.Select(x => new CandidateInformationResponseItem
{
Prefix = x.Prefix,
PrefixId = x.Prefix != null ? x.Prefix.Id.ToString() : null,
Prefix = x.PrefixName,
PrefixId = x.PrefixId != null ? x.PrefixId.ToString() : null,
FirstName = x.FirstName,
LastName = x.LastName,
Nationality = x.Nationality,
DateOfBirth = x.DateOfBirth,
Relationship = x.Relationship,
RelationshipId = x.Relationship != null ? x.Relationship.Id.ToString() : null,
CitizenProvince = x.CitizenProvince,
CitizenProvinceId = x.CitizenProvince != null ? x.CitizenProvince.Id.ToString() : null,
CitizenDistrict = x.CitizenDistrict,
CitizenDistrictId = x.CitizenDistrict != null ? x.CitizenDistrict.Id.ToString() : null,
Relationship = x.RelationshipName,
RelationshipId = x.RelationshipId != null ? x.RelationshipId.ToString() : null,
CitizenProvince = x.CitizenProvinceName,
CitizenProvinceId = x.CitizenProvinceId != null ? x.CitizenProvinceId.ToString() : null,
CitizenDistrict = x.CitizenDistrictName,
CitizenDistrictId = x.CitizenDistrictId != null ? x.CitizenDistrictId.ToString() : null,
CitizenDate = x.CitizenDate,
Email = x.Email,
CitizenId = x.CitizenId,
@ -602,21 +623,21 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
.Select(x => new CandidateAddressResponseItem
{
RegistAddress = x.RegistAddress,
RegistProvince = x.RegistProvince,
RegistProvinceId = x.RegistProvince != null ? x.RegistProvince.Id.ToString() : null,
RegistDistrict = x.RegistDistrict,
RegistDistrictId = x.RegistDistrict != null ? x.RegistDistrict.Id.ToString() : null,
RegistSubDistrict = x.RegistSubDistrict,
RegistSubDistrictId = x.RegistSubDistrict != null ? x.RegistSubDistrict.Id.ToString() : null,
RegistProvince = x.RegistProvinceName,
RegistProvinceId = x.RegistProvinceId != null ? x.RegistProvinceId.ToString() : null,
RegistDistrict = x.RegistDistrictName,
RegistDistrictId = x.RegistDistrictId != null ? x.RegistDistrictId.ToString() : null,
RegistSubDistrict = x.RegistSubDistrictName,
RegistSubDistrictId = x.RegistSubDistrictId != null ? x.RegistSubDistrictId.ToString() : null,
RegistZipCode = x.RegistZipCode,
RegistSame = x.RegistSame,
CurrentAddress = x.CurrentAddress,
CurrentProvince = x.CurrentProvince,
CurrentProvinceId = x.CurrentProvince != null ? x.CurrentProvince.Id.ToString() : null,
CurrentDistrict = x.CurrentDistrict,
CurrentDistrictId = x.CurrentDistrict != null ? x.CurrentDistrict.Id.ToString() : null,
CurrentSubDistrict = x.CurrentSubDistrict,
CurrentSubDistrictId = x.CurrentSubDistrict != null ? x.CurrentSubDistrict.Id.ToString() : null,
CurrentProvince = x.CurrentProvinceName,
CurrentProvinceId = x.CurrentProvinceId != null ? x.CurrentProvinceId.ToString() : null,
CurrentDistrict = x.CurrentDistrictName,
CurrentDistrictId = x.CurrentDistrictId != null ? x.CurrentDistrictId.ToString() : null,
CurrentSubDistrict = x.CurrentSubDistrictName,
CurrentSubDistrictId = x.CurrentSubDistrictId != null ? x.CurrentSubDistrictId.ToString() : null,
CurrentZipCode = x.CurrentZipCode,
})
.FirstOrDefaultAsync();
@ -629,20 +650,20 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
.Select(x => new CandidateFamilyResponseItem
{
Marry = x.Marry,
MarryPrefix = x.MarryPrefix,
MarryPrefixId = x.MarryPrefix != null ? x.MarryPrefix.Id.ToString() : null,
MarryPrefix = x.MarryPrefixName,
MarryPrefixId = x.MarryPrefixId != null ? x.MarryPrefixId.ToString() : null,
MarryFirstName = x.MarryFirstName,
MarryLastName = x.MarryLastName,
MarryOccupation = x.MarryOccupation,
MarryNationality = x.MarryNationality,
FatherPrefix = x.FatherPrefix,
FatherPrefixId = x.FatherPrefix != null ? x.FatherPrefix.Id.ToString() : null,
FatherPrefix = x.FatherPrefixName,
FatherPrefixId = x.FatherPrefixId != null ? x.FatherPrefixId.ToString() : null,
FatherFirstName = x.FatherFirstName,
FatherLastName = x.FatherLastName,
FatherOccupation = x.FatherOccupation,
FatherNationality = x.FatherNationality,
MotherPrefix = x.MotherPrefix,
MotherPrefixId = x.MotherPrefix != null ? x.MotherPrefix.Id.ToString() : null,
MotherPrefix = x.MotherPrefixName,
MotherPrefixId = x.MotherPrefixId != null ? x.MotherPrefixId.ToString() : null,
MotherFirstName = x.MotherFirstName,
MotherLastName = x.MotherLastName,
MotherOccupation = x.MotherOccupation,
@ -654,7 +675,6 @@ namespace BMA.EHR.Recurit.Exam.Service.Services
public async Task<IEnumerable<Education?>> GetsAsyncEducation(string candidateId)
{
return await _context.Educations.AsQueryable()
.Include(x => x.EducationLevel)
.Where(x => x.Id == Guid.Parse(candidateId))
.OrderBy(d => d.DurationStart)
.ToListAsync();

View file

@ -1,98 +0,0 @@
using BMA.EHR.Recurit.Exam.Service.Data;
using BMA.EHR.Recurit.Exam.Service.Models;
using Microsoft.EntityFrameworkCore;
using System.Security.Claims;
namespace BMA.EHR.Recurit.Exam.Service.Services
{
public class PrefixService
{
#region " Fields "
private readonly ApplicationDbContext _context;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
#region " Constructor and Destructor "
public PrefixService(ApplicationDbContext context,
IHttpContextAccessor httpContextAccessor)
{
_context = context;
_httpContextAccessor = httpContextAccessor;
}
#endregion
#region " Properties "
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
#endregion
#region " Methods "
public async Task<IEnumerable<Prefix>> GetsAsync(bool showAll = true)
{
if (showAll)
return await _context.Prefixes.AsQueryable()
.OrderBy(d => d.Name)
.ToListAsync();
else
return await _context.Prefixes.AsQueryable()
.Where(p => p.IsActive)
.OrderBy(d => d.Name)
.ToListAsync();
}
public async Task<Prefix?> GetByIdAsync(Guid id)
{
return await _context.Prefixes.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task UpdateAsync(Guid id, Prefix updated)
{
var existData = await _context.Prefixes.FirstOrDefaultAsync(x => x.Id == id);
if (existData != null)
{
if (existData.Name != updated.Name)
{
existData.Name = updated.Name;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
existData.LastUpdatedAt = DateTime.Now;
}
if (existData.IsActive != updated.IsActive)
{
existData.IsActive = updated.IsActive;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
existData.LastUpdatedAt = DateTime.Now;
}
await _context.SaveChangesAsync();
}
}
public async Task CreateAsync(Prefix inserted)
{
inserted.CreatedUserId = UserId ?? "";
inserted.CreatedFullName = FullName ?? "System Administrator";
inserted.CreatedAt = DateTime.Now;
inserted.LastUpdatedAt = DateTime.Now;
inserted.LastUpdateFullName = FullName ?? "System Administrator";
inserted.LastUpdateUserId = UserId ?? "";
await _context.Prefixes.AddAsync(inserted);
await _context.SaveChangesAsync();
}
#endregion
}
}

View file

@ -1,98 +0,0 @@
using BMA.EHR.Recurit.Exam.Service.Data;
using BMA.EHR.Recurit.Exam.Service.Models;
using Microsoft.EntityFrameworkCore;
using System.Security.Claims;
namespace BMA.EHR.Recurit.Exam.Service.Services
{
public class ProvinceService
{
#region " Fields "
private readonly ApplicationDbContext _context;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
#region " Constructor and Destructor "
public ProvinceService(ApplicationDbContext context,
IHttpContextAccessor httpContextAccessor)
{
_context = context;
_httpContextAccessor = httpContextAccessor;
}
#endregion
#region " Properties "
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
#endregion
#region " Methods "
public async Task<IEnumerable<Province>> GetsAsync(bool showAll = true)
{
if (showAll)
return await _context.Provinces.AsQueryable()
.OrderBy(d => d.Name)
.ToListAsync();
else
return await _context.Provinces.AsQueryable()
.Where(p => p.IsActive)
.OrderBy(d => d.Name)
.ToListAsync();
}
public async Task<Province?> GetByIdAsync(Guid id)
{
return await _context.Provinces.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task UpdateAsync(Guid id, Province updated)
{
var existData = await _context.Provinces.FirstOrDefaultAsync(x => x.Id == id);
if (existData != null)
{
if (existData.Name != updated.Name)
{
existData.Name = updated.Name;
existData.LastUpdatedAt = DateTime.Now;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
}
if (existData.IsActive != updated.IsActive)
{
existData.IsActive = updated.IsActive;
existData.LastUpdatedAt = DateTime.Now;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
}
await _context.SaveChangesAsync();
}
}
public async Task CreateAsync(Province inserted)
{
inserted.CreatedUserId = UserId ?? "";
inserted.CreatedFullName = FullName ?? "System Administrator";
inserted.CreatedAt = DateTime.Now;
inserted.LastUpdatedAt = DateTime.Now;
inserted.LastUpdateFullName = FullName ?? "System Administrator";
inserted.LastUpdateUserId = UserId ?? "";
await _context.Provinces.AddAsync(inserted);
await _context.SaveChangesAsync();
}
#endregion
}
}

View file

@ -1,97 +0,0 @@
using System.Security.Claims;
using BMA.EHR.Recurit.Exam.Service.Data;
using BMA.EHR.Recurit.Exam.Service.Models;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Recurit.Exam.Service.Services;
public class RelationshipService
{
#region " Fields "
private readonly ApplicationDbContext _context;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
#region " Constructor and Destructor "
public RelationshipService(ApplicationDbContext context,
IHttpContextAccessor httpContextAccessor)
{
_context = context;
_httpContextAccessor = httpContextAccessor;
}
#endregion
#region " Properties "
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
#endregion
#region " Methods "
public async Task<IEnumerable<Relationship>> GetsAsync(bool showAll = true)
{
if (showAll)
return await _context.Relationships.AsQueryable()
.OrderBy(d => d.Name)
.ToListAsync();
else
return await _context.Relationships.AsQueryable()
.Where(p => p.IsActive)
.OrderBy(d => d.Name)
.ToListAsync();
}
public async Task<Relationship?> GetByIdAsync(Guid id)
{
return await _context.Relationships.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task UpdateAsync(Guid id, Relationship updated)
{
var existData = await _context.Relationships.FirstOrDefaultAsync(x => x.Id == id);
if (existData != null)
{
if (existData.Name != updated.Name)
{
existData.Name = updated.Name;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
existData.LastUpdatedAt = DateTime.Now;
}
if (existData.IsActive != updated.IsActive)
{
existData.IsActive = updated.IsActive;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
existData.LastUpdatedAt = DateTime.Now;
}
await _context.SaveChangesAsync();
}
}
public async Task CreateAsync(Relationship inserted)
{
inserted.CreatedUserId = UserId ?? "";
inserted.CreatedFullName = FullName ?? "System Administrator";
inserted.CreatedAt = DateTime.Now;
inserted.LastUpdatedAt = DateTime.Now;
inserted.LastUpdateFullName = FullName ?? "System Administrator";
inserted.LastUpdateUserId = UserId ?? "";
await _context.Relationships.AddAsync(inserted);
await _context.SaveChangesAsync();
}
#endregion
}

View file

@ -1,98 +0,0 @@
using System.Security.Claims;
using BMA.EHR.Recurit.Exam.Service.Data;
using BMA.EHR.Recurit.Exam.Service.Models;
using Microsoft.EntityFrameworkCore;
namespace BMA.EHR.Recurit.Exam.Service.Services
{
public class ReligionService
{
#region " Fields "
private readonly ApplicationDbContext _context;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
#region " Constructor and Destructor "
public ReligionService(ApplicationDbContext context,
IHttpContextAccessor httpContextAccessor)
{
_context = context;
_httpContextAccessor = httpContextAccessor;
}
#endregion
#region " Properties "
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
#endregion
#region " Methods "
public async Task<IEnumerable<Religion>> GetsAsync(bool showAll = true)
{
if (showAll)
return await _context.Religions.AsQueryable()
.OrderBy(d => d.Name)
.ToListAsync();
else
return await _context.Religions.AsQueryable()
.Where(p => p.IsActive)
.OrderBy(d => d.Name)
.ToListAsync();
}
public async Task<Religion?> GetByIdAsync(Guid id)
{
return await _context.Religions.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task UpdateAsync(Guid id, Religion updated)
{
var existData = await _context.Religions.FirstOrDefaultAsync(x => x.Id == id);
if (existData != null)
{
if (existData.Name != updated.Name)
{
existData.Name = updated.Name;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
existData.LastUpdatedAt = DateTime.Now;
}
if (existData.IsActive != updated.IsActive)
{
existData.IsActive = updated.IsActive;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
existData.LastUpdatedAt = DateTime.Now;
}
await _context.SaveChangesAsync();
}
}
public async Task CreateAsync(Religion inserted)
{
inserted.CreatedUserId = UserId ?? "";
inserted.CreatedFullName = FullName ?? "System Administrator";
inserted.CreatedAt = DateTime.Now;
inserted.LastUpdatedAt = DateTime.Now;
inserted.LastUpdateFullName = FullName ?? "System Administrator";
inserted.LastUpdateUserId = UserId ?? "";
await _context.Religions.AddAsync(inserted);
await _context.SaveChangesAsync();
}
#endregion
}
}

View file

@ -1,119 +0,0 @@
using System.Collections.Immutable;
using System.Security.Claims;
using BMA.EHR.Extensions;
using BMA.EHR.Recurit.Exam.Service.Data;
using BMA.EHR.Recurit.Exam.Service.Models;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
namespace BMA.EHR.Recurit.Exam.Service.Services
{
public class SubDistrictService
{
#region " Fields "
private readonly ApplicationDbContext _context;
private readonly IHttpContextAccessor _httpContextAccessor;
#endregion
#region " Constructor and Destructor "
public SubDistrictService(ApplicationDbContext context,
IHttpContextAccessor httpContextAccessor)
{
_context = context;
_httpContextAccessor = httpContextAccessor;
}
#endregion
#region " Properties "
private string? UserId => _httpContextAccessor?.HttpContext?.User?.FindFirst(ClaimTypes.NameIdentifier)?.Value;
private string? FullName => _httpContextAccessor?.HttpContext?.User?.FindFirst("name")?.Value;
#endregion
#region " Methods "
public async Task<IEnumerable<SubDistrict>> GetsAsync(string districtId, bool showAll = true)
{
if (showAll)
return await _context.SubDistricts.AsQueryable()
.Include(d => d.District)
.Where(x => x.District.Id == Guid.Parse(districtId))
.OrderBy(d => d.Name)
.ToListAsync();
else
return await _context.SubDistricts.AsQueryable()
.Include(d => d.District)
.Where(x => x.District.Id == Guid.Parse(districtId))
.Where(p => p.IsActive)
.OrderBy(d => d.Name)
.ToListAsync();
}
public async Task<SubDistrict?> GetByIdAsync(Guid id)
{
return await _context.SubDistricts.AsQueryable()
.Include(d => d.District)
.FirstOrDefaultAsync(x => x.Id == id);
}
public async Task UpdateAsync(Guid id, SubDistrict updated)
{
var existData = await _context.SubDistricts.FirstOrDefaultAsync(x => x.Id == id);
if (existData != null)
{
// if (!existData.Compare(updated))
// {
// existData.Name = updated.Name;
// existData.ZipCode = updated.ZipCode;
// existData.IsActive = updated.IsActive;
// existData.LastUpdatedAt = DateTime.Now;
// existData.LastUpdateUserId = UserId ?? "";
// existData.LastUpdateFullName = FullName ?? "";
// await _context.SaveChangesAsync();
// }
if (existData.Name != updated.Name || existData.ZipCode != updated.ZipCode)
{
existData.Name = updated.Name;
existData.ZipCode = updated.ZipCode;
existData.LastUpdatedAt = DateTime.Now;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
}
if (existData.IsActive != updated.IsActive)
{
existData.IsActive = updated.IsActive;
existData.LastUpdatedAt = DateTime.Now;
existData.LastUpdateUserId = UserId ?? "";
existData.LastUpdateFullName = FullName ?? "";
}
await _context.SaveChangesAsync();
}
}
public async Task CreateAsync(SubDistrict inserted, string districtId)
{
var district = await _context.Districts.FirstOrDefaultAsync(x => x.Id == Guid.Parse(districtId));
inserted.CreatedUserId = UserId ?? "";
inserted.CreatedFullName = FullName ?? "System Administrator";
inserted.CreatedAt = DateTime.Now;
inserted.LastUpdatedAt = DateTime.Now;
inserted.LastUpdateFullName = FullName ?? "System Administrator";
inserted.LastUpdateUserId = UserId ?? "";
inserted.District = district;
await _context.SubDistricts.AddAsync(inserted);
await _context.SaveChangesAsync();
}
#endregion
}
}