using CodeLiturgy.Data; using CodeLiturgy.Data.Application; using CodeLiturgy.Data.Application.Users; using CodeLiturgy.Data.Application; using Microsoft.EntityFrameworkCore; namespace CodeLiturgy.Domain.Model { /// /// Database model configuration extensions /// public static class ModelBuilderExtensions { #region Initialization static ModelBuilderExtensions() { } /// /// Setup the database model /// /// public static void ConfigureCurrentDbModel(this ModelBuilder modelBuilder) { modelBuilder .ConfigureDatabaseKeys() .ConfigureAppContextModel() .ConfigureUserModel() .ConfigureEnvironmentModel(); //.ConfigureIdentityModel(); } #endregion #region Application Users /// /// Configure App context model /// /// private static ModelBuilder ConfigureAppContextModel(this ModelBuilder builder) { return builder; //.ConfigureIdentityModel(); } #endregion #region DatabasePK 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; } #endregion #region Database Models private static ModelBuilder ConfigureUserModel(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) { modelBuilder.Entity().ToTable("site_env"); modelBuilder .Entity() .HasMany(x => x.Sites) .WithOne(x => x.Environment) .HasForeignKey(x => x.EnvironmentId); return modelBuilder; } #endregion } }