151 lines
5.8 KiB
C#
151 lines
5.8 KiB
C#
using BLAIzor.Models;
|
|
using Microsoft.AspNetCore.Identity;
|
|
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace BLAIzor.Data
|
|
{
|
|
public class ApplicationDbContext : IdentityDbContext
|
|
{
|
|
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
|
|
: base(options)
|
|
{
|
|
}
|
|
|
|
public DbSet<SiteInfo> SiteInfos { get; set; }
|
|
public DbSet<MenuItem> MenuItems { get; set; } // Add MenuItem DbSet
|
|
public DbSet<DesignTemplate> DesignTemplates { get; set; }
|
|
public DbSet<CssTemplate> CssTemplates { get; set; }
|
|
public DbSet<ContentGroup> ContentGroups { get; set; }
|
|
public DbSet<ContentItem> ContentItems { get; set; }
|
|
public DbSet<ContentChunk> ContentChunks { get; set; }
|
|
public DbSet<FormDefinition> FormDefinitions { get; set; }
|
|
public DbSet<AppLog> Logs { get; set; }
|
|
|
|
|
|
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
{
|
|
base.OnModelCreating(modelBuilder);
|
|
|
|
// SiteInfo configuration
|
|
|
|
|
|
modelBuilder.Entity<IdentityUser>().HasData(new IdentityUser
|
|
{
|
|
Id = "0988758e-e16c-4c2c-8c1e-efa3ac5f0274",
|
|
UserName = "adam.g@aycode.com",
|
|
NormalizedUserName = "ADAM.G@AYCODE.COM",
|
|
Email = "adam.g@aycode.com",
|
|
NormalizedEmail = "ADAM.G@AYCODE.COM",
|
|
EmailConfirmed = true,
|
|
//PasswordHash = new PasswordHasher<IdentityUser>().HashPassword(null, "Password123!"),
|
|
PasswordHash = "AQAAAAIAAYagAAAAEChxKCu+ReGvcZFR/6kPASbpnQdMp1MJuepeRyR4bfHTkUk8SfNAqmckGXvuw+GaGA==",
|
|
SecurityStamp = "7ecf121a-b0e7-4e30-a1f1-299eeaf0a9cc",
|
|
ConcurrencyStamp = "a2836246-0303-4370-b283-e53a9a3f2813"
|
|
});
|
|
|
|
modelBuilder.Entity<DesignTemplate>().HasData(new DesignTemplate
|
|
{
|
|
Id = 1,
|
|
UserId = "0988758e-e16c-4c2c-8c1e-efa3ac5f0274",
|
|
TemplateName = "Default Site",
|
|
TemplatePhotoUrl = "/images/default-logo.png",
|
|
Description = "The default template",
|
|
Tags = "system",
|
|
IsPrivate = false,
|
|
IsPublished = false,
|
|
Status = "Draft",
|
|
QDrandCollectionName = "html_snippets"
|
|
});
|
|
|
|
|
|
|
|
modelBuilder.Entity<SiteInfo>().HasData(new SiteInfo
|
|
{
|
|
Id = 1,
|
|
UserId = "0988758e-e16c-4c2c-8c1e-efa3ac5f0274",
|
|
SiteName = "Default Site",
|
|
BrandLogoUrl = "/images/default-logo.png",
|
|
DefaultColor = "#FFFFFF",
|
|
DomainUrl = "poppixel.cloud",
|
|
DefaultUrl = "https://ai.poppixel.cloud",
|
|
IsPublished = false,
|
|
TemplateId = 1
|
|
});
|
|
|
|
modelBuilder.Entity<SiteInfo>()
|
|
.HasOne(s => s.User)
|
|
.WithMany()
|
|
.HasForeignKey(s => s.UserId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
modelBuilder.Entity<SiteInfo>()
|
|
.HasOne(s => s.Template)
|
|
.WithMany(t => t.Sites)
|
|
.HasForeignKey(s => s.TemplateId)
|
|
.OnDelete(DeleteBehavior.Restrict); // Prevent cascading deletes
|
|
|
|
// MenuItem configuration
|
|
modelBuilder.Entity<MenuItem>()
|
|
.HasOne(m => m.SiteInfo)
|
|
.WithMany(s => s.MenuItems)
|
|
.HasForeignKey(m => m.SiteInfoId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
modelBuilder.Entity<MenuItem>()
|
|
.HasOne(m => m.ContentGroup)
|
|
.WithMany()
|
|
.HasForeignKey(m => m.ContentGroupId)
|
|
.OnDelete(DeleteBehavior.NoAction);
|
|
|
|
modelBuilder.Entity<MenuItem>()
|
|
.HasOne(m => m.ContentItem)
|
|
.WithMany()
|
|
.HasForeignKey(m => m.ContentItemId)
|
|
.OnDelete(DeleteBehavior.Restrict);
|
|
|
|
modelBuilder.Entity<MenuItem>()
|
|
.HasOne(m => m.Parent)
|
|
.WithMany(p => p.Children)
|
|
.HasForeignKey(m => m.ParentId)
|
|
.OnDelete(DeleteBehavior.Restrict);
|
|
|
|
modelBuilder.Entity<ContentItem>()
|
|
.HasOne(ci => ci.ContentGroup)
|
|
.WithMany(cg => cg.Items)
|
|
.HasForeignKey(ci => ci.ContentGroupId)
|
|
.OnDelete(DeleteBehavior.Cascade); // When a ContentGroup is deleted, delete its ContentItems
|
|
|
|
modelBuilder.Entity<ContentChunk>()
|
|
.HasOne(cc => cc.ContentItem)
|
|
.WithMany(ci => ci.Chunks)
|
|
.HasForeignKey(cc => cc.ContentItemId)
|
|
.OnDelete(DeleteBehavior.Cascade); // When a ContentItem is deleted, delete its Chunks
|
|
|
|
modelBuilder.Entity<DesignTemplate>()
|
|
.HasOne(s => s.User)
|
|
.WithMany()
|
|
.HasForeignKey(s => s.UserId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
modelBuilder.Entity<CssTemplate>()
|
|
.HasOne(ct => ct.DesignTemplate)
|
|
.WithOne(dt => dt.CssTemplate) // Assuming DesignTemplate can have multiple CSS templates
|
|
.HasForeignKey<CssTemplate>(ct => ct.DesignTemplateId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
modelBuilder.Entity<FormDefinition>()
|
|
.HasOne(fd => fd.SiteInfo)
|
|
.WithMany(s => s.FormDefinitions)
|
|
.HasForeignKey(fd => fd.SiteInfoId)
|
|
.OnDelete(DeleteBehavior.Cascade);
|
|
|
|
modelBuilder.Entity<FormDefinition>()
|
|
.HasIndex(fd => new { fd.SiteInfoId, fd.Slug })
|
|
.IsUnique(); // Ensure each form slug is unique per site
|
|
}
|
|
}
|
|
}
|