Skip to content

Commit

Permalink
Refactored reference doc code
Browse files Browse the repository at this point in the history
We were concatenating doc lists and then prying them apart.  Now we just query both lists directly.
  • Loading branch information
randywoods committed Aug 17, 2023
1 parent 59a8c59 commit 4d6140c
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions CSETWebApi/CSETWeb_Api/CSETWebCore.Helpers/ReferencesBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using CSETWebCore.DataLayer;
using CSETWebCore.DataLayer.Model;
using CSETWebCore.Model.Question;
using Microsoft.EntityFrameworkCore;

namespace CSETWebCore.Helpers
{
Expand Down Expand Up @@ -74,24 +75,27 @@ public void BuildDocumentsForMaturityQuestion(int maturityQuestion_ID,
out List<CustomDocument> sourceDocList,
out List<CustomDocument> additionalDocList)
{
// Create a list of documents we actual have on board, so that we don't build any dead links
List<string> availableRefDocs = GetBuildDocuments();

var documents = _context.MATURITY_SOURCE_FILES.Where(s => s.Mat_Question_Id == maturityQuestion_ID).Select(s => new { s.Gen_File.Gen_File_Id, s.Gen_File.Title, s.Gen_File.File_Name, s.Section_Ref, IsSource = true, s.Gen_File.Is_Uploaded })
.Concat(
_context.MATURITY_REFERENCES.Where(s => s.Mat_Question_Id == maturityQuestion_ID).Select(s => new { s.Gen_File.Gen_File_Id, s.Gen_File.Title, s.Gen_File.File_Name, s.Section_Ref, IsSource = false, s.Gen_File.Is_Uploaded })
).ToList();

// Source Documents
var sourceDocuments = documents.Where(t => t.IsSource)
.Select(s => new CustomDocument() { File_Id = s.Gen_File_Id, Title = s.Title, File_Name = s.File_Name, Section_Ref = s.Section_Ref, Is_Uploaded = s.Is_Uploaded ?? false })
.ToList();
var doc1 = _context.MATURITY_SOURCE_FILES
.Include(x => x.Gen_File)
.Where(s => s.Mat_Question_Id == maturityQuestion_ID)
.Select(s => new { s.Gen_File.Gen_File_Id, s.Gen_File.Title, s.Gen_File.File_Name, s.Section_Ref, s.Gen_File.Is_Uploaded });
var sourceDocuments = doc1
.Select(s => new CustomDocument() { File_Id = s.Gen_File_Id, Title = s.Title, File_Name = s.File_Name, Section_Ref = s.Section_Ref, Is_Uploaded = s.Is_Uploaded ?? false });
sourceDocList = sourceDocuments.Where(d => availableRefDocs.Contains(d.File_Name) || d.Is_Uploaded).ToList();


// Additional Resource Documents
var additionalDocuments = documents.Where(t => !t.IsSource)
.Select(s => new CustomDocument() { File_Id = s.Gen_File_Id, Title = s.Title, File_Name = s.File_Name, Section_Ref = s.Section_Ref, Is_Uploaded = s.Is_Uploaded ?? false })
.ToList();
var doc2 = _context.MATURITY_REFERENCES
.Include(x => x.Gen_File)
.Where(s => s.Mat_Question_Id == maturityQuestion_ID)
.Select(s => new { s.Gen_File_Id, s.Gen_File.Title, s.Gen_File.File_Name, s.Section_Ref, s.Gen_File.Is_Uploaded });
var additionalDocuments = doc2
.Select(s => new CustomDocument() { File_Id = s.Gen_File_Id, Title = s.Title, File_Name = s.File_Name, Section_Ref = s.Section_Ref, Is_Uploaded = s.Is_Uploaded ?? false });
additionalDocList = additionalDocuments.Where(d => availableRefDocs.Contains(d.File_Name) || d.Is_Uploaded).ToList();
}

Expand Down

0 comments on commit 4d6140c

Please sign in to comment.