[#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
+17 -17
View File
@@ -47,26 +47,26 @@ namespace Elwig.Windows {
if (!_actChanged || _actList == null || _acts == null || _actIds == null)
return;
foreach (var (vtrgid, _) in _acts.Where(a => a.Value == null)) {
ctx.Remove(ctx.AreaCommitmentTypes.Find(vtrgid)!);
}
foreach (var (attr, old) in _actIds) {
attr.VtrgId = old;
}
foreach (var (old, vtrgid) in _acts.Where(a => a.Value != null)) {
ctx.Update(ctx.AreaCommitmentTypes.Find(old)!);
}
await ctx.SaveChangesAsync();
// delete
var delete = _acts.Where(a => a.Value == null).Select(a => a.Key).ToList();
await ctx.AreaCommitmentTypes.Where(v => delete.Contains(v.VtrgId)).ExecuteDeleteAsync();
foreach (var (old, vtrgid) in _acts.Where(a => a.Value != null)) {
// update
ctx.UpdateRange(_actList
.Where(_actIds.ContainsKey)
.Select(t => {
t.VtrgId = _actIds[t];
ctx.Entry(t).State = EntityState.Added;
return t;
}));
await ctx.SaveChangesAsync();
foreach (var (old, vtrgid) in _acts.Where(a => a.Value != null && a.Key != a.Value)) {
await ctx.Database.ExecuteSqlAsync($"UPDATE area_commitment_type SET vtrgid = {vtrgid} WHERE vtrgid = {old}");
}
await ctx.SaveChangesAsync();
foreach (var type in _actList.Where(a => !_actIds.ContainsKey(a))) {
if (type.VtrgId == null) continue;
ctx.Add(type);
}
// insert
ctx.AddRange(_actList
.Where(t => !_actIds.ContainsKey(t) && t.VtrgId != null));
await ctx.SaveChangesAsync();
}
@@ -125,7 +125,7 @@ namespace Elwig.Windows {
var id = AreaCommitmentTypeIdInput.Text;
if (old != null) _acts[old] = id;
attr.VtrgId = id;
attr.SortId = v?.SortId;
attr.SortId = v?.SortId ?? "";
attr.AttrId = a?.AttrId;
attr.MinKgPerHa = AreaCommitmentTypeMinKgPerHaInput.Text.Length > 0 ? int.Parse(AreaCommitmentTypeMinKgPerHaInput.Text) : null;
attr.PenaltyPerKg = AreaCommitmentTypePenaltyPerKgInput.Text.Length > 0 ? decimal.Parse(AreaCommitmentTypePenaltyPerKgInput.Text) : null;