Files
ApplianceRepair/DatabaseContext.cs

57 lines
2.1 KiB
C#
Raw Permalink Normal View History

2026-04-25 22:45:59 -05:00
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
2026-02-03 16:55:37 -06:00
namespace ApplianceRepair
{
2026-04-25 22:45:59 -05:00
public class DatabaseContext(DbContextOptions<DatabaseContext> options) : IdentityDbContext<IdentityUser>(options)
2026-02-03 16:55:37 -06:00
{
public DbSet<HomePageRecord> HomePage { get; set; }
public DbSet<ContentCardRecord> ContentCards { get; set; }
public DbSet<BusinessConfigRecord> BusinessConfig { get; set; }
2026-04-22 20:09:26 -05:00
public DbSet<RepairRequestRecord> RepairRequests { get; set; }
2026-04-25 13:14:08 -05:00
public DbSet<RepairRequestMediaRecord> 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();
}
}
}
2026-02-03 16:55:37 -06:00
}
}