πŸ“„ LegalImagingController Documentation


Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Key Functional Areas
  4. Data Models & ViewModels
  5. Helper Methods & Utilities
  6. Error Handling & Return Types
  7. Sample Code Blocks & Usage Examples
  8. UML Overview
  9. 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 + BlobData records
    • 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 DocumentImage record with DocumentIndexes JSON
    • Marks TempDocumentData as 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 TempDocumentData page 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 storeSearch
  • POST /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)
  • UploadFiles
  • Download
  • GetImage

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 AzureADRead for full name
  • OCRResult: Uses IronTesseract to 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:

  1. Ingest multi‐page files
  2. OCR & temporary staging
  3. Rich indexing UI
  4. Merged PDF creation & cloud storage
  5. Powerful search/list/reporting
  6. Admin CRUD for metadata
  7. 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! ✨