migrate + ปรับสอบแข่งขัน (#6)

Co-authored-by: harid <harid_pr61@live.rmutl.com>
This commit is contained in:
Harid Promsri 2025-10-16 17:35:59 +07:00 committed by GitHub
parent 9332086ee9
commit 6e9fb4b368
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 1839 additions and 110 deletions

View file

@ -1104,19 +1104,18 @@ namespace BMA.EHR.Recruit.Service.Controllers
r.LastName = workSheet?.Cells[row, 8]?.GetValue<string>() ?? ""; r.LastName = workSheet?.Cells[row, 8]?.GetValue<string>() ?? "";
r.Gendor = workSheet?.Cells[row, 98]?.GetValue<string>() ?? ""; r.Gendor = workSheet?.Cells[row, 98]?.GetValue<string>() ?? "";
r.National = workSheet?.Cells[row, 9]?.GetValue<string>() ?? ""; r.National = workSheet?.Cells[row, 9]?.GetValue<string>() ?? "";
r.Race = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? ""; r.Race = "";
r.Religion = workSheet?.Cells[row, 10]?.GetValue<string>() ?? ""; r.Religion = workSheet?.Cells[row, 10]?.GetValue<string>() ?? "";
r.DateOfBirth = !string.IsNullOrWhiteSpace(workSheet?.Cells[row, 11]?.GetValue<string>()) ? _recruitService.CheckDateTime(workSheet?.Cells[row, 11]?.GetValue<string>() ?? "", "dd/MM/yyyy") : DateTime.MinValue; r.DateOfBirth = !string.IsNullOrWhiteSpace(workSheet?.Cells[row, 11]?.GetValue<string>()) ? _recruitService.CheckDateTime(workSheet?.Cells[row, 11]?.GetValue<string>() ?? "", "dd/MM/yyyy") : null;
r.CitizenId = workSheet?.Cells[row, 12]?.GetValue<string>() ?? ""; r.CitizenId = workSheet?.Cells[row, 12]?.GetValue<string>() ?? "";
r.typeTest = workSheet?.Cells[row, 13]?.GetValue<string>() ?? ""; r.typeTest = workSheet?.Cells[row, 13]?.GetValue<string>() ?? "";
r.Marry = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? ""; r.Marry = "";
r.Isspecial = "N"; r.Isspecial = "N";
r.CitizenCardIssuer = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? ""; r.CitizenCardExpireDate = null;
r.CitizenCardExpireDate = Convert.ToDateTime(workSheet?.Cells[row, 9999]?.GetValue<string>().ToDateTime(DateTimeFormat.Ymd, "-")); r.ModifiedDate = null;
r.ApplyDate = !string.IsNullOrWhiteSpace(workSheet?.Cells[row, 87]?.GetValue<string>()) ? _recruitService.CheckDateTime(workSheet?.Cells[row, 87]?.GetValue<string>() ?? "", "dd/MM/yyyy") : DateTime.MinValue; r.ApplyDate = !string.IsNullOrWhiteSpace(workSheet?.Cells[row, 87]?.GetValue<string>()) ? _recruitService.CheckDateTime(workSheet?.Cells[row, 87]?.GetValue<string>() ?? "", "dd/MM/yyyy") : null;
r.PositionType = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? ""; r.PositionType = "";
r.PositionLevel = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? ""; r.PositionLevel = "";
r.CreatedAt = DateTime.Now; r.CreatedAt = DateTime.Now;
r.CreatedUserId = UserId ?? ""; r.CreatedUserId = UserId ?? "";
r.CreatedFullName = FullName ?? "System Administrator"; r.CreatedFullName = FullName ?? "System Administrator";
@ -1129,13 +1128,13 @@ namespace BMA.EHR.Recruit.Service.Controllers
{ {
Degree = workSheet?.Cells[row, 18]?.GetValue<string>() ?? "", Degree = workSheet?.Cells[row, 18]?.GetValue<string>() ?? "",
Major = workSheet?.Cells[row, 19]?.GetValue<string>() == "อื่น ๆ" ? workSheet?.Cells[row, 20]?.GetValue<string>() ?? "" : workSheet?.Cells[row, 19]?.GetValue<string>() ?? "", Major = workSheet?.Cells[row, 19]?.GetValue<string>() == "อื่น ๆ" ? workSheet?.Cells[row, 20]?.GetValue<string>() ?? "" : workSheet?.Cells[row, 19]?.GetValue<string>() ?? "",
MajorGroupId = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "", MajorGroupId = "",
MajorGroupName = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "", MajorGroupName = "",
University = workSheet?.Cells[row, 21]?.GetValue<string>() == "อื่น ๆ" ? workSheet?.Cells[row, 22]?.GetValue<string>() ?? "" : workSheet?.Cells[row, 21]?.GetValue<string>() ?? "", University = workSheet?.Cells[row, 21]?.GetValue<string>() == "อื่น ๆ" ? workSheet?.Cells[row, 22]?.GetValue<string>() ?? "" : workSheet?.Cells[row, 21]?.GetValue<string>() ?? "",
GPA = (double)workSheet?.Cells[row, 26]?.GetValue<double>(), GPA = (double)workSheet?.Cells[row, 26]?.GetValue<double>(),
Specialist = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "", Specialist = "",
HighDegree = workSheet?.Cells[row, 27]?.GetValue<string>() ?? "", HighDegree = workSheet?.Cells[row, 27]?.GetValue<string>() ?? "",
BachelorDate = !string.IsNullOrWhiteSpace(workSheet?.Cells[row, 25]?.GetValue<string>()) ? _recruitService.CheckDateTime(workSheet?.Cells[row, 11]?.GetValue<string>() ?? "", "dd/MM/yyyy") : DateTime.MinValue, BachelorDate = !string.IsNullOrWhiteSpace(workSheet?.Cells[row, 25]?.GetValue<string>()) ? _recruitService.CheckDateTime(workSheet?.Cells[row, 25]?.GetValue<string>() ?? "", "dd/MM/yyyy") : null,
CreatedAt = DateTime.Now, CreatedAt = DateTime.Now,
CreatedUserId = UserId ?? "", CreatedUserId = UserId ?? "",
CreatedFullName = FullName ?? "System Administrator", CreatedFullName = FullName ?? "System Administrator",
@ -1172,7 +1171,7 @@ namespace BMA.EHR.Recruit.Service.Controllers
Province = workSheet?.Cells[row, 56]?.GetValue<string>() ?? "", Province = workSheet?.Cells[row, 56]?.GetValue<string>() ?? "",
ZipCode = workSheet?.Cells[row, 57]?.GetValue<string>() ?? "", ZipCode = workSheet?.Cells[row, 57]?.GetValue<string>() ?? "",
Telephone = workSheet?.Cells[row, 58]?.GetValue<string>() ?? "", Telephone = workSheet?.Cells[row, 58]?.GetValue<string>() ?? "",
Mobile = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "", Mobile = "",
Address1 = $"{(workSheet?.Cells[row, 61]?.GetValue<string>() ?? "")} {(workSheet?.Cells[row, 62]?.GetValue<string>() ?? "")}", Address1 = $"{(workSheet?.Cells[row, 61]?.GetValue<string>() ?? "")} {(workSheet?.Cells[row, 62]?.GetValue<string>() ?? "")}",
Moo1 = workSheet?.Cells[row, 63]?.GetValue<string>() ?? "", Moo1 = workSheet?.Cells[row, 63]?.GetValue<string>() ?? "",
Soi1 = workSheet?.Cells[row, 64]?.GetValue<string>() ?? "", Soi1 = workSheet?.Cells[row, 64]?.GetValue<string>() ?? "",
@ -1215,21 +1214,21 @@ namespace BMA.EHR.Recruit.Service.Controllers
LastUpdateUserId = UserId ?? "", LastUpdateUserId = UserId ?? "",
LastUpdateFullName = FullName ?? "System Administrator" LastUpdateFullName = FullName ?? "System Administrator"
}); });
/*Comment ข้อมูลใบประกอบวิชาชีพ เพราะในไฟล์นำเข้ายังไม่มีคอลัมน์ที่ระบุข้อมูลส่วนนี้*/
// certificate //// certificate
r.Certificates.Add(new RecruitCertificate() //r.Certificates.Add(new RecruitCertificate()
{ //{
CertificateNo = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "", // CertificateNo = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "",
Description = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "", // Description = workSheet?.Cells[row, 9999]?.GetValue<string>() ?? "",
IssueDate = Convert.ToDateTime(workSheet?.Cells[row, 9999]?.GetValue<string>().ToDateTime(DateTimeFormat.Ymd, "-")), // IssueDate = Convert.ToDateTime(workSheet?.Cells[row, 9999]?.GetValue<string>().ToDateTime(DateTimeFormat.Ymd, "-")),
ExpiredDate = Convert.ToDateTime(workSheet?.Cells[row, 9999]?.GetValue<string>().ToDateTime(DateTimeFormat.Ymd, "-")), // ExpiredDate = Convert.ToDateTime(workSheet?.Cells[row, 9999]?.GetValue<string>().ToDateTime(DateTimeFormat.Ymd, "-")),
CreatedAt = DateTime.Now, // CreatedAt = DateTime.Now,
CreatedUserId = UserId ?? "", // CreatedUserId = UserId ?? "",
CreatedFullName = FullName ?? "System Administrator", // CreatedFullName = FullName ?? "System Administrator",
LastUpdatedAt = DateTime.Now, // LastUpdatedAt = DateTime.Now,
LastUpdateUserId = UserId ?? "", // LastUpdateUserId = UserId ?? "",
LastUpdateFullName = FullName ?? "System Administrator" // LastUpdateFullName = FullName ?? "System Administrator"
}); //});
r.RecruitImport = imported; r.RecruitImport = imported;
_context.Recruits.Add(r); _context.Recruits.Add(r);
@ -1980,13 +1979,8 @@ namespace BMA.EHR.Recruit.Service.Controllers
); );
} }
int total = await query.CountAsync(); // join กับ DisableScores ก่อน เพื่อ filter ตาม ExamStatus
var queryWithScores = query
query = query
.Skip((req.Page - 1) * req.PageSize)
.Take(req.PageSize);
var data = await query
.GroupJoin( .GroupJoin(
_context.RecruitScores.Include(x => x.ScoreImport), _context.RecruitScores.Include(x => x.ScoreImport),
rc => new { rc.RecruitImport!.Id, rc.ExamId }, rc => new { rc.RecruitImport!.Id, rc.ExamId },
@ -1995,49 +1989,78 @@ namespace BMA.EHR.Recruit.Service.Controllers
) )
.SelectMany( .SelectMany(
x => x.scores.DefaultIfEmpty(), x => x.scores.DefaultIfEmpty(),
(x, sr) => new (x, sr) => new { x.recruit, score = sr }
{ );
examID = x.recruit.ExamId,
profileID = x.recruit.CitizenId, // filter ตาม req.ExamResult
prefix = x.recruit.Prefix, if (!string.IsNullOrWhiteSpace(req.ExamResult))
fullName = $"{x.recruit.FirstName} {x.recruit.LastName}", {
dateOfBirth = x.recruit.DateOfBirth != null && x.recruit.DateOfBirth != DateTime.MinValue switch (req.ExamResult.ToLower())
? x.recruit.DateOfBirth.ToThaiShortDate() {
: "", case "missed_exam":
gender = x.recruit.Gendor, queryWithScores = queryWithScores.Where(x => x.score != null && x.score.ExamStatus == "ขส.");
degree = x.recruit.Educations.Any() ? x.recruit.Educations.First().Degree : "", break;
major = x.recruit.Educations.Any() ? x.recruit.Educations.First().Major : "", case "pass":
certificateNo = x.recruit.Certificates.Any() queryWithScores = queryWithScores.Where(x => x.score != null && x.score.ExamStatus == "ผ่าน");
? x.recruit.Certificates.First().CertificateNo ?? "" break;
: "", case "notpass":
certificateIssueDate = x.recruit.Certificates.Any() && x.recruit.Certificates.First().IssueDate != null && x.recruit.Certificates.First().IssueDate != DateTime.MinValue queryWithScores = queryWithScores.Where(x => x.score != null && x.score.ExamStatus == "ไม่ผ่าน");
? x.recruit.Certificates.First().IssueDate.ToThaiShortDate() break;
: "", }
examScore = sr == null ? 0.0 : sr.TotalScore, }
examResult = sr == null ? "" : sr.ExamStatus,
examAttribute = x.recruit.Certificates.Any() && x.recruit.Certificates.First().IssueDate != null // total count หลังกรอง
? _recruitService.CheckValidCertificate(x.recruit.Certificates.First().IssueDate, 5) int total = await queryWithScores.CountAsync();
? "มีคุณสมบัติ" : "ไม่มีคุณสมบัติ"
: "ไม่มีคุณสมบัติ", // pagination
remark = x.recruit.Remark, queryWithScores = queryWithScores
isSpecial = x.recruit.Isspecial == "Y" ? x.recruit.Isspecial : "", .Skip((req.Page - 1) * req.PageSize)
applyDate = x.recruit.ApplyDate != null && x.recruit.ApplyDate != DateTime.MinValue .Take(req.PageSize);
? x.recruit.ApplyDate.ToThaiShortDate()
: "", // mapping
university = x.recruit.Educations.Any() ? x.recruit.Educations.First().University : "", var data = await queryWithScores
position_name = x.recruit.PositionName, .Select(x => new
hddPosition = x.recruit.HddPosition, {
typeTest = x.recruit.typeTest, examID = x.recruit.ExamId,
position_level = x.recruit.PositionLevel, profileID = x.recruit.CitizenId,
position_type = x.recruit.PositionType, prefix = x.recruit.Prefix,
exam_name = x.recruit.RecruitImport!.Name, fullName = $"{x.recruit.FirstName} {x.recruit.LastName}",
exam_order = x.recruit.RecruitImport != null && x.recruit.RecruitImport.Order != null dateOfBirth = x.recruit.DateOfBirth.HasValue && x.recruit.DateOfBirth.Value != DateTime.MinValue
? x.recruit.RecruitImport.Order.ToString() ? x.recruit.DateOfBirth.Value.ToThaiShortDate()
: "", : "",
score_year = x.recruit.RecruitImport != null && x.recruit.RecruitImport.Year != null gender = x.recruit.Gendor,
? x.recruit.RecruitImport.Year.ToThaiYear().ToString() degree = x.recruit.Educations.Any() ? x.recruit.Educations.First().Degree : "",
: "", major = x.recruit.Educations.Any() ? x.recruit.Educations.First().Major : "",
}) certificateNo = x.recruit.Certificates.Any() ? x.recruit.Certificates.First().CertificateNo ?? "" : "",
certificateIssueDate = x.recruit.Certificates.Any() && x.recruit.Certificates.First().IssueDate != null && x.recruit.Certificates.First().IssueDate != DateTime.MinValue
? x.recruit.Certificates.First().IssueDate.ToThaiShortDate()
: "",
examScore = x.score == null ? 0.0 : x.score.TotalScore,
examResult = x.score == null ? "" : x.score.ExamStatus,
examAttribute = x.recruit.Certificates.Any() && x.recruit.Certificates.First().IssueDate != null
? _recruitService.CheckValidCertificate(x.recruit.Certificates.First().IssueDate, 5)
? "มีคุณสมบัติ" : "ไม่มีคุณสมบัติ"
: "ไม่มีคุณสมบัติ",
remark = x.recruit.Remark,
isSpecial = x.recruit.Isspecial == "Y" ? x.recruit.Isspecial : "",
applyDate = x.recruit.ApplyDate.HasValue && x.recruit.ApplyDate.Value != DateTime.MinValue
? x.recruit.ApplyDate.Value.ToThaiShortDate()
: "",
university = x.recruit.Educations.Any() ? x.recruit.Educations.First().University : "",
position_name = x.recruit.PositionName,
hddPosition = x.recruit.HddPosition ?? "",
typeTest = x.recruit.typeTest ?? "",
position_level = x.recruit.PositionLevel ?? "",
position_type = x.recruit.PositionType ?? "",
exam_name = x.recruit.RecruitImport!.Name,
exam_order = x.recruit.RecruitImport != null && x.recruit.RecruitImport.Order != null
? x.recruit.RecruitImport.Order.ToString()
: "",
score_year = x.recruit.RecruitImport != null && x.recruit.RecruitImport.Year != null
? (x.recruit.RecruitImport.Year > 2500 ? x.recruit.RecruitImport.Year : x.recruit.RecruitImport.Year + 543).ToString()
: "",
number = x.score == null ? "" : x.score.Number,
})
.ToListAsync(); .ToListAsync();
// --------------------------- // ---------------------------
@ -2133,10 +2156,8 @@ namespace BMA.EHR.Recruit.Service.Controllers
ProfileID = p.CitizenId, ProfileID = p.CitizenId,
p.Prefix, p.Prefix,
FullName = $"{p.FirstName} {p.LastName}", FullName = $"{p.FirstName} {p.LastName}",
DateOfBirth = p.DateOfBirth != null DateOfBirth = p.DateOfBirth.HasValue && p.DateOfBirth.Value != DateTime.MinValue
? p.DateOfBirth != DateTime.MinValue ? p.DateOfBirth.Value.ToThaiShortDate()
? p.DateOfBirth.ToThaiShortDate()
: ""
: "", : "",
Gender = p.Gendor, Gender = p.Gendor,
Degree = p.Educations.First().Degree, Degree = p.Educations.First().Degree,
@ -2852,10 +2873,8 @@ namespace BMA.EHR.Recruit.Service.Controllers
ExamID = p.ExamId != null ? p.ExamId.ToThaiNumber() : "", ExamID = p.ExamId != null ? p.ExamId.ToThaiNumber() : "",
CitizenId = p.CitizenId != null ? p.CitizenId.ToThaiNumber() : "", CitizenId = p.CitizenId != null ? p.CitizenId.ToThaiNumber() : "",
FullName = $"{p.Prefix}{p.FirstName} {p.LastName}", FullName = $"{p.Prefix}{p.FirstName} {p.LastName}",
DateOfBirth = p.DateOfBirth != null DateOfBirth = p.DateOfBirth.HasValue && p.DateOfBirth.Value != DateTime.MinValue
? p.DateOfBirth != DateTime.MinValue ? p.DateOfBirth.Value.ToThaiShortDate().ToThaiNumber()
? p.DateOfBirth.ToThaiShortDate().ToString().ToThaiNumber()
: ""
: "", : "",
Gender = p.Gendor, Gender = p.Gendor,
Degree = p.Educations.First().Degree, Degree = p.Educations.First().Degree,

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,109 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BMA.EHR.Recruit.Service.Migrations
{
/// <inheritdoc />
public partial class update_nullable : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<DateTime>(
name: "ModifiedDate",
table: "Recruits",
type: "datetime(6)",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "datetime(6)");
migrationBuilder.AlterColumn<DateTime>(
name: "DateOfBirth",
table: "Recruits",
type: "datetime(6)",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "datetime(6)");
migrationBuilder.AlterColumn<DateTime>(
name: "CitizenCardExpireDate",
table: "Recruits",
type: "datetime(6)",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "datetime(6)");
migrationBuilder.AlterColumn<DateTime>(
name: "ApplyDate",
table: "Recruits",
type: "datetime(6)",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "datetime(6)");
migrationBuilder.AlterColumn<DateTime>(
name: "BachelorDate",
table: "RecruitEducations",
type: "datetime(6)",
nullable: true,
oldClrType: typeof(DateTime),
oldType: "datetime(6)");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<DateTime>(
name: "ModifiedDate",
table: "Recruits",
type: "datetime(6)",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
oldClrType: typeof(DateTime),
oldType: "datetime(6)",
oldNullable: true);
migrationBuilder.AlterColumn<DateTime>(
name: "DateOfBirth",
table: "Recruits",
type: "datetime(6)",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
oldClrType: typeof(DateTime),
oldType: "datetime(6)",
oldNullable: true);
migrationBuilder.AlterColumn<DateTime>(
name: "CitizenCardExpireDate",
table: "Recruits",
type: "datetime(6)",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
oldClrType: typeof(DateTime),
oldType: "datetime(6)",
oldNullable: true);
migrationBuilder.AlterColumn<DateTime>(
name: "ApplyDate",
table: "Recruits",
type: "datetime(6)",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
oldClrType: typeof(DateTime),
oldType: "datetime(6)",
oldNullable: true);
migrationBuilder.AlterColumn<DateTime>(
name: "BachelorDate",
table: "RecruitEducations",
type: "datetime(6)",
nullable: false,
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
oldClrType: typeof(DateTime),
oldType: "datetime(6)",
oldNullable: true);
}
}
}

View file

@ -62,10 +62,10 @@ namespace BMA.EHR.Recruit.Service.Migrations
.HasComment("PrimaryKey") .HasComment("PrimaryKey")
.HasAnnotation("Relational:JsonPropertyName", "id"); .HasAnnotation("Relational:JsonPropertyName", "id");
b.Property<DateTime>("ApplyDate") b.Property<DateTime?>("ApplyDate")
.HasColumnType("datetime(6)"); .HasColumnType("datetime(6)");
b.Property<DateTime>("CitizenCardExpireDate") b.Property<DateTime?>("CitizenCardExpireDate")
.HasColumnType("datetime(6)"); .HasColumnType("datetime(6)");
b.Property<string>("CitizenCardIssuer") b.Property<string>("CitizenCardIssuer")
@ -101,7 +101,7 @@ namespace BMA.EHR.Recruit.Service.Migrations
.HasColumnOrder(101) .HasColumnOrder(101)
.HasComment("User Id ที่สร้างข้อมูล"); .HasComment("User Id ที่สร้างข้อมูล");
b.Property<DateTime>("DateOfBirth") b.Property<DateTime?>("DateOfBirth")
.HasColumnType("datetime(6)"); .HasColumnType("datetime(6)");
b.Property<string>("ExamId") b.Property<string>("ExamId")
@ -157,7 +157,7 @@ namespace BMA.EHR.Recruit.Service.Migrations
.HasMaxLength(20) .HasMaxLength(20)
.HasColumnType("varchar(20)"); .HasColumnType("varchar(20)");
b.Property<DateTime>("ModifiedDate") b.Property<DateTime?>("ModifiedDate")
.HasColumnType("datetime(6)"); .HasColumnType("datetime(6)");
b.Property<string>("National") b.Property<string>("National")
@ -512,7 +512,7 @@ namespace BMA.EHR.Recruit.Service.Migrations
.HasComment("PrimaryKey") .HasComment("PrimaryKey")
.HasAnnotation("Relational:JsonPropertyName", "id"); .HasAnnotation("Relational:JsonPropertyName", "id");
b.Property<DateTime>("BachelorDate") b.Property<DateTime?>("BachelorDate")
.HasColumnType("datetime(6)"); .HasColumnType("datetime(6)");
b.Property<DateTime>("CreatedAt") b.Property<DateTime>("CreatedAt")

View file

@ -33,8 +33,8 @@ namespace BMA.EHR.Recruit.Service.Models.Recruits
[MaxLength(200)] [MaxLength(200)]
public string Religion { get; set; } = string.Empty; public string Religion { get; set; } = string.Empty;
[Required] //[Required]
public DateTime DateOfBirth { get; set; } public DateTime? DateOfBirth { get; set; }
[MaxLength(20)] [MaxLength(20)]
public string Marry { get; set; } = string.Empty; public string Marry { get; set; } = string.Empty;
@ -48,7 +48,7 @@ namespace BMA.EHR.Recruit.Service.Models.Recruits
[MaxLength(200)] [MaxLength(200)]
public string CitizenCardIssuer { get; set; } = string.Empty; public string CitizenCardIssuer { get; set; } = string.Empty;
public DateTime CitizenCardExpireDate { get; set; } public DateTime? CitizenCardExpireDate { get; set; }
[MaxLength(200)] [MaxLength(200)]
public string Remark { get; set; } = string.Empty; public string Remark { get; set; } = string.Empty;
@ -72,9 +72,9 @@ namespace BMA.EHR.Recruit.Service.Models.Recruits
public DateTime CreatedDate { get; set; } = DateTime.Now; public DateTime CreatedDate { get; set; } = DateTime.Now;
public DateTime ModifiedDate { get; set; } public DateTime? ModifiedDate { get; set; }
public DateTime ApplyDate { get; set; } public DateTime? ApplyDate { get; set; }
public string? PositionName { get; set; } public string? PositionName { get; set; }
public string? PositionType { get; set; } public string? PositionType { get; set; }

View file

@ -26,7 +26,7 @@ namespace BMA.EHR.Recruit.Service.Models.Recruits
[MaxLength(200)] [MaxLength(200)]
public string HighDegree { get; set; } public string HighDegree { get; set; }
public DateTime BachelorDate { get; set; } public DateTime? BachelorDate { get; set; }
public Recruit Recruit { get; set; } public Recruit Recruit { get; set; }
} }

View file

@ -460,13 +460,13 @@ namespace BMA.EHR.Recruit.Service.Services
if (!string.IsNullOrWhiteSpace(road)) parts.Add($"ถนน {road}"); if (!string.IsNullOrWhiteSpace(road)) parts.Add($"ถนน {road}");
return string.Join(" ", parts); return string.Join(" ", parts);
} }
public DateTime CheckDateTime(string Date, string Formate) public DateTime? CheckDateTime(string Date, string Formate)
{ {
// ตอนนี้ทำไว้ให้รองรับแค่ "dd/MM/yyyy", "yyyy-MM-dd" // ตอนนี้ทำไว้ให้รองรับแค่ "dd/MM/yyyy", "yyyy-MM-dd"
Date = Date.Trim(); Date = Date.Trim();
if (string.IsNullOrWhiteSpace(Date)) if (string.IsNullOrWhiteSpace(Date))
return DateTime.MinValue; return null;
// จะเข้าเฉพาะกรณีที่ string เป็นตัวเลข เช่น "35635", "44561.5" // จะเข้าเฉพาะกรณีที่ string เป็นตัวเลข เช่น "35635", "44561.5"
if (double.TryParse(Date, out double oaDate)) if (double.TryParse(Date, out double oaDate))
@ -484,7 +484,7 @@ namespace BMA.EHR.Recruit.Service.Services
string[] parts = Date.Trim().Replace("-", "/").Split("/"); string[] parts = Date.Trim().Replace("-", "/").Split("/");
if (parts.Length != 3) if (parts.Length != 3)
return DateTime.MinValue; return null;
int year; int year;
int month; int month;
@ -498,14 +498,14 @@ namespace BMA.EHR.Recruit.Service.Services
} }
else if (!int.TryParse(parts[2], out year)) else if (!int.TryParse(parts[2], out year))
{ {
return DateTime.MinValue; return null;
} }
if (!int.TryParse(parts[1], out month)) if (!int.TryParse(parts[1], out month))
return DateTime.MinValue; return null;
if (!int.TryParse(parts[0], out day)) if (!int.TryParse(parts[0], out day))
return DateTime.MinValue; return null;
break; break;
@ -516,18 +516,18 @@ namespace BMA.EHR.Recruit.Service.Services
} }
else if (!int.TryParse(parts[0], out year)) else if (!int.TryParse(parts[0], out year))
{ {
return DateTime.MinValue; return null;
} }
if (!int.TryParse(parts[1], out month)) if (!int.TryParse(parts[1], out month))
return DateTime.MinValue; return null;
if (!int.TryParse(parts[2], out day)) if (!int.TryParse(parts[2], out day))
return DateTime.MinValue; return null;
break; break;
default: default:
return DateTime.MinValue; return null;
} }
if (month < 1 || month > 12) if (month < 1 || month > 12)
@ -540,13 +540,13 @@ namespace BMA.EHR.Recruit.Service.Services
else if (day > maxDay) else if (day > maxDay)
day = maxDay; day = maxDay;
var normalDate = $"{day}/{(month >= 1 && month <= 9 ? $"0{month}" : month)}/{year}"; var normalDate = $"{(day >= 1 && day <= 9 ? $"0{day}" : day)}/{(month >= 1 && month <= 9 ? $"0{month}" : month)}/{year}";
if (DateTime.TryParseExact(normalDate, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime parsedDate)) if (DateTime.TryParseExact(normalDate, "dd/MM/yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out DateTime parsedDate))
{ {
return parsedDate; return parsedDate;
} }
return DateTime.MinValue; return null;
} }
} }
} }