From 3e70d40ec8e242c703dc346c5dec65948fe3e0c1 Mon Sep 17 00:00:00 2001
From: mborzyszkowski <maciej.borzyszkowski@gmail.com>
Date: Tue, 14 Jul 2020 18:34:04 +0200
Subject: [PATCH] Separate Mentor and first full version of DatabaseFiller

---
 .../Controllers/AdminController.cs            |  26 ++-
 src/InternshipSystem.Core/DeanAcceptance.cs   |   4 +-
 src/InternshipSystem.Core/Mentor.cs           |   1 +
 .../DatabaseFiller.cs                         | 201 +++++++++++-------
 .../InternshipDbContext.cs                    |   3 +-
 5 files changed, 146 insertions(+), 89 deletions(-)

diff --git a/src/InternshipSystem.Api/Controllers/AdminController.cs b/src/InternshipSystem.Api/Controllers/AdminController.cs
index b3548d0..9e81473 100644
--- a/src/InternshipSystem.Api/Controllers/AdminController.cs
+++ b/src/InternshipSystem.Api/Controllers/AdminController.cs
@@ -15,6 +15,17 @@ namespace Internship.Api.Controller
 
         public DatabaseFiller FillerService { get; }
 
+        
+        [HttpPost("fill")] 
+        public async Task<IActionResult> Fill() {
+            await FillerService.FillCompany();
+            await FillerService.FillInterns();
+            await FillerService.FillInternshipTypes();
+            await FillerService.FillEditions();
+            await FillerService.FillInternShips();
+            return Ok();
+        }
+
         [HttpPost("fill/companies")]
         public async Task<IActionResult> FillCompaniesAsync()
         {
@@ -32,19 +43,18 @@ namespace Internship.Api.Controller
         public async Task<IActionResult> FillInternshipTypesAsync() {
             await FillerService.FillInternshipTypes();
             return Ok();
-        }
+        }     
 
-        // TODO: 
-        // [HttpPost("fill/editions")]
-        // public async Task<IActionResult> FillEditionsAsync() {
-        //     await FillerService.FillEditions();
-        //     return Ok();
-        // }        
+        [HttpPost("fill/editions")]
+        public async Task<IActionResult> FillEditionsAsync() {
+            await FillerService.FillEditions();
+            return Ok();
+        }
         
         [HttpPost("fill/internships")]
         public async Task<IActionResult> FillInternShipsAsync() {
             await FillerService.FillInternShips();
             return Ok();
-        }           
+        }
     }
 }
\ No newline at end of file
diff --git a/src/InternshipSystem.Core/DeanAcceptance.cs b/src/InternshipSystem.Core/DeanAcceptance.cs
index 55c0e7c..8982849 100644
--- a/src/InternshipSystem.Core/DeanAcceptance.cs
+++ b/src/InternshipSystem.Core/DeanAcceptance.cs
@@ -4,9 +4,9 @@ namespace InternshipSystem.Core
 {
     public class DeanAcceptance
     {
-        public DateTime AcceptanceDate { get; set; }
+        public DateTime? AcceptanceDate { get; set; }
         public bool IsDeansAcceptanceRequired { get; set; }
-        public DeanAcceptanceReason Reason { get; set; }
+        public DeanAcceptanceReason? Reason { get; set; }
     }
     
     public enum DeanAcceptanceReason
diff --git a/src/InternshipSystem.Core/Mentor.cs b/src/InternshipSystem.Core/Mentor.cs
index c6503d0..4d42630 100644
--- a/src/InternshipSystem.Core/Mentor.cs
+++ b/src/InternshipSystem.Core/Mentor.cs
@@ -1,6 +1,7 @@
 namespace InternshipSystem.Core
 {
     public class Mentor {
+        public int Id { get; set; }
         public string Name { get; set; }
         public string Surname { get; set; }
         public string Email { get; set; }
diff --git a/src/InternshipSystem.Repository/DatabaseFiller.cs b/src/InternshipSystem.Repository/DatabaseFiller.cs
index 8903ab9..5a5c72c 100644
--- a/src/InternshipSystem.Repository/DatabaseFiller.cs
+++ b/src/InternshipSystem.Repository/DatabaseFiller.cs
@@ -25,11 +25,11 @@ namespace InternshipSystem.Repository
                     SiteAddress = new Uri("https://www.intel.com/content/www/us/en/jobs/locations/poland.html"),
                     Nip = "9570752316",
                     Range = RangeOfActivities.International,
-                    Branches = new List<BranchOffice>() 
+                    Branches = new List<BranchOffice>
                     {
-                        new BranchOffice() 
+                        new BranchOffice
                         {
-                            Address = new Address() 
+                            Address = new Address
                             {
                                 City = "Gdańsk",
                                 Street = "ul. Słowackiego",
@@ -38,9 +38,9 @@ namespace InternshipSystem.Repository
                                 Country = "Poland"
                             }
                         },
-                        new BranchOffice() 
+                        new BranchOffice
                         {
-                            Address = new Address() 
+                            Address = new Address
                             {
                                 City = "Gdańsk",
                                 Street = "Jana z Kolna",
@@ -49,9 +49,9 @@ namespace InternshipSystem.Repository
                                 Country = "Poland"
                             }
                         },
-                        new BranchOffice() 
+                        new BranchOffice
                         {
-                            Address = new Address() 
+                            Address = new Address
                             {
                                 City = "Boston",
                                 Street = "State St",
@@ -108,10 +108,30 @@ namespace InternshipSystem.Repository
                     Surname = "Kowalski",
                     AlbumNumber = "123456",
                     Email = "s123456@student.pg.edu.pl",
+                    Semester = 4,
                     Course = new Course
                     {
                         Name = "Informatyka",
-                        DesiredSemesters = new List<int> { 4, 6 }
+                        DesiredSemesters = new List<int> { 4, 6 },
+                        ProgramEntries = new List<InternshipProgramEntry>
+                        {
+                            new InternshipProgramEntry
+                            {
+                                Description = "Instalacja, konfiguracja i administracja niewielkich sieci komputerowych, w tym bezprzewodowych."
+                            },
+                            new InternshipProgramEntry
+                            {
+                                Description = "Implementacja polityki bezpieczeństwa informacji w firmie lub instytucji, instalacja ochrony antywirusowej, konfiguracja zapór ogniowych."
+                            },
+                            new InternshipProgramEntry
+                            {
+                                Description = "Instalacja, konfiguracja i administracja oprogramowania, w szczególnościsystemów operacyjnychiserwerów aplikacji."
+                            },
+                            new InternshipProgramEntry
+                            {
+                                Description = "Projektowanie, implementacja i modyfikacjeoprogramowaniaw różnych technologiach i dla różnych zastosowań."
+                            }
+                        }
                     }
                 },
                 new Intern {
@@ -119,10 +139,30 @@ namespace InternshipSystem.Repository
                     Surname = "Kołek",
                     AlbumNumber = "102137",
                     Email = "s102137@student.pg.edu.pl",
+                    Semester = 6,
                     Course = new Course 
                     {
                         Name = "Robotyka",
-                        DesiredSemesters = new List<int> { 6 }
+                        DesiredSemesters = new List<int> { 6 },
+                        ProgramEntries = new List<InternshipProgramEntry>
+                        {
+                            new InternshipProgramEntry
+                            {
+                                Description = "Testowanie oprogramowania, także z wykorzystaniem narzędzi do testowania automatycznego."
+                            },
+                            new InternshipProgramEntry
+                            {
+                                Description = "Wykorzystanie otwartych komponentów programowych z uwzględnieniem prawnych zależności pomiędzy nimi a produktem wynikowym."
+                            },
+                            new InternshipProgramEntry
+                            {
+                                Description = "Projektowanie i implementacja baz danych oraz badanie ich wydajności."
+                            },
+                            new InternshipProgramEntry
+                            {
+                                Description = "Projektowanie i prototypowaniezaawansowanychinterfejsów użytkownika."
+                            }
+                        }
                     }
                 }
             };
@@ -178,64 +218,45 @@ namespace InternshipSystem.Repository
             await Context.SaveChangesAsync();
         }
 
-        // TODO: rewrite later
-        // public async Task FillEditions() {
-        //     var editions = new List<Edition>
-        //     {
-        //         new Edition 
-        //         {
-        //             StartDate = new DateTime(2000, 5, 10),
-        //             EndDate = new DateTime(2000, 11, 10),
-        //             IPPDeadlineDate = new DateTime(2000, 9, 30),
-        //             Subjects = new List<InternshipProgramSubject>
-        //             {
-        //                 new InternshipProgramSubject
-        //                 {
-        //                     Course = new Course
-        //                     {
-        //                         Name = "Informatyka"
-        //                     }
-        //                 },
-        //                 new InternshipProgramSubject
-        //                 {
-        //                     Course = new Course
-        //                     {
-        //                         Name = "Budowanie UI"
-        //                     }
-        //                 },
-        //                 new InternshipProgramSubject
-        //                 {
-        //                     Course = new Course
-        //                     {
-        //                         Name = "Budowanie Back End"
-        //                     }
-        //                 }
-        //             }
-        //         }
-        //     };
-        //     Context.Editions.AddRange(editions);
-        //     await Context.SaveChangesAsync();
-        // }
+        public async Task FillEditions() {
+            var editions = new List<Edition>
+            {
+                new Edition 
+                {
+                    StartDate = new DateTime(2000, 5, 10),
+                    EndDate = new DateTime(2000, 11, 10),
+                    IPPDeadlineDate = new DateTime(2000, 9, 30),
+                    Subjects = new List<InternshipProgramEntry>
+                    {
+                        Context.InternshipProgramEntries
+                            .Where(i => i.Description == "Instalacja, konfiguracja i administracja niewielkich sieci komputerowych, w tym bezprzewodowych.")
+                            .First(),
+                        Context.InternshipProgramEntries
+                            .Where(i => i.Description == "Projektowanie, implementacja i modyfikacjeoprogramowaniaw różnych technologiach i dla różnych zastosowań.")
+                            .First()
+                    }
+                }
+            };
+            Context.Editions.AddRange(editions);
+            await Context.SaveChangesAsync();
+        }
 
         public async Task FillInternShips() {
+            var edition = Context.Editions.First();
+
             var intenrships = new List<Internship>
             {
                 new Internship
                 {
-                    Intern = Context.Interns.Where(i => i.AlbumNumber == "123456").Single(),
-                    Edition = null, //TODO: Context.Editions.Where(e => e.StartDate.Equals(new DateTime(2000, 5, 10))).Single(),
-                    BranchOffice = new BranchOffice() 
-                    {
-                        Address = new Address() 
-                        {
-                            City = "Gdańsk",
-                            Street = "ul. Słowackiego",
-                            Building = "173",
-                            PostalCode = "80-298",
-                            Country = "Poland"
-                        }
-                    },
-                    Type = Context.InternshipTypes.Where(t => t.Type == "UOP").Single(),
+                    Intern = Context.Interns.Where(i => i.AlbumNumber == "123456").First(),
+                    Edition = edition,
+                    BranchOffice = 
+                        Context.Companies
+                            .Where(c => c.Nip == "9570752316")      //Intel
+                            .First()
+                            .Branches
+                            .First(),
+                    Type = Context.InternshipTypes.Where(t => t.Type == "UOP").First(),
                     StartDate = new DateTime(2000, 7, 1),
                     EndDate = new DateTime(2000, 8, 30),
                     IsAccepted = false,
@@ -249,25 +270,49 @@ namespace InternshipSystem.Repository
                     {
                         InsuranceDeliveryDate = new DateTime(2000, 6, 29),
                         IsInsuranceRequired = true
-                    },
-                    InternshipLengthInWeeks = 9,
+                    }, 
+                    LengthInWeeks = 9,
                     Grade = 0,
-                    Program = new List<InternshipProgramSubject>
+                    Program = new List<InternshipProgramEntry>
                     {
-                        new InternshipProgramSubject
-                        {
-                            Course = new Course
-                            {
-                                Name = "Bazy Danych"   
-                            }
-                        },
-                        new InternshipProgramSubject
-                        {
-                            Course = new Course
-                            {
-                                Name = "Design UI"   
-                            }
-                        }
+                        edition.Subjects.First()
+                    },
+                    Mentor = new Mentor
+                    {
+                        Name = "Horacy",
+                        Surname = "Wościcki",
+                        Email = "howos@intel.com",
+                        Phone = "605-555-555"
+                    }
+                },
+                new Internship
+                {
+                    Intern = Context.Interns.Where(i => i.AlbumNumber == "102137").First(),
+                    Edition = edition,
+                    BranchOffice = 
+                        Context.Companies
+                            .Where(c => c.Nip == "5842068320")      //Asseco
+                            .First()
+                            .Branches
+                            .First(),
+                    Type = Context.InternshipTypes.Where(t => t.Type == "UZ").First(),
+                    StartDate = new DateTime(2000, 7, 1),
+                    EndDate = new DateTime(2000, 8, 30),
+                    IsAccepted = false,
+                    DeanAcceptance = new DeanAcceptance
+                    {
+                        IsDeansAcceptanceRequired = false
+                    },
+                    Insurance = new Insurance
+                    {
+                        InsuranceDeliveryDate = new DateTime(2000, 6, 29),
+                        IsInsuranceRequired = true
+                    }, 
+                    LengthInWeeks = 9,
+                    Grade = 0,
+                    Program = new List<InternshipProgramEntry>
+                    {
+                        edition.Subjects.First()
                     },
                     Mentor = new Mentor
                     {
diff --git a/src/InternshipSystem.Repository/InternshipDbContext.cs b/src/InternshipSystem.Repository/InternshipDbContext.cs
index d498c22..cd53a19 100644
--- a/src/InternshipSystem.Repository/InternshipDbContext.cs
+++ b/src/InternshipSystem.Repository/InternshipDbContext.cs
@@ -11,6 +11,8 @@ namespace InternshipSystem.Repository
         public DbSet<Report> Reports { get; set; }
         public DbSet<Intern> Interns { get; set; }
         public DbSet<InternshipType> InternshipTypes { get; set; }
+        public DbSet<Mentor> Mentors { get; set; }
+        public DbSet<InternshipProgramEntry> InternshipProgramEntries { get; set; }
         public InternshipDbContext(DbContextOptions<InternshipDbContext> options)
             : base(options)
         {          
@@ -25,7 +27,6 @@ namespace InternshipSystem.Repository
                 .Entity<Internship>(ie => {
                     ie.OwnsOne(i => i.DeanAcceptance);
                     ie.OwnsOne(i => i.Insurance);
-                    ie.OwnsOne(i => i.Mentor);
                 });
             
             modelBuilder