From 6a06dd0e17d8d8340081a3f947510e91e1af3a52 Mon Sep 17 00:00:00 2001
From: esantangelo <enzo020895@gmail.com>
Date: Thu, 10 Dec 2020 21:32:43 -0300
Subject: [PATCH] entities and configuration

---
 Tsi1.Api/Tsi1.DataLayer/Entities/Course.cs    |  3 ++
 Tsi1.Api/Tsi1.DataLayer/Entities/Student.cs   |  3 ++
 .../Entities/StudentCourseResult.cs           | 21 ++++++++++++
 .../StudentCourseResultConfiguration.cs       | 32 +++++++++++++++++++
 Tsi1.Api/Tsi1.DataLayer/Tsi1Context.cs        |  2 ++
 5 files changed, 61 insertions(+)
 create mode 100644 Tsi1.Api/Tsi1.DataLayer/Entities/StudentCourseResult.cs
 create mode 100644 Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/StudentCourseResultConfiguration.cs

diff --git a/Tsi1.Api/Tsi1.DataLayer/Entities/Course.cs b/Tsi1.Api/Tsi1.DataLayer/Entities/Course.cs
index c09ae3a..03da9e3 100644
--- a/Tsi1.Api/Tsi1.DataLayer/Entities/Course.cs
+++ b/Tsi1.Api/Tsi1.DataLayer/Entities/Course.cs
@@ -13,6 +13,7 @@ namespace Tsi1.DataLayer.Entities
             Sections = new HashSet<Section>();
             Communications = new HashSet<Communication>();
             Activities = new HashSet<Activity>();
+            StudentCourseResults = new HashSet<StudentCourseResult>();
         }
 
         public int Id { get; set; }
@@ -28,5 +29,7 @@ namespace Tsi1.DataLayer.Entities
         public ICollection<Communication> Communications { get; set; }
 
         public ICollection<Activity> Activities { get; set; }
+
+        public ICollection<StudentCourseResult> StudentCourseResults { get; set; }
     }
 }
diff --git a/Tsi1.Api/Tsi1.DataLayer/Entities/Student.cs b/Tsi1.Api/Tsi1.DataLayer/Entities/Student.cs
index cccbc18..e6c50ad 100644
--- a/Tsi1.Api/Tsi1.DataLayer/Entities/Student.cs
+++ b/Tsi1.Api/Tsi1.DataLayer/Entities/Student.cs
@@ -11,6 +11,7 @@ namespace Tsi1.DataLayer.Entities
             StudentCourses = new HashSet<StudentCourse>();
             EvaluationInscriptions = new HashSet<EvaluationInscription>();
             Submissions = new HashSet<Submission>();
+            StudentCourseResults = new HashSet<StudentCourseResult>();
         }
 
         public int Id { get; set; }
@@ -26,5 +27,7 @@ namespace Tsi1.DataLayer.Entities
         public ICollection<EvaluationInscription> EvaluationInscriptions { get; set; }
 
         public ICollection<Submission> Submissions { get; set; }
+
+        public ICollection<StudentCourseResult> StudentCourseResults { get; set; }
     }
 }
diff --git a/Tsi1.Api/Tsi1.DataLayer/Entities/StudentCourseResult.cs b/Tsi1.Api/Tsi1.DataLayer/Entities/StudentCourseResult.cs
new file mode 100644
index 0000000..443110a
--- /dev/null
+++ b/Tsi1.Api/Tsi1.DataLayer/Entities/StudentCourseResult.cs
@@ -0,0 +1,21 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Tsi1.DataLayer.Entities
+{
+    public class StudentCourseResult
+    {
+        public int Id { get; set; }
+
+        public int Result { get; set; }
+
+        public DateTime Date { get; set; }
+
+        public int StudentId { get; set; }
+        public int CourseId { get; set; }
+
+        public Student Student { get; set; }
+        public Course Course { get; set; }
+    }
+}
diff --git a/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/StudentCourseResultConfiguration.cs b/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/StudentCourseResultConfiguration.cs
new file mode 100644
index 0000000..6149b85
--- /dev/null
+++ b/Tsi1.Api/Tsi1.DataLayer/EntityConfiguration/StudentCourseResultConfiguration.cs
@@ -0,0 +1,32 @@
+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 StudentCourseResultConfiguration : IEntityTypeConfiguration<StudentCourseResult>
+    {
+        public void Configure(EntityTypeBuilder<StudentCourseResult> builder)
+        {
+            builder.HasKey(x => x.Id);
+
+            builder.Property(x => x.Result)
+                .IsRequired()
+                .HasColumnType("integer");
+
+            builder.Property(x => x.Date)
+                .IsRequired();
+
+            builder.HasOne(x => x.Course)
+                .WithMany(x => x.StudentCourseResults)
+                .HasForeignKey(x => x.CourseId);
+
+            builder.HasOne(x => x.Student)
+                .WithMany(x => x.StudentCourseResults)
+                .HasForeignKey(x => x.StudentId);
+        }
+    }
+}
diff --git a/Tsi1.Api/Tsi1.DataLayer/Tsi1Context.cs b/Tsi1.Api/Tsi1.DataLayer/Tsi1Context.cs
index cef2ed0..50967e8 100644
--- a/Tsi1.Api/Tsi1.DataLayer/Tsi1Context.cs
+++ b/Tsi1.Api/Tsi1.DataLayer/Tsi1Context.cs
@@ -39,6 +39,7 @@ namespace Tsi1.DataLayer
         public DbSet<EvaluationInscription> EvaluationInscriptions { get; set; }
         public DbSet<Submission> Submissions { get; set; }
         public DbSet<EvaluationType> EvaluationTypes { get; set; }
+        public DbSet<StudentCourseResult> StudentCourseResults { get; set; }
 
 
 
@@ -77,6 +78,7 @@ namespace Tsi1.DataLayer
             modelBuilder.ApplyConfiguration(new EvaluationInscriptionConfiguration());
             modelBuilder.ApplyConfiguration(new SubmissionConfiguration());
             modelBuilder.ApplyConfiguration(new EvaluationTypeConfiguration());
+            modelBuilder.ApplyConfiguration(new StudentCourseResultConfiguration());
         }
     }
 }
-- 
GitLab