π LegalImagingController Documentation
Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Data Models & ViewModels
- Helper Methods & Utilities
- Error Handling & Return Types
- Sample Code Blocks & Usage Examples
- UML Overview
- Conclusion
1. Overview & Purpose
The LegalImagingController is the central ASP.NET Core MVC controller for the IrbyImaging UI. It handles:
- Uploading multiβpage PDF/image documents
- Performing OCR (via IronOCR & Syncfusion)
- Indexing and storing documents in Azure Blob + EF Core
- Listing, searching and previewing legal/safety/IT documents
- Generating license & lease reports
- Admin management of DocumentΒ Categories, Types, Attributes
- PDFβviewer integration (Syncfusion EJ2 PdfViewer)
- File system management (Syncfusion EJ2 FileManager)
- Geoβmapping lease locations
This single controller coordinates UI views, business logic (IrbyImaging.BusinessLogic), data access (IrbyContext), and thirdβparty services.
2. Dependencies & Technologies
| Technology / Package | Purpose |
|---|---|
| ASP.NET Core MVC | Web framework |
| Entity Framework Core | Data access (IrbyContext) |
| Azure.Storage.Blobs | Blob storage for document images |
| iTextSharp | PDF split/merge and text extraction |
IronOCR (IronOcr) |
Optical Character Recognition |
| IronPdf | PDF creation & searchable PDF bytes |
| Syncfusion EJ2.FileManager | File system UI (read, copy, move, upload) |
| Syncfusion.EJ2.PdfViewer | PDF viewing & annotation API |
| Syncfusion.XlsIO & Spreadsheet | Excel import/export within UI |
| Syncfusion.DocIO & DocumentEditor | Word document editing & formatting |
| Newtonsoft.Json | JSON serialization for indices & APIs |
| Microsoft.AspNetCore.Identity | User/role management (optional) |
| MemoryCache | Caching for PDFβviewer tile images |
| GoogleLocationService | (Commented) Geoβcoding addresses for map pins |
3. Key Functional Areas
3.1 Upload & Temporary Processing π
Endpoints for receiving raw files and breaking them into singleβpage PDFs:
- Upload (GET): Renders upload form
- UploadDocs (POST):
- Streams each multiβpage PDF into individual page streams
- Generates
TempDocumentData+BlobDatarecords - Persists to
_context - Redirects to
DocPreview
[HttpPost]
[RequestSizeLimit(900_000_000)]
public async Task<IActionResult> UploadDocs(IEnumerable<IFormFile> file, string category) { β¦ }
3.2 Document Indexing & Saving πΎ
After preview, users assign metadata/index values and save:
- DocPreview: Lists pages for indexing
- SaveDocument / Save (
POST):- Merges pages via iTextSharp
- Extracts full OCR text (Syncfusion PdfRenderer)
- Uploads final PDF to Azure Blob
- Creates
DocumentImagerecord withDocumentIndexesJSON - Marks
TempDocumentDataas indexed
public async Task<IActionResult> Save(DocumentImaging image, IFormCollection form, string batchId) { β¦ }
3.3 Listing & Searching Documents π
- List (GET/POST): Show all saved docs by category
- SearchAll: Global search across index values, OCR content, leads, job names
- List(DocumentImaging image, IFormCollection form, string category): Filter by custom index list
Results displayed via DocumentImagingListΒ view model.
3.4 Preview & Rendering ποΈ
- Preview(Guid id): Transforms a single
TempDocumentDatapage back to PDF stream - RenderImage/RenderImagePrev: Streams image or blob content for
<img>tags - ViewPdf(Guid id): Writes PDF bytes to temp file and returns PDF response
- ViewOCR(Guid id): Streams searchableβOCR PDF for a document group
3.5 Reporting Endpoints π
Three license reports generate pivoted SQL outputs:
- GCLicenseReport (General Contractor)
- ECLicenseReport (Electrical Contractor)
- MunicipalLicenseReport
All use _context.LicenseReport.FromSqlInterpolated(...) with dynamic pivot SQL.
3.6 Admin CRUD: Categories, Types & Attributes π οΈ
A full administration suite:
| Entity | Actions |
|---|---|
| Document Categories | List, Create, Edit, Delete, Modal |
| Document Types | List, Create, Edit, Delete, Modal |
| Document Attributes | List, Create, Edit, Delete, Modal |
Each action uses view models (DocumentCategoryView, DocumentTypeView, DocumentAttributeView) and binds to EF Core.
3.7 PDF Viewer API Endpoints π
Exposes Syncfusion EJ2 PdfViewer service endpoints under [ApiController]:
POST storeSearchPOST /Load,/RenderPdfPages,/Bookmarks,/Download,/RenderThumbnailImages,/ExportAnnotations,/ImportAnnotationsβ¦
They call PdfRenderer with an inβmemory cache to serve page images, annotations, bookmarks, etc.
3.8 File Manager Endpoints ποΈ
Under MVC controller, Syncfusion EJ2 FileManager events:
FileOperations(read, delete, copy, move, details, create, search, rename)UploadFilesDownloadGetImage
Uses PhysicalFileProvider API.
3.9 GeoMapping & MapsController πΊοΈ
- GeoMapping: Renders a map view of lease agreements (pivot SQL + Syncfusion Chart data).
- MapsController: Minimal API for storing clientβside search data (
StoreSearch).
4. Data Models & ViewModels
| Model / VM | Description |
|---|---|
DocumentImage |
EF Core entity for saved documents |
TempDocumentData |
Temporary uploaded page data |
BlobData |
Raw bytes for each temp page |
DocumentImaging |
Main VM for preview, indexing & lists |
DocumentAttributeViewDetail |
Single index field in edit/list UIs |
IndexOptions |
JSONβserializable struct for index values |
LegalDocumentCategories / LegalDocumentCategoryDetail |
Used in GetDocumentCategories |
DocumentTypeViewDetail |
VM for listing/editing Document Types |
DocumentCategoryViewDetail |
VM for categories |
DocumentAttributeView |
VM for creating/editing attributes |
ContractStackedBar / StackedBar100ChartData |
Chart data for lease/contract reports |
5. Helper Methods & Utilities π§
- GetUserName: Queries Azure AD via
AzureADReadfor full name - OCRResult: Uses
IronTesseractto produce searchable PDF bytes & extract text - Combine: Byte[] concatenation helper
- JsonConverterstring: Flattens a POCO to
Dictionary<string,string> - GetFormatType: Maps extension β
Syncfusion.EJ2.DocumentEditor.FormatType
6. Error Handling & Return Types β οΈ
- Return Types:
IActionResult,JsonResult,FileContentResult,FileStreamResult - HTTP Status: Defaults to 200; Syncfusion FileManager uses status codes on error
- Try/Catch: Sparseβerrors bubble up to ASP.NET Coreβs error middleware
- Validation: Minimal; most controllers assume valid EF results
7. Sample Code Blocks & Usage Examples π
Uploading Documents
// Client-side HTML form:
<form asp-action="UploadDocs" enctype="multipart/form-data" method="post">
<input type="file" name="file" multiple />
<input type="hidden" name="category" value="legal" />
<button type="submit">Upload</button>
</form>
Previewing a Page via AJAX
fetch('/LegalImaging/Preview?id=' + pageId)
.then(res => res.blob())
.then(blob => {
const url = URL.createObjectURL(blob);
document.querySelector('#pageImg').src = url;
});
Saving Final Document
[HttpPost]
public async Task<IActionResult> Save(DocumentImaging image, IFormCollection form, string batchId) {
// Merge pages, upload blob, save EF recordβ¦
}
8. UML Overview
ββββββββββββββββββββββββββ uses βββββββββββββββββββββββββββββ
β LegalImagingControllerβββββββββββββββββββΆβ IrbyContext (EF) β
ββββββββββββββββββββββββββ βββββββββββββββββββββββββββββ
β
β invokes βββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββΆβ Azure Blob Storage β
β βββββββββββββββββββββββββββββββ
β
β calls OCR & PDF libs βββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββΆβ IronOCR, IronPdf, iTextSharpβ
βββββββββββββββββββββββββββββββ
9. Conclusion β
The LegalImagingController orchestrates a complex endβtoβend imaging workflow:
- Ingest multiβpage files
- OCR & temporary staging
- Rich indexing UI
- Merged PDF creation & cloud storage
- Powerful search/list/reporting
- Admin CRUD for metadata
- Embedded PDFβviewer & fileβmanager services
By leveraging thirdβparty libraries and EF Core, it provides a robust platform for legal, safety, and IT document management in the IrbyImaging UI.
Happy Coding & Documenting! β¨