[#82] BaseDataWindow: Fixed error handling after first error to allow saving changes
Test / Run tests (push) Successful in 2m8s

This commit is contained in:
2026-08-03 14:18:20 +02:00
parent cfabf99c99
commit e6712732cd
6 changed files with 89 additions and 87 deletions
+16 -16
View File
@@ -48,30 +48,30 @@ namespace Elwig.Windows {
if (!_modChanged || _modList == null || _mods == null || _modIds == null)
return;
var year = (SeasonList.SelectedItem as Season)?.Year;
int i = 0;
foreach (var mod in _modList) mod.Ordering = ++i;
var year = (SeasonList.SelectedItem as Season)?.Year;
foreach (var (modid, _) in _mods.Where(m => m.Value == null)) {
ctx.Remove(ctx.Modifiers.Find(year, modid)!);
}
foreach (var (mod, old) in _modIds) {
mod.ModId = old;
}
foreach (var (old, modid) in _mods.Where(m => m.Value != null)) {
ctx.Update(ctx.Modifiers.Find(year, old)!);
}
await ctx.SaveChangesAsync();
// delete
var deleteModIds = _mods.Where(b => b.Value == null).Select(b => b.Key).ToList();
await ctx.Modifiers.Where(b => b.Year == year && deleteModIds.Contains(b.ModId)).ExecuteDeleteAsync();
// update
ctx.UpdateRange(_modList
.Where(_modIds.ContainsKey)
.Select(m => {
m.ModId = _modIds[m];
ctx.Entry(m).State = EntityState.Added;
return m;
}));
await ctx.SaveChangesAsync();
foreach (var (old, modid) in _mods.Where(m => m.Value != null)) {
await ctx.Database.ExecuteSqlAsync($"UPDATE modifier SET modid = {modid} WHERE (year, modid) = ({year}, {old})");
}
await ctx.SaveChangesAsync();
foreach (var mod in _modList.Where(m => !_modIds.ContainsKey(m))) {
if (mod.ModId == null) continue;
await ctx.AddAsync(mod);
}
// insert
ctx.AddRange(_modList
.Where(m => !_modIds.ContainsKey(m) && m.ModId != null));
await ctx.SaveChangesAsync();
}