This commit is contained in:
code liturgy 2022-11-18 00:48:52 +00:00
parent a0c6749bad
commit 1feb6a8e57
1 changed files with 56 additions and 38 deletions

View File

@ -1,7 +1,4 @@
using CodeLiturgy.Data;
using CodeLiturgy.Data.Application;
using CodeLiturgy.Data.Application.Users;
using CodeLiturgy.Data.Application;
using Microsoft.EntityFrameworkCore;
namespace CodeLiturgy.Domain.Model
@ -23,9 +20,9 @@ namespace CodeLiturgy.Domain.Model
{
modelBuilder
.ConfigureDatabaseKeys()
.ConfigureAppContextModel()
.CurrencyModel()
.ConfigureUserModel()
.ConfigureEnvironmentModel();
.ConfigureAppContextModel();
//.ConfigureIdentityModel();
}
@ -39,10 +36,57 @@ namespace CodeLiturgy.Domain.Model
/// Configure App context model
/// </summary>
/// <param name="modelBuilder"></param>
private static ModelBuilder ConfigureAppContextModel(this ModelBuilder builder)
private static void ConfigureAppContextModel(this ModelBuilder builder)
{
builder.Entity<ApplicationUserRole>().ToTable("UserRoles");
builder.Entity<ApplicationUser>(b =>
{
b.HasMany<ApplicationUserRole>()
.WithOne(b => b.User)
.HasForeignKey(ur => ur.UserId).IsRequired();
});
builder.Entity<ApplicationUser>().ToTable("ApplicationUser")
.HasKey(x => x.Id);
builder.Entity<ApplicationRole>(b =>
{
b.HasKey(r => r.Id);
b.HasIndex(r => r.NormalizedName).HasDatabaseName("RoleNameIndex").IsUnique();
b.ToTable("Roles");
b.Property(r => r.ConcurrencyStamp).IsConcurrencyToken();
b.Property(u => u.Name).HasMaxLength(256);
b.Property(u => u.NormalizedName).HasMaxLength(256);
b.HasMany<ApplicationUserRole>().WithOne().HasForeignKey(ur => ur.RoleId).IsRequired();
b.HasMany<ApplicationRoleClaim>().WithOne().HasForeignKey(rc => rc.RoleId).IsRequired();
});
builder.Entity<ApplicationUserRole>().HasOne(x => x.ApplicationRole);
builder.Entity<ApplicationRoleClaim>().HasOne<ApplicationRole>(x => x.ApplicationRole);
builder.Entity<ApplicationUserClaim>().HasOne<ApplicationUser>(x => x.ApplicationUser);
builder.Entity<ApplicationRoleClaim>(b =>
{
b.HasKey(rc => rc.Id);
b.ToTable("RoleClaims");
});
builder.Entity<ApplicationUserRole>(b =>
{
b.HasKey(r => new {r.UserId, r.RoleId});
b.ToTable("UserRoles");
});
builder.Entity<ApplicationRoleClaim>().ToTable("RoleClaims");
builder.Entity<ApplicationUserRole>().ToTable("UserRole");
return builder;
//.ConfigureIdentityModel();
}
@ -53,23 +97,6 @@ namespace CodeLiturgy.Domain.Model
private static ModelBuilder ConfigureDatabaseKeys(this ModelBuilder modelBuilder)
{
// Site
modelBuilder
.Entity<Site>(builder => builder
.HasKey(site => site.Id))
.Entity<Site>().Property(site => site.Id)
.ValueGeneratedOnAdd();
// Site Environment
modelBuilder
.Entity<SiteEnvironment>(builder => builder
.HasKey(site => site.Id))
.Entity<Site>().Property(site => site.Id)
.ValueGeneratedOnAdd();
// FinanceOp
return
modelBuilder;
@ -80,24 +107,15 @@ namespace CodeLiturgy.Domain.Model
#region Database Models
private static ModelBuilder ConfigureUserModel(this ModelBuilder modelBuilder)
private static ModelBuilder CurrencyModel(this ModelBuilder modelBuilder)
{
modelBuilder.Entity<ApplicationUser>()
.HasMany(x => x.Environments)
.WithOne(u => u.User)
.HasForeignKey(x => x.UserId);
return modelBuilder;
}
private static ModelBuilder ConfigureEnvironmentModel(this ModelBuilder modelBuilder)
private static ModelBuilder ConfigureUserModel(this ModelBuilder modelBuilder)
{
modelBuilder.Entity<SiteEnvironment>().ToTable("site_env");
modelBuilder
.Entity<SiteEnvironment>()
.HasMany(x => x.Sites)
.WithOne(x => x.Environment)
.HasForeignKey(x => x.EnvironmentId);
return modelBuilder;
}