Seed the initial page content from page-content.json

This commit is contained in:
Francesco Lorenzo D'Amico
2026-09-11 13:43:05 +02:00
parent f1e5c3fb12
commit 0f05f663e7
3 changed files with 207 additions and 0 deletions
+31
View File
@@ -39,9 +39,40 @@ public static class SeedData
context.SaveChanges();
}
SeedPageContent(context);
}
}
/// <summary>
/// Legt den Startinhalt der Seite einmalig an. Der Startwert stammt aus
/// SeedData/page-content.json, damit die Seite nach der Umstellung optisch
/// unveraendert bleibt. Existiert die Zeile bereits, passiert nichts --
/// spaetere Aenderungen im Editor werden also nie ueberschrieben.
/// </summary>
private static void SeedPageContent(RazorPagesMovieContext context)
{
if (context.PageContent.Any())
{
return;
}
var path = Path.Combine(AppContext.BaseDirectory, "SeedData", "page-content.json");
if (!File.Exists(path))
{
return;
}
context.PageContent.Add(new PageContentEntity
{
Id = PageContentEntity.SingletonId,
Content = File.ReadAllBytes(path),
UpdatedAt = DateTime.UtcNow
});
context.SaveChanges();
}
private class AdminAccountSeed
{
public string Username { get; set; } = string.Empty;