From 361e7df3eea1e69f5ea242ce9d77bf1e40a94344 Mon Sep 17 00:00:00 2001
From: esantangelo <enzo020895@gmail.com>
Date: Wed, 21 Oct 2020 19:38:51 -0300
Subject: [PATCH] commit

---
 Tsi1.Api/Tsi1.DataLayer/Entities/Forum.cs     |  4 +++
 Tsi1.Api/Tsi1.DataLayer/Entities/Tenant.cs    | 20 +++++++++++++++
 .../EntityConfiguration/ForumConfiguration.cs |  4 +++
 .../TenantConfiguration.cs                    | 25 +++++++++++++++++++
 Tsi1.Api/Tsi1.DataLayer/Tsi1Context.cs        |  2 ++
 5 files changed, 55 insertions(+)
 create mode 100644 Tsi1.Api/Tsi1.DataLayer/Entities/Tenant.cs
 create mode 100644 Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/TenantConfiguration.cs

diff --git a/Tsi1.Api/Tsi1.DataLayer/Entities/Forum.cs b/Tsi1.Api/Tsi1.DataLayer/Entities/Forum.cs
index 8c36203..9cb5a15 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 0000000..d5201ec
--- /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 0007d57..1de5bbd 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 0000000..dd0e9a4
--- /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 5781632..83f1d15 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());
         }
     }
 }
-- 
GitLab