30 lines
864 B
C#
30 lines
864 B
C#
using BuchhaltungBlazor.Data;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace BuchhaltungBlazor.Services;
|
|
|
|
public static class GenericController {
|
|
private static readonly BookingDb db = new();
|
|
public static async Task<IList<TResult>?> GetAllAsync<TResult>() where TResult : class {
|
|
try {
|
|
return await db.Set<TResult>().ToListAsync();
|
|
}
|
|
catch (Exception exception) {
|
|
Console.WriteLine(exception);
|
|
return default;
|
|
}
|
|
}
|
|
|
|
public static void DeleteAndCreateDb() {
|
|
bool a = db.Database.EnsureDeleted();
|
|
bool b = db.Database.EnsureCreated();
|
|
Console.WriteLine($"deleted = {a}, created = {b}");
|
|
db.SaveChanges();
|
|
}
|
|
|
|
public static async Task Migrate() {
|
|
await db.Database.MigrateAsync();
|
|
await db.SaveChangesAsync();
|
|
}
|
|
|
|
} |