[#82] BaseDataWindow: Fixed error handling after first error to allow saving changes
Test / Run tests (push) Successful in 2m8s
Test / Run tests (push) Successful in 2m8s
This commit is contained in:
@@ -41,25 +41,26 @@ namespace Elwig.Windows {
|
||||
if (!_branchChanged || _branchList == null || _branches == null || _branchIds == null)
|
||||
return;
|
||||
|
||||
// delete
|
||||
var deleteZwstIds = _branches.Where(b => b.Value == null).Select(b => b.Key).ToList();
|
||||
await ctx.Branches.Where(b => deleteZwstIds.Contains(b.ZwstId)).ExecuteDeleteAsync();
|
||||
|
||||
foreach (var (branch, old) in _branchIds) {
|
||||
branch.ZwstId = old;
|
||||
}
|
||||
foreach (var (old, zwstid) in _branches.Where(b => b.Value != null)) {
|
||||
ctx.Update(ctx.Branches.Find(old)!);
|
||||
}
|
||||
// update
|
||||
ctx.UpdateRange(_branchList
|
||||
.Where(_branchIds.ContainsKey)
|
||||
.Select(b => {
|
||||
b.ZwstId = _branchIds[b];
|
||||
ctx.Entry(b).State = EntityState.Added;
|
||||
return b;
|
||||
}));
|
||||
await ctx.SaveChangesAsync();
|
||||
|
||||
foreach (var (old, zwstid) in _branches.Where(b => b.Value != null)) {
|
||||
foreach (var (old, zwstid) in _branches.Where(b => b.Value != null && b.Key != b.Value)) {
|
||||
await ctx.Database.ExecuteSqlAsync($"UPDATE branch SET zwstid = {zwstid} WHERE zwstid = {old}");
|
||||
}
|
||||
|
||||
foreach (var branch in _branchList.Where(b => !_branchIds.ContainsKey(b))) {
|
||||
if (branch.ZwstId == null) continue;
|
||||
ctx.Add(branch);
|
||||
}
|
||||
// insert
|
||||
ctx.AddRange(_branchList
|
||||
.Where(b => !_branchIds.ContainsKey(b) && b.ZwstId != null));
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user