Make methods in Utils async

This commit is contained in:
2023-03-22 23:30:04 +01:00
parent 51b9dcbf41
commit 3318db42ba
2 changed files with 10 additions and 7 deletions

View File

@ -7,6 +7,7 @@ using System.Windows;
using System.Windows.Controls;
using System.Diagnostics;
using System.Windows.Controls.Primitives;
using Microsoft.EntityFrameworkCore;
namespace Elwig.Helpers {
public static class Utils {
@ -86,13 +87,14 @@ namespace Elwig.Helpers {
});
}
public static bool MgNrExists(AppDbContext ctx, int mgnr) {
return ctx.Members.Find(mgnr) != null;
public static async Task<bool> MgNrExists(AppDbContext ctx, int mgnr) {
return await ctx.Members.FindAsync(mgnr) != null;
}
public static int NextMgNr(AppDbContext ctx) {
int c = ctx.Members.Select(m => m.MgNr).Min();
ctx.Members.OrderBy(m => m.MgNr).Select(m => m.MgNr).ToList().ForEach(a => { if (a <= c + 100) c = a; });
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;
}
}