This commit is contained in:
parent
e0adbb0b71
commit
e8681834f2
1 changed files with 14 additions and 18 deletions
|
|
@ -583,10 +583,8 @@ public class ImportBackgroundService : BackgroundService
|
|||
// Clear tracker to avoid stale references after BulkDelete (which bypasses EF tracking)
|
||||
_context.ChangeTracker.Clear();
|
||||
|
||||
// Add history record using Attach stub for navigation (no explicit FK property on model)
|
||||
var importStub = new RecruitImport { Id = rec_import_id };
|
||||
_context.Attach(importStub);
|
||||
_context.RecruitImportHistories.Add(new RecruitImportHistory
|
||||
// Add history record — set FK shadow property directly to avoid Attach side-effects
|
||||
var historyEntry = _context.RecruitImportHistories.Add(new RecruitImportHistory
|
||||
{
|
||||
Description = "นำเข้าข้อมูลผลคะแนนสอบ",
|
||||
CreatedAt = DateTime.Now,
|
||||
|
|
@ -595,24 +593,22 @@ public class ImportBackgroundService : BackgroundService
|
|||
LastUpdatedAt = DateTime.Now,
|
||||
LastUpdateUserId = job.UserId ?? "",
|
||||
LastUpdateFullName = job.FullName ?? "System Administrator",
|
||||
RecruitImport = importStub,
|
||||
});
|
||||
historyEntry.Property("RecruitImportId").CurrentValue = rec_import_id;
|
||||
|
||||
// get doc from minio
|
||||
var doc = await _minioService.UploadFileAsync(new DummyFormFile(job.ImportFile));
|
||||
var imported = new ScoreImport
|
||||
{
|
||||
Year = rec_import_year,
|
||||
RecruitImportId = rec_import_id,
|
||||
ImportFile = doc,
|
||||
CreatedAt = DateTime.Now,
|
||||
CreatedUserId = job.UserId ?? "",
|
||||
CreatedFullName = job.FullName ?? "System Administrator",
|
||||
LastUpdatedAt = DateTime.Now,
|
||||
LastUpdateUserId = job.UserId ?? "",
|
||||
LastUpdateFullName = job.FullName ?? "System Administrator",
|
||||
Scores = new List<RecruitScore>()
|
||||
};
|
||||
var imported = new ScoreImport();
|
||||
imported.Year = rec_import_year;
|
||||
imported.RecruitImportId = rec_import_id;
|
||||
imported.ImportFile = doc;
|
||||
imported.CreatedAt = DateTime.Now;
|
||||
imported.CreatedUserId = job.UserId ?? "";
|
||||
imported.CreatedFullName = job.FullName ?? "System Administrator";
|
||||
imported.LastUpdatedAt = DateTime.Now;
|
||||
imported.LastUpdateUserId = job.UserId ?? "";
|
||||
imported.LastUpdateFullName = job.FullName ?? "System Administrator";
|
||||
imported.Scores = new List<RecruitScore>();
|
||||
|
||||
// Save ScoreImport parent first to get its Id
|
||||
_context.ScoreImports.Add(imported);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue