diff --git a/CodeLiturgy.Views/Models/ModelBuilderExtensions.cs b/CodeLiturgy.Views/Models/ModelBuilderExtensions.cs
index 1782c7c..1c19ec7 100644
--- a/CodeLiturgy.Views/Models/ModelBuilderExtensions.cs
+++ b/CodeLiturgy.Views/Models/ModelBuilderExtensions.cs
@@ -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,10 +20,10 @@ namespace CodeLiturgy.Domain.Model
{
modelBuilder
.ConfigureDatabaseKeys()
- .ConfigureAppContextModel()
+ .CurrencyModel()
.ConfigureUserModel()
- .ConfigureEnvironmentModel();
-
+ .ConfigureAppContextModel();
+
//.ConfigureIdentityModel();
}
@@ -39,10 +36,57 @@ namespace CodeLiturgy.Domain.Model
/// Configure App context model
///
///
- private static ModelBuilder ConfigureAppContextModel(this ModelBuilder builder)
+ private static void ConfigureAppContextModel(this ModelBuilder builder)
{
+ builder.Entity().ToTable("UserRoles");
+ builder.Entity(b =>
+ {
+ b.HasMany()
+ .WithOne(b => b.User)
+ .HasForeignKey(ur => ur.UserId).IsRequired();
+ });
+
+
+ builder.Entity().ToTable("ApplicationUser")
+ .HasKey(x => x.Id);
+
+
+ builder.Entity(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().WithOne().HasForeignKey(ur => ur.RoleId).IsRequired();
+ b.HasMany().WithOne().HasForeignKey(rc => rc.RoleId).IsRequired();
+ });
+
+ builder.Entity().HasOne(x => x.ApplicationRole);
+ builder.Entity().HasOne(x => x.ApplicationRole);
+ builder.Entity().HasOne(x => x.ApplicationUser);
+
+
+ builder.Entity(b =>
+ {
+ b.HasKey(rc => rc.Id);
+ b.ToTable("RoleClaims");
+ });
+
+ builder.Entity(b =>
+ {
+ b.HasKey(r => new {r.UserId, r.RoleId});
+ b.ToTable("UserRoles");
+ });
+
+ builder.Entity().ToTable("RoleClaims");
+ builder.Entity().ToTable("UserRole");
+
+
- return builder;
//.ConfigureIdentityModel();
}
@@ -53,23 +97,6 @@ namespace CodeLiturgy.Domain.Model
private static ModelBuilder ConfigureDatabaseKeys(this ModelBuilder modelBuilder)
{
- // Site
- modelBuilder
- .Entity(builder => builder
- .HasKey(site => site.Id))
- .Entity().Property(site => site.Id)
- .ValueGeneratedOnAdd();
-
-
- // Site Environment
- modelBuilder
- .Entity(builder => builder
- .HasKey(site => site.Id))
- .Entity().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()
- .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().ToTable("site_env");
- modelBuilder
- .Entity()
- .HasMany(x => x.Sites)
- .WithOne(x => x.Environment)
- .HasForeignKey(x => x.EnvironmentId);
return modelBuilder;
}