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
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
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
Ordering & Limiting
GetOrdered() - Returns documents sorted by Order property
GetFirst(int count) - Gets the first N documents
Search
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"
GetContracts() - Gets contract documents
Searches for keywords: "contract", "kontrakt", "kjøpekontrakt", "agreement"
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
DocumentCount - Get total document count
HasType(int type) - Check if a document type exists
HasPublicDocuments - Check if any public documents exist
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
Project, Phase, Building
Download
- DocumentCollection.cs - Complete C# source code
Related Documentation
- PropertyDocument Class - The individual document class
- ImageCollection - Similar collection for images
- Shared Classes Overview - All shared classes