diff --git a/Tsi1.Api/Tsi1.DataLayer/Entities/Forum.cs b/Tsi1.Api/Tsi1.DataLayer/Entities/Forum.cs index 8c362031bac40111b3975336e3ead073e736c506..9cb5a15180ecd75c36bcba58e02d4bdb6e5a8d91 100644 --- a/Tsi1.Api/Tsi1.DataLayer/Entities/Forum.cs +++ b/Tsi1.Api/Tsi1.DataLayer/Entities/Forum.cs @@ -17,6 +17,10 @@ namespace Tsi1.DataLayer.Entities public int CourseId { get; set; } + public int TenantId { get; set; } + + public Tenant Tenant { get; set; } + public Course Course { get; set; } public ICollection<Post> Posts { get; set; } diff --git a/Tsi1.Api/Tsi1.DataLayer/Entities/Tenant.cs b/Tsi1.Api/Tsi1.DataLayer/Entities/Tenant.cs new file mode 100644 index 0000000000000000000000000000000000000000..d5201eca1c83babdb7268e9c9d6dcb78f537dd96 --- /dev/null +++ b/Tsi1.Api/Tsi1.DataLayer/Entities/Tenant.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Tsi1.DataLayer.Entities +{ + public class Tenant + { + public Tenant() + { + Forums = new HashSet<Forum>(); + } + + public int Id { get; set; } + + public string Name { get; set; } + + public ICollection<Forum> Forums { get; set; } + } +} diff --git a/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/ForumConfiguration.cs b/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/ForumConfiguration.cs index 0007d57ee4625c7756efa828488bb9034a6fb2bc..1de5bbdcf518e9ee1b0fa9a2d566c804f74000d6 100644 --- a/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/ForumConfiguration.cs +++ b/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/ForumConfiguration.cs @@ -25,6 +25,10 @@ namespace Tsi1.DataLayer.EntityConfiguration .WithMany(x => x.Forums) .HasForeignKey(x => x.CourseId); + builder.HasOne(x => x.Tenant) + .WithMany(x => x.Forums) + .HasForeignKey(x => x.TenantId); + } } } diff --git a/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/TenantConfiguration.cs b/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/TenantConfiguration.cs new file mode 100644 index 0000000000000000000000000000000000000000..dd0e9a4dffd5495369e89509d2be3f48a39ad782 --- /dev/null +++ b/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/TenantConfiguration.cs @@ -0,0 +1,25 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using System; +using System.Collections.Generic; +using System.Text; +using Tsi1.DataLayer.Entities; + +namespace Tsi1.DataLayer.EntityConfiguration +{ + class TenantConfiguration : IEntityTypeConfiguration<Tenant> + { + public void Configure(EntityTypeBuilder<Tenant> builder) + { + builder.HasKey(x => x.Id); + + builder.HasIndex(x => x.Name) + .IsUnique(); + + builder.Property(x => x.Name) + .IsRequired() + .HasColumnType("character varying(50)"); + + } + } +} diff --git a/Tsi1.Api/Tsi1.DataLayer/Tsi1Context.cs b/Tsi1.Api/Tsi1.DataLayer/Tsi1Context.cs index 578163242e61b037f2e80b869c0f2d5af8a4eb3c..83f1d1526a4cb166a45ff7bee494484ae12fa9e7 100644 --- a/Tsi1.Api/Tsi1.DataLayer/Tsi1Context.cs +++ b/Tsi1.Api/Tsi1.DataLayer/Tsi1Context.cs @@ -19,6 +19,7 @@ namespace Tsi1.DataLayer public DbSet<Forum> Forums { get; set; } public DbSet<Post> Posts { get; set; } public DbSet<PostMessage> PostMessages { get; set; } + public DbSet<Tenant> Tenants { get; set; } public Tsi1Context(DbContextOptions options) : base(options) { } @@ -35,6 +36,7 @@ namespace Tsi1.DataLayer modelBuilder.ApplyConfiguration(new ForumConfiguration()); modelBuilder.ApplyConfiguration(new PostConfiguration()); modelBuilder.ApplyConfiguration(new PostMessageConfiguration()); + modelBuilder.ApplyConfiguration(new TenantConfiguration()); } } }