From 344566813f6b2b657d3535cfae65f342b2578bc6 Mon Sep 17 00:00:00 2001
From: Michal Bohdanowicz <m.w.bohdanowicz@gmail.com>
Date: Tue, 12 Jan 2021 00:24:27 +0100
Subject: [PATCH] fXDD

---
 .../Controllers/InternshipManagementController.cs        | 9 ++++++---
 .../Queries/SearchQuery/InternshipSearchQuery.cs         | 3 +++
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/InternshipSystem.Api/Controllers/InternshipManagementController.cs b/src/InternshipSystem.Api/Controllers/InternshipManagementController.cs
index d04049c..1f4aad1 100644
--- a/src/InternshipSystem.Api/Controllers/InternshipManagementController.cs
+++ b/src/InternshipSystem.Api/Controllers/InternshipManagementController.cs
@@ -38,11 +38,14 @@ namespace InternshipSystem.Api.Controllers
                     .Include(i => i.InternshipRegistration.Type)
                     .Include(i => i.Student)
                     .Include(i => i.Documentation)
-                    .Where(i => !searchQuery.EditionId.HasValue || i.Edition.Id.Equals(searchQuery.EditionId))
-                    .Where(i => !searchQuery.InternshipState.HasValue || i.InternshipRegistration.State.Equals(searchQuery.InternshipState))
-                    .Where(i => !searchQuery.StudentAlbumNumber.HasValue || i.Student.AlbumNumber.Equals(searchQuery.StudentAlbumNumber))
+                    .Include(i => i.Report)
+                    .Where(i => !searchQuery.EditionId.HasValue || i.Edition.Id == searchQuery.EditionId)
+                    .Where(i => !searchQuery.InternshipState.HasValue || i.InternshipRegistration.State == searchQuery.InternshipState)
+                    .Where(i => !searchQuery.InternshipState.HasValue || i.Report.State == searchQuery.ReportState)
+                    .Where(i => !searchQuery.StudentAlbumNumber.HasValue || i.Student.AlbumNumber == searchQuery.StudentAlbumNumber)
                     .Where(i => string.IsNullOrEmpty(searchQuery.StudentFirstName) || i.Student.FirstName.ToLower().Contains(searchQuery.StudentFirstName.ToLower()))
                     .Where(i => string.IsNullOrEmpty(searchQuery.StudentLastName) || i.Student.LastName.ToLower().Contains(searchQuery.StudentLastName.ToLower()))
+                    .Where(i => !searchQuery.DocumentWithState.HasValue || i.Documentation.Any(d => d.State == searchQuery.DocumentWithState))
                     .Skip(searchQuery.Page * searchQuery.PerPage)
                     .Take(searchQuery.PerPage);
             
diff --git a/src/InternshipSystem.Api/Queries/SearchQuery/InternshipSearchQuery.cs b/src/InternshipSystem.Api/Queries/SearchQuery/InternshipSearchQuery.cs
index ecf01c3..d2b184d 100644
--- a/src/InternshipSystem.Api/Queries/SearchQuery/InternshipSearchQuery.cs
+++ b/src/InternshipSystem.Api/Queries/SearchQuery/InternshipSearchQuery.cs
@@ -7,6 +7,7 @@ namespace InternshipSystem.Api.Queries.SearchQuery
     {
         public Guid? EditionId { get; set; } = null;
         public DocumentState? InternshipState { get; set; } = null;
+        public DocumentState? ReportState { get; set; }
         public int? StudentAlbumNumber { get; set; } = null;
         public string StudentFirstName { get; set; } = "";
         public string StudentLastName { get; set; } = "";
@@ -15,5 +16,7 @@ namespace InternshipSystem.Api.Queries.SearchQuery
         /// </summary>
         public string OrderByField { get; set; } = "";
         public SortOrder SortOrder { get; set; } = SortOrder.None;
+
+        public DocumentState? DocumentWithState { get; set; }
     }
 }
\ No newline at end of file
-- 
2.45.2