Move some Utils functions to AppDbContext

This commit is contained in:
2023-04-16 11:21:30 +02:00
parent d5b9af541f
commit 0333e8a5c5
5 changed files with 29 additions and 27 deletions

View File

@ -86,27 +86,5 @@ namespace Elwig.Helpers {
UseShellExecute = true,
});
}
public static async Task<bool> MgNrExists(AppDbContext ctx, int mgnr) {
return await ctx.Members.FindAsync(mgnr) != null;
}
public static async Task<bool> VNrExists(AppDbContext ctx, int vnr) {
return await ctx.Contracts.FindAsync(vnr) != null;
}
public static async Task<int> NextMgNr(AppDbContext ctx) {
int c = await ctx.Members.Select(m => m.MgNr).MinAsync();
(await ctx.Members.OrderBy(m => m.MgNr).Select(m => m.MgNr).ToListAsync())
.ForEach(a => { if (a <= c + 100) c = a; });
return c + 1;
}
public static async Task<int> NextVNr(AppDbContext ctx) {
int c = await ctx.Contracts.Select(co => co.VNr).MinAsync();
(await ctx.Contracts.OrderBy(co => co.VNr).Select(co => co.VNr).ToListAsync())
.ForEach(a => { if (a <= c + 100) c = a; });
return c + 1;
}
}
}