📁 AccountingImagingController.cs Documentation
Path:
IrbyImaging/UI/Controllers/AccountingImagingController.cs
📖 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Controller Structure
- Key Functional Areas
- API Endpoints Overview
- View Models & Data Models
- Helper Methods & Utilities
- Third‐Party Integrations
- Sample Code & Usage Examples
- UML Diagram (High Level)
- Conclusion
🧐 1. Overview & Purpose
AccountingImagingController is the central ASP.NET Core MVC controller managing accounting document imaging workflows within the IrbyImaging application. Its responsibilities include:
- Uploading various document formats (PDF, Word, Excel, Email, Images).
- Running OCR (Optical Character Recognition) on uploads.
- Indexing documents with dynamic attributes.
- Storing document blobs in Azure Blob Storage.
- Previewing, listing, searching, and filtering documents.
- Generating reports (licenses, contractors, municipal, PNC).
- A file manager for browsing server files (via Syncfusion).
- Exposing PDF viewer endpoints for in-browser annotations.
This single controller spans features across multiple imaging types (Legal, Safety, IT, Accounting, Bidding). It inherits common logic from BaseController.
🔗 2. Dependencies & Technologies
| Category | Libraries & Frameworks |
|---|---|
| Web Framework | ASP.NET Core MVC, Razor Views |
| PDF Processing | iTextSharp, IronPdf, Syncfusion.PdfViewer, Syncfusion.EJ2.PdfViewer |
| OCR & Imaging | IronOcr (Tesseract), IronPdf, IronXL, System.Drawing |
| Office Document I/O | Syncfusion.DocIO, Syncfusion.XlsIO, Microsoft.Office.Interop.Outlook |
| Azure Storage | Azure.Storage.Blobs |
| Front‐End Components | Syncfusion EJ2 FileManager, Spreadsheet, DocumentEditor, Charts |
| Data Access | Entity Framework Core, Raw SQL (FromSqlInterpolated) |
| Identity & Security | ASP.NET Core Identity, AzureADRead |
| JSON Handling | Newtonsoft.Json |
| Misc Utilities | MimeKit, System.IO, System.Web, LINQ, Caching (IMemoryCache) |
🏗 Controller Structure
AccountingImagingController : BaseController
├─ Fields & DI
│ ├─ _context (IrbyContext)
│ ├─ _httpContextAccessor
│ ├─ _hostingEnvironment
│ ├─ _cache (IMemoryCache)
│ ├─ _blobServiceClient (Azure Blob)
│ └─ _configuration
├─ Public Actions
│ ├─ Index, Upload, DocPreview, Preview, DeletePreview, List, PncLookup, ...
│ ├─ HTTP POST actions: UploadDocs, UploadPncCsv, SearchPnc, SaveDocument, Save, Edit, Delete, ...
│ ├─ FileManager & PDF Viewer Web API endpoints
│ └─ Utility endpoints: GetNames, SearchByEmployeeNumber, ...
└─ Private Helpers
├─ SetImagingType(...)
├─ OCRResult(...)
├─ JsonConverterstring(...)
├─ GetDocumentPath(...)
└─ Combine(...)
⭐ 4. Key Functional Areas
4.1. Document Upload & Indexing
-
Upload Docs (
UploadDocs):- Accepts
IFormFilestreams. - Splits multi‐page PDFs or Word/Excel/Email attachments into single‐page PDF byte arrays.
- Runs OCR (
IronTesseract) on images/PDFs. - Creates temporary
TempDocumentDataandBlobDatarecords. - Tags each batch with
BatchId&IndexTagfor later assembly and indexing.
- Accepts
-
Indexing Flow:
- User selects category (legal, safety, accounting).
- After upload, user sees DocPreview to assign dynamic indexes (attributes).
- On Save, controller merges temp pages into a single PDF, stores blob to Azure, saves a
DocumentImagewith JSON‐serialized index values.
[HttpPost]
[RequestSizeLimit(900_000_000)]
public async Task<IActionResult> UploadDocs(IEnumerable<IFormFile> file, string category) { ... }
4.2. Document Preview & Rendering
- DocPreview: Shows thumbnails of unindexed pages by
BatchId+ user. - Preview(Guid id): Streams a single-page PDF for preview in browser.
- RenderImage / RenderImagePrev / RenderDeleteImagePrev:
- Retrieves blobs from Azure or temp store.
- Returns
FileContentResultfor in-browser display.
public async Task<ActionResult> RenderImage(Guid id, string Preview) {
var pdf = _context.DocumentImages.First(...);
var blob = containerClient.GetBlobClient(pdf.BlobName);
await blob.DownloadTo(ms);
return File(ms.ToArray(), pdf.ContentType);
}
4.3. Document Listing & Search
-
List(string category):
- Lists all images for a given imaging type.
- Displays dynamic indexes (e.g., Expiration Date) for quick grid filtering.
-
SearchAll(...) & List(...) [POST]:
- Multi‐criteria filtering by category, type, date range, OCR text, employee/job.
[HttpPost]
public ActionResult SearchAll(DocumentImaging image, IFormCollection form, ...) { ... }
4.4. PNC (Purchasing Card) CSV Integration
- UploadPncCsv:
- Loads Excel/CSV via IronXL.
- Maps rows to
Pncentity and persists unique transactions.
- PncLookup / SearchPnc:
- Provides lookup UI to filter
Pncrecords.
- Provides lookup UI to filter
public IActionResult UploadPncCsv(IEnumerable<IFormFile> file, string category) { ... }
[HttpPost]
public IActionResult SearchPnc([FromBody] PncData pncData) { ... }
4.5. Reporting & Geo‐Mapping
-
GCLicenseReport, ECLicenseReport, MunicipalLicenseReport:
- Execute raw SQL pivot queries to format license attributes into a tabular structure.
- Data source fed to Syncfusion EJ2 components (
ViewBag.datasource).
-
GeoMapping:
- Fetches location attributes (address, lease terms).
- Can embed map visualizations.
public IActionResult GCLicenseReport() {
var records = _context.LicenseReport.FromSqlInterpolated($"--General Contractor Licenses...\r\n...").ToList();
ViewBag.datasource = records;
return View();
}
4.6. File Manager (Syncfusion)
- FileOperations: Implements PhysicalFileProvider operations (
read,delete,copy,move,create,search,rename). - UploadFiles, Download, GetImage: Integrates Syncfusion EJ2 FileManager.
public object FileOperations([FromBody] FileManagerDirectoryContent args) { ... }
4.7. PDF Viewer API Endpoints
Under [Route("[controller]")] and [ApiController]:
| Endpoint | HTTP | Description |
|---|---|---|
/MapsController/storeSearch |
POST | Stores map search data |
/AccountingImaging/Load |
POST | Loads PDF into viewer cache |
/AccountingImaging/RenderPdfPages |
POST | Renders specified PDF pages |
/AccountingImaging/RenderThumbnailImages |
POST | Extracts thumbnail images |
/AccountingImaging/Bookmarks |
POST | Retrieves bookmarks |
/AccountingImaging/Download |
POST | Returns base64 PDF document |
/AccountingImaging/PrintImages |
POST | Prepares print‐ready images |
/AccountingImaging/ExportAnnotations |
POST | Serializes annotation data |
/AccountingImaging/ImportAnnotations |
POST | Reads saved annotation JSON from server |
/AccountingImaging/Unload |
POST | Clears document cache |
📦 6. View Models & Data Models
| Model / ViewModel | Purpose |
|---|---|
DocumentImaging |
Aggregates upload/preview data & dynamic indexes |
DocumentImagingList |
DTO for listing images with index snippet |
DocumentAttributeViewDetail |
Single index field (name, value, multi‐value) |
TempDocumentData & BlobData |
Staging entities before final save |
DocumentImage |
Final persisted imaging record (includes blob) |
Pnc, PncData |
Purchasing card transactions & filter DTO |
IndexOptions |
JSON‐deserialized index value (ID, name, type) |
DocumentTypeView, DocumentCategoryView, DocumentAttributeView |
CRUD UIs for master data |
🔧 7. Helper Methods & Utilities
| Method | Description |
|---|---|
SetImagingType(...) |
Flags a TempDocumentData with the correct imaging type enum |
OCRResult(...) |
Runs IronTesseract OCR, returns searchable PDF & extracted text |
JsonConverterstring(...) |
Converts a JSON‐mapped object to key/value dictionary |
GetDocumentPath(...) |
Resolves local vs. WebRoot path for PDF viewer |
Combine(byte[], byte[]) |
Concatenates two byte arrays (helper, rarely used) |
GetFormatType(string) |
Maps file extension to Syncfusion DocumentEditor FormatType |
🚀 8. Third‐Party Integrations
- Azure Blob Storage (
BlobServiceClient) for scalable blob hosting. - iTextSharp & PdfCopy to merge and split PDF pages.
- IronOcr for high‐quality OCR to generate searchable PDFs.
- IronPdf for HTML‐to‐PDF conversion (emails).
- IronXL for Excel reading/writing.
- MimeKit for parsing
.msgemail files. - Syncfusion EJ2 suite: FileManager, DocumentEditor, Spreadsheet, Charts, PDF Viewer.
- Syncfusion.DocIO to handle Word documents.
📝 9. Sample Code & Usage Examples
9.1 Upload & Index
// HTML Form (Razor)
<form asp-action="UploadDocs" enctype="multipart/form-data" method="post">
<input type="file" name="file" multiple />
<input type="hidden" name="category" value="accounting" />
<button type="submit">Upload Accounting Docs</button>
</form>
9.2 Preview Single Page
// AJAX call to Preview action
fetch('/AccountingImaging/Preview/' + id)
.then(res => res.blob())
.then(blob => {
document.querySelector('#pdfFrame').src = URL.createObjectURL(blob);
});
9.3 Search Documents
const filters = { DocumentType: selectedType, OcrSearch: true, searchString: 'Invoice' };
fetch('/AccountingImaging/SearchAll', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(filters)
}).then(...);
🛠️ 10. UML Diagram (High Level)
classDiagram
BaseController <|-- AccountingImagingController
AccountingImagingController o-- IrbyContext
AccountingImagingController o-- IHttpContextAccessor
AccountingImagingController o-- IWebHostEnvironment
AccountingImagingController o-- IMemoryCache
AccountingImagingController o-- BlobServiceClient
AccountingImagingController o-- IConfiguration
AccountingImagingController : +IActionResult Index()
AccountingImagingController : +Task<IActionResult> UploadDocs(...)
AccountingImagingController : +ActionResult DocPreview(...)
AccountingImagingController : +FileContentResult GetDocument(...)
AccountingImagingController : +JsonResult SearchPnc(...)
AccountingImagingController : +IActionResult GeoMapping(bool)
✅ 11. Conclusion
The AccountingImagingController orchestrates a full-fledged document imaging solution—from multi‐format uploads, OCR & indexing, to advanced search, reporting, and in-browser PDF annotation. It leverages a rich ecosystem of third‐party libraries (IronOcr, Syncfusion, Azure Storage) to deliver enterprise‐grade imaging for accounting (and other) departments within the IrbyImaging UI.
This single controller is feature‐dense, serving as the backbone for all imaging workflows: staging temp data, merging pages, dynamic attribute management, and final persistence. Proper separation of concerns (staging vs. final save) and robust error handling ensure scalability and maintainability as business needs evolve.
Feel free to explore individual action methods and helper routines for deeper customization or to extract common logic into dedicated services for cleaner architecture! 🎉