Move some Utils functions to AppDbContext
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Elwig.Models;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Elwig.Helpers {
|
||||
public class AppDbContext : DbContext {
|
||||
@ -27,5 +29,27 @@ namespace Elwig.Helpers {
|
||||
optionsBuilder.UseLazyLoadingProxies();
|
||||
base.OnConfiguring(optionsBuilder);
|
||||
}
|
||||
|
||||
public async Task<bool> MgNrExists(int mgnr) {
|
||||
return await Members.FindAsync(mgnr) != null;
|
||||
}
|
||||
|
||||
public async Task<bool> VNrExists(int vnr) {
|
||||
return await Contracts.FindAsync(vnr) != null;
|
||||
}
|
||||
|
||||
public async Task<int> NextMgNr() {
|
||||
int c = await Members.Select(m => m.MgNr).MinAsync();
|
||||
(await Members.OrderBy(m => m.MgNr).Select(m => m.MgNr).ToListAsync())
|
||||
.ForEach(a => { if (a <= c + 100) c = a; });
|
||||
return c + 1;
|
||||
}
|
||||
|
||||
public async Task<int> NextVNr() {
|
||||
int c = await Contracts.Select(co => co.VNr).MinAsync();
|
||||
(await Contracts.OrderBy(co => co.VNr).Select(co => co.VNr).ToListAsync())
|
||||
.ForEach(a => { if (a <= c + 100) c = a; });
|
||||
return c + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user