This commit is contained in:
parent
73b0db6b36
commit
e0adbb0b71
1 changed files with 18 additions and 5 deletions
|
|
@ -570,12 +570,23 @@ public class ImportBackgroundService : BackgroundService
|
|||
|
||||
if (rec_import == null) throw new Exception("RecruitImport not found");
|
||||
|
||||
if (rec_import.ScoreImport != null && rec_import.ScoreImport.Scores != null)
|
||||
var rec_import_id = rec_import.Id;
|
||||
var rec_import_year = rec_import.Year;
|
||||
var hasExistingScores = rec_import.ScoreImport != null && rec_import.ScoreImport.Scores != null;
|
||||
|
||||
if (hasExistingScores)
|
||||
{
|
||||
await _context.BulkDeleteAsync(rec_import.ScoreImport.Scores.ToList());
|
||||
var existingScores = rec_import.ScoreImport.Scores.ToList();
|
||||
await _context.BulkDeleteAsync(existingScores);
|
||||
}
|
||||
|
||||
rec_import.ImportHostories.Add(new RecruitImportHistory
|
||||
// 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
|
||||
{
|
||||
Description = "นำเข้าข้อมูลผลคะแนนสอบ",
|
||||
CreatedAt = DateTime.Now,
|
||||
|
|
@ -584,13 +595,15 @@ public class ImportBackgroundService : BackgroundService
|
|||
LastUpdatedAt = DateTime.Now,
|
||||
LastUpdateUserId = job.UserId ?? "",
|
||||
LastUpdateFullName = job.FullName ?? "System Administrator",
|
||||
RecruitImport = importStub,
|
||||
});
|
||||
|
||||
// get doc from minio
|
||||
var doc = await _minioService.UploadFileAsync(new DummyFormFile(job.ImportFile));
|
||||
var imported = new ScoreImport
|
||||
{
|
||||
Year = rec_import.Year,
|
||||
Year = rec_import_year,
|
||||
RecruitImportId = rec_import_id,
|
||||
ImportFile = doc,
|
||||
CreatedAt = DateTime.Now,
|
||||
CreatedUserId = job.UserId ?? "",
|
||||
|
|
@ -602,7 +615,7 @@ public class ImportBackgroundService : BackgroundService
|
|||
};
|
||||
|
||||
// Save ScoreImport parent first to get its Id
|
||||
rec_import.ScoreImport = imported;
|
||||
_context.ScoreImports.Add(imported);
|
||||
await _context.SaveChangesAsync();
|
||||
_context.ChangeTracker.Clear();
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue