using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity.EntityFrameworkCore; using Microsoft.EntityFrameworkCore; namespace ApplianceRepair { public class DatabaseContext(DbContextOptions options) : IdentityDbContext(options) { public DbSet HomePage { get; set; } public DbSet ContentCards { get; set; } public DbSet BusinessConfig { get; set; } public DbSet RepairRequests { get; set; } public DbSet RepairRequestMedia { get; set; } // Seed the data public static async Task Initialize(DatabaseContext context) { if (!context.BusinessConfig.Any()) { var config = Defaults.DefaultBusinessConfig; config.CreatedAt = DateTime.Now; config.UpdatedAt = DateTime.Now; await context.BusinessConfig.AddAsync(config); await context.SaveChangesAsync(); } if (!context.HomePage.Any()) { var home = Defaults.DefaultHomePageContent; home.CreatedAt = DateTime.Now; home.UpdatedAt = DateTime.Now; await context.HomePage.AddAsync(home); await context.SaveChangesAsync(); if (!context.ContentCards.Any()) { foreach (var card in Defaults.DefaultHomePageServiceCards) { card.CreatedAt = DateTime.Now; card.UpdatedAt = DateTime.Now; await context.ContentCards.AddAsync(card); } foreach (var card in Defaults.DefaultHomePageTrustCards) { card.CreatedAt = DateTime.Now; card.UpdatedAt = DateTime.Now; await context.ContentCards.AddAsync(card); } await context.SaveChangesAsync(); } } } } }