[#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,26 +41,28 @@ namespace Elwig.Windows {
|
||||
if (!_attrChanged || _attrList == null || _attrs == null || _attrIds == null)
|
||||
return;
|
||||
|
||||
// delete
|
||||
var deleteAttrIds = _attrs.Where(a => a.Value == null).Select(a => a.Key).ToList();
|
||||
await ctx.WineAttributes.Where(a => deleteAttrIds.Contains(a.AttrId)).ExecuteDeleteAsync();
|
||||
foreach (var (attr, old) in _attrIds) {
|
||||
attr.AttrId = old;
|
||||
}
|
||||
foreach (var (old, attrid) in _attrs.Where(a => a.Value != null)) {
|
||||
ctx.Update(ctx.WineAttributes.Find(old)!);
|
||||
}
|
||||
await ctx.SaveChangesAsync();
|
||||
|
||||
// update
|
||||
ctx.UpdateRange(_attrList
|
||||
.Where(_attrIds.ContainsKey)
|
||||
.Select(a => {
|
||||
a.AttrId = _attrIds[a];
|
||||
ctx.Entry(a).State = EntityState.Added;
|
||||
return a;
|
||||
}));
|
||||
await ctx.SaveChangesAsync();
|
||||
foreach (var (old, attrid) in _attrs.Where(a => a.Value != null)) {
|
||||
await ctx.Database.ExecuteSqlAsync($"UPDATE wine_attribute SET attrid = {attrid} WHERE attrid = {old}");
|
||||
await ctx.Database.ExecuteSqlAsync($"UPDATE area_commitment_type SET vtrgid = (sortid || COALESCE(attrid, '') || COALESCE(disc, '')) WHERE attrid = {attrid}");
|
||||
await ctx.Database.ExecuteSqlRawAsync($"UPDATE payment_variant SET data = REPLACE(REPLACE(data, '/{old}\"', '/{attrid}\"'), '/{old}-', '/{attrid}-')");
|
||||
await ctx.Database.ExecuteSqlAsync($"UPDATE payment_variant SET data = REPLACE(REPLACE(data, {$"/{old}\""}, {$"/{attrid}\""}), {$"/{old}-"}, {$"/{attrid}-"})");
|
||||
}
|
||||
|
||||
foreach (var attr in _attrList.Where(a => !_attrIds.ContainsKey(a))) {
|
||||
if (attr.AttrId == null) continue;
|
||||
ctx.Add(attr);
|
||||
}
|
||||
// insert
|
||||
ctx.AddRange(_attrList
|
||||
.Where(a => !_attrIds.ContainsKey(a) && a.AttrId != null));
|
||||
await ctx.SaveChangesAsync();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user