fix scoreimport
All checks were successful
Build & Deploy on Dev / build (push) Successful in 46s

This commit is contained in:
Suphonchai Phoonsawat 2026-05-19 17:02:53 +07:00
parent 13a8e309e7
commit cba16f25b9

View file

@ -572,12 +572,16 @@ public class ImportBackgroundService : BackgroundService
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;
var existingScoreImport = rec_import.ScoreImport;
if (hasExistingScores)
if (existingScoreImport != null)
{
var existingScores = rec_import.ScoreImport.Scores.ToList();
var existingScores = existingScoreImport.Scores?.ToList() ?? new List<RecruitScore>();
if (existingScores.Count > 0)
await _context.BulkDeleteAsync(existingScores);
// Also delete the ScoreImport row itself (has unique index on RecruitImportId)
_context.ChangeTracker.Clear();
await _context.BulkDeleteAsync(new List<ScoreImport> { existingScoreImport });
}
// Clear tracker to avoid stale references after BulkDelete (which bypasses EF tracking)