From 22122b5d57d412b23d38c1ec91cc1b0f0dac586e Mon Sep 17 00:00:00 2001
From: esantangelo <enzo020895@gmail.com>
Date: Sun, 15 Nov 2020 12:19:34 -0300
Subject: [PATCH] entity configuration

---
 .../Tsi1.DataLayer/Entities/Communication.cs  | 19 ++++++++++++++
 Tsi1.Api/Tsi1.DataLayer/Entities/Course.cs    |  3 +++
 Tsi1.Api/Tsi1.DataLayer/Entities/Tenant.cs    |  3 +++
 .../CommunicationConfiguration.cs             | 26 +++++++++++++++++++
 4 files changed, 51 insertions(+)
 create mode 100644 Tsi1.Api/Tsi1.DataLayer/Entities/Communication.cs
 create mode 100644 Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/CommunicationConfiguration.cs

diff --git a/Tsi1.Api/Tsi1.DataLayer/Entities/Communication.cs b/Tsi1.Api/Tsi1.DataLayer/Entities/Communication.cs
new file mode 100644
index 0000000..c8d5dec
--- /dev/null
+++ b/Tsi1.Api/Tsi1.DataLayer/Entities/Communication.cs
@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Tsi1.DataLayer.Entities
+{
+    public class Communication
+    {
+        public int Id { get; set; }
+
+        public string Text { get; set; }
+
+        public DateTime ValidUntil { get; set; }
+
+        public Course Course { get; set; }
+
+        public Tenant Tenant { get; set; }
+    }
+}
diff --git a/Tsi1.Api/Tsi1.DataLayer/Entities/Course.cs b/Tsi1.Api/Tsi1.DataLayer/Entities/Course.cs
index 80c4291..f7efedf 100644
--- a/Tsi1.Api/Tsi1.DataLayer/Entities/Course.cs
+++ b/Tsi1.Api/Tsi1.DataLayer/Entities/Course.cs
@@ -11,6 +11,7 @@ namespace Tsi1.DataLayer.Entities
             StudentCourses = new HashSet<StudentCourse>();
             ProfessorCourses = new HashSet<ProfessorCourse>();
             Sections = new HashSet<Section>();
+            Communications = new HashSet<Communication>();
         }
 
         public int Id { get; set; }
@@ -22,5 +23,7 @@ namespace Tsi1.DataLayer.Entities
         public ICollection<StudentCourse> StudentCourses { get; set; }
         public ICollection<ProfessorCourse> ProfessorCourses { get; set; }
         public ICollection<Section> Sections { get; set; }
+
+        public ICollection<Communication> Communications { get; set; }
     }
 }
diff --git a/Tsi1.Api/Tsi1.DataLayer/Entities/Tenant.cs b/Tsi1.Api/Tsi1.DataLayer/Entities/Tenant.cs
index 0a153f8..a146909 100644
--- a/Tsi1.Api/Tsi1.DataLayer/Entities/Tenant.cs
+++ b/Tsi1.Api/Tsi1.DataLayer/Entities/Tenant.cs
@@ -13,6 +13,7 @@ namespace Tsi1.DataLayer.Entities
             Students = new HashSet<Student>();
             Users = new HashSet<User>();
             Surveys = new HashSet<Survey>();
+            Communications = new HashSet<Communication>();
         }
 
         public int Id { get; set; }
@@ -24,5 +25,7 @@ namespace Tsi1.DataLayer.Entities
         public ICollection<Student> Students { get; set; }
         public ICollection<User> Users { get; set; }
         public ICollection<Survey> Surveys { get; set; }
+
+        public ICollection<Communication> Communications { get; set; }
     }
 }
diff --git a/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/CommunicationConfiguration.cs b/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/CommunicationConfiguration.cs
new file mode 100644
index 0000000..ae75b95
--- /dev/null
+++ b/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/CommunicationConfiguration.cs
@@ -0,0 +1,26 @@
+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
+{
+    public class CommunicationConfiguration : IEntityTypeConfiguration<Communication>
+    {
+        public void Configure(EntityTypeBuilder<Communication> builder)
+        {
+            builder.HasKey(x => x.Id);
+
+            builder.Property(x => x.Text)
+                .IsRequired()
+                .HasColumnType("character varying(1000)");
+
+            builder.Property(x => x.ValidUntil)
+                .IsRequired();
+
+            builder.HasIndex(x => x.ValidUntil);
+        }
+    }
+}
-- 
GitLab