AppDbContext: Move all calls to App.HintContextChange() outside of any AppDbContext block
All checks were successful
Test / Run tests (push) Successful in 2m44s

This commit is contained in:
2024-09-05 17:21:00 +02:00
parent 7437187630
commit 8d9172f91e
6 changed files with 180 additions and 169 deletions

View File

@ -100,39 +100,40 @@ namespace Elwig.Services {
}
public static async Task<int> UpdateAreaCommitment(this AreaComAdminViewModel vm, int? oldFbNr) {
using var ctx = new AppDbContext();
int newFbNr = (int)vm.FbNr!;
var a = new AreaCom {
FbNr = oldFbNr ?? newFbNr,
MgNr = (int)vm.MgNr!,
YearFrom = (int)vm.YearFrom!,
YearTo = vm.YearTo,
VtrgId = vm.AreaComType!.VtrgId,
CultId = vm.WineCult?.CultId,
Comment = string.IsNullOrEmpty(vm.Comment) ? null : vm.Comment,
KgNr = vm.Kg!.KgNr,
RdNr = vm.Rd?.RdNr,
GstNr = vm.GstNr!.Trim(),
Area = (int)vm.Area!,
};
using (var ctx = new AppDbContext()) {
var a = new AreaCom {
FbNr = oldFbNr ?? newFbNr,
MgNr = (int)vm.MgNr!,
YearFrom = (int)vm.YearFrom!,
YearTo = vm.YearTo,
VtrgId = vm.AreaComType!.VtrgId,
CultId = vm.WineCult?.CultId,
Comment = string.IsNullOrEmpty(vm.Comment) ? null : vm.Comment,
KgNr = vm.Kg!.KgNr,
RdNr = vm.Rd?.RdNr,
GstNr = vm.GstNr!.Trim(),
Area = (int)vm.Area!,
};
if (vm.Rd?.RdNr == 0) {
vm.Rd.RdNr = await ctx.NextRdNr(a.KgNr);
a.RdNr = vm.Rd.RdNr;
ctx.Add(vm.Rd);
}
if (vm.Rd?.RdNr == 0) {
vm.Rd.RdNr = await ctx.NextRdNr(a.KgNr);
a.RdNr = vm.Rd.RdNr;
ctx.Add(vm.Rd);
}
if (oldFbNr != null) {
ctx.Update(a);
} else {
ctx.Add(a);
}
if (oldFbNr != null) {
ctx.Update(a);
} else {
ctx.Add(a);
}
await ctx.SaveChangesAsync();
await ctx.SaveChangesAsync();
if (newFbNr != a.FbNr) {
await ctx.Database.ExecuteSqlAsync($"UPDATE area_commitment SET fbnr = {newFbNr} WHERE fbnr = {oldFbNr}");
if (newFbNr != a.FbNr) {
await ctx.Database.ExecuteSqlAsync($"UPDATE area_commitment SET fbnr = {newFbNr} WHERE fbnr = {oldFbNr}");
}
}
await App.HintContextChange();