Skip to content

DocumentCollection

DocumentCollection is a specialized collection class for managing PropertyDocument objects with domain-specific logic. It provides filtering, sorting, validation, and convenience methods for working with documents across all entities (Estate, Project, Phase, Building).

Why Use DocumentCollection?

Instead of using a generic List<PropertyDocument>, DocumentCollection provides:

  • Domain-specific methods like GetFloorPlans(), GetProspectus(), GetPublicDocuments()
  • Built-in validation when adding documents
  • Filtering by type, extension, and visibility
  • Search capabilities for finding documents by title
  • Type safety and self-documenting code

Basic Usage

// Creating a new collection
var documents = new DocumentCollection();

// Adding documents (with automatic validation)
documents.Add(new PropertyDocument
{
    Id = "DOC-001",
    Title = "Floor Plan - 2nd Floor",
    Url = "https://cdn.example.com/floor-plan.pdf",
    FileName = "floor-plan-2nd",
    FileExtension = "pdf",
    Type = 1,
    IsPublic = true,
    Order = 1
});

// Get public documents
var publicDocs = documents.GetPublicDocuments();

// Get PDFs only
var pdfDocs = documents.GetPDFs();

// Search by title
var floorPlans = documents.SearchByTitle("floor plan");

Key Methods

Filtering by Type

GetByType(int type, bool ordered = true) - Gets documents of a specific type

// Get all documents of type 1 (e.g., floor plans in Vitec)
var floorPlans = estate.Documents.GetByType(1);

GetByTypes(int[] types, bool ordered = true) - Gets documents matching any type

// Get multiple document types
var legalDocs = estate.Documents.GetByTypes(new[] { 5, 6, 7 });

Public/Private Filtering

GetPublicDocuments(bool ordered = true) - Gets all public documents

// Show only public documents on website
var publicDocs = estate.Documents.GetPublicDocuments();
foreach (var doc in publicDocs)
{
    DisplayDocument(doc.Title, doc.Url);
}

GetPrivateDocuments(bool ordered = true) - Gets internal/private documents

// Show private documents to agents only
var privateDocs = estate.Documents.GetPrivateDocuments();

Filtering by File Extension

GetByExtension(string extension, bool ordered = true) - Gets documents with specific extension

// Get all PDFs
var pdfs = estate.Documents.GetByExtension("pdf");

// Get all Word documents
var wordDocs = estate.Documents.GetByExtension("docx");

GetPDFs(bool ordered = true) - Convenience method for PDFs

var allPDFs = estate.Documents.GetPDFs();

Ordering & Limiting

GetOrdered() - Returns documents sorted by Order property

var sortedDocs = estate.Documents.GetOrdered();

GetFirst(int count) - Gets the first N documents

// Get first 5 documents
var topDocs = estate.Documents.GetFirst(5);

SearchByTitle(string searchTerm, bool ordered = true) - Search documents by title

// Find all documents with "contract" in title
var contracts = estate.Documents.SearchByTitle("contract");

// Case-insensitive search
var plans = estate.Documents.SearchByTitle("PLAN"); // Matches "floor plan", "site plan", etc.

Common Use Cases

These convenience methods cover typical real estate document scenarios:

GetFloorPlans() - Gets floor plan documents

Searches for keywords: "floor plan", "plantegning", "plan", "etasjekart"

var floorPlans = estate.Documents.GetFloorPlans();
if (floorPlans.HasDocuments)
{
    DisplayFloorPlans(floorPlans);
}

GetProspectus() - Gets prospectus/sales documents

Searches for keywords: "prospectus", "prospekt", "salgsoppgave", "sales document"

var prospectus = estate.Documents.GetProspectus();

GetContracts() - Gets contract documents

Searches for keywords: "contract", "kontrakt", "kjøpekontrakt", "agreement"

var contracts = estate.Documents.GetContracts();

Validation

Documents are automatically validated when added to the collection:

var documents = new DocumentCollection();

// This will throw InvalidOperationException
documents.Add(new PropertyDocument
{
    Id = "DOC-001",
    Url = "https://example.com/doc.pdf"
}); // Missing Title

// This will succeed
documents.Add(new PropertyDocument
{
    Id = "DOC-001",
    Title = "Floor Plan",
    Url = "https://example.com/doc.pdf",
    FileName = "floor-plan",
    FileExtension = "pdf"
});

Validation rules: - Document cannot be null - Must have an Id - Must have a Title - Must have a Url

Utility Properties

HasDocuments - Check if collection has any documents

if (estate.Documents.HasDocuments)
{
    ShowDocumentsSection(estate.Documents);
}

DocumentCount - Get total document count

Console.WriteLine($"Total documents: {estate.Documents.DocumentCount}");

HasType(int type) - Check if a document type exists

if (estate.Documents.HasType(1))
{
    ShowFloorPlansTab();
}

HasPublicDocuments - Check if any public documents exist

if (estate.Documents.HasPublicDocuments)
{
    ShowDocumentsSection();
}

Complete Example

// Estate with multiple documents
var estate = new Estate
{
    Id = "EST-001",
    Heading = "Modern Apartment in City Center"
};

// Documents are automatically initialized as DocumentCollection
estate.Documents.Add(new PropertyDocument
{
    Id = "DOC-001",
    Title = "Salgsoppgave",
    Url = "https://cdn.example.com/prospectus.pdf",
    FileName = "salgsoppgave",
    FileExtension = "pdf",
    Type = 0,
    IsPublic = true,
    Order = 1
});

estate.Documents.Add(new PropertyDocument
{
    Id = "DOC-002",
    Title = "Floor Plan - 2nd Floor",
    Url = "https://cdn.example.com/floor-plan-2nd.pdf",
    FileName = "floor-plan-2nd",
    FileExtension = "pdf",
    Type = 1,
    IsPublic = true,
    Order = 2
});

estate.Documents.Add(new PropertyDocument
{
    Id = "DOC-003",
    Title = "Internal Valuation Report",
    Url = "https://cdn.example.com/valuation.pdf",
    FileName = "valuation",
    FileExtension = "pdf",
    Type = 10,
    IsPublic = false,
    Order = 3
});

// Get public documents for website
var publicDocs = estate.Documents.GetPublicDocuments();
Console.WriteLine($"Public documents: {publicDocs.DocumentCount}");

// Get floor plans
var floorPlans = estate.Documents.GetFloorPlans();
Console.WriteLine($"Floor plans: {floorPlans.DocumentCount}");

// Get prospectus
var prospectus = estate.Documents.GetProspectus();
if (prospectus.HasDocuments)
{
    Console.WriteLine($"Prospectus: {prospectus.First().Title}");
}

// Get all PDFs
var allPDFs = estate.Documents.GetPDFs();
Console.WriteLine($"PDFs: {allPDFs.DocumentCount}");

// Search for specific documents
var contracts = estate.Documents.SearchByTitle("contract");
Console.WriteLine($"Contracts found: {contracts.DocumentCount}");

Working with Document Types

Document types are stored as integers from the source system (e.g., Vitec). You can filter by these type codes:

// Example Vitec document types (hypothetical values)
const int TYPE_PROSPECTUS = 0;
const int TYPE_FLOOR_PLAN = 1;
const int TYPE_ENERGY_CERTIFICATE = 2;
const int TYPE_BUILDING_INSPECTION = 3;

// Get all floor plans
var floorPlans = estate.Documents.GetByType(TYPE_FLOOR_PLAN);

// Get multiple types
var essentialDocs = estate.Documents.GetByTypes(new[]
{
    TYPE_PROSPECTUS,
    TYPE_FLOOR_PLAN,
    TYPE_ENERGY_CERTIFICATE
});

Usage Across Models

DocumentCollection is used consistently across property-related models:

Estate

public DocumentCollection? Documents { get; set; }

Project, Phase, Building

public DocumentCollection? Documents { get; set; }

Download