init
This commit is contained in:
28
OpenArchival.DataAccess/HomepageConfigurationSeeder.cs
Normal file
28
OpenArchival.DataAccess/HomepageConfigurationSeeder.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Runtime.InteropServices.Marshalling;
|
||||
|
||||
namespace OpenArchival.DataAccess;
|
||||
|
||||
public static class HomepageConfigurationSeeder
|
||||
{
|
||||
public static async Task SeedHomepageConfig(IServiceProvider serviceProvider)
|
||||
{
|
||||
var contextFactory = serviceProvider.GetRequiredService<IDbContextFactory<ApplicationDbContext>>();
|
||||
await using var context = await contextFactory.CreateDbContextAsync();
|
||||
|
||||
HomePageConfiguration? existingConfig = await context.HomePageConfiguration.FirstOrDefaultAsync();
|
||||
if (existingConfig == null)
|
||||
{
|
||||
var config = new HomePageConfiguration() {
|
||||
Content = "<p>No homepage content configured</p>",
|
||||
HomePageBanner = null,
|
||||
SliderEntries = null
|
||||
};
|
||||
|
||||
context.HomePageConfiguration.Add(config);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user