📄 SaveDocument.cshtml Documentation

Welcome to the comprehensive documentation for the SaveDocument.cshtml Razor view in the IrbyImaging application. This guide covers everything—from high‑level overview to low‑level implementation details, with code snippets, UML diagrams, and usage examples.


📑 Table of Contents

  1. Overview & Purpose
  2. File Location & Structure
  3. Dependencies & Technologies
  4. Key Functional Areas
  5. Data Models & View Models
  6. Third‑party Integrations
  7. Scripts & Styles
  8. Sequence UML Diagram
  9. Usage Examples
  10. Conclusion

1. Overview & Purpose

SaveDocument.cshtml is a Razor view used in the LegalImaging module. Its primary goal is to:

  • 🆕 Allow users to select a document type for the uploaded PDF.
  • 🔍 Fetch and display index metadata fields (attributes) based on the selected type.
  • 💾 Submit metadata along with the document to the back‑end for saving.
  • 📄 Show a live PDF preview of the document.

This view orchestrates two primary steps:

  1. Get Index Definitions
  2. Capture & Save Index Values

2. File Location & Structure

IrbyImaging/
└─ Views/
   └─ LegalImaging/
      └─ SaveDocument.cshtml

High‑level structure:

  • @model directive
  • Imports (@using)
  • ViewData & Layout assignment
  • Inline C# to prepare view‑specific variables
  • Two major <form> blocks
    • One for selecting document type
    • One for capturing & saving metadata
  • PDF embedding
  • Section styles & Scripts

3. Dependencies & Technologies

Category Detail
Framework ASP.NET Core MVC Razor Views
Language C# (Razor syntax), HTML, JavaScript
CSS Libs Bootstrap Datepicker, Dropzone, Select2
JS Libs jQuery, Select2
Third‑Party Controls Syncfusion EJ2 (not actively used in snippet)
JSON Serials Newtonsoft.Json

4. Key Functional Areas

4.1 Model Binding

@model IrbyImaging.Models.DocumentImaging
  • Model: DocumentImaging
  • Purpose: Carries document metadata (BatchIds, ReferenceId, FilePath, ContentType, IndexList, etc.)

4.2 ViewData & Layout

@{
    ViewData["Title"] = "Save Uploaded Document";
    Layout = "~/Views/Shared/_LegalLayout.cshtml";
}
  • Title: Sets the browser’s tab title.
  • Layout: Points to a shared Legal section layout.

4.3 Select Document Type Form

This form lets users choose from preconfigured document types:

<form asp-action="SaveDoc" class="form-horizontal" id="type-form" method="post">
  @Html.HiddenFor(model => model.BatchIds, new { Value = lists })
  @Html.AntiForgeryToken()

  <h4>Select Document Type</h4>
  <select asp-for="DocumentType" asp-items="@Model.DocumentTypes">
    <option value="" disabled selected>Select Document Type</option>
  </select>

  <input type="hidden" id="batchId" value="@guidList" />
  <button type="submit" class="btn btn-primary">Get Indexes</button>
</form>
  • asp-action="SaveDoc": Invokes LegalImagingController.SaveDoc(DocumentImaging model).
  • BatchIds: Passed as hidden field for back‑end correlation.

4.4 Dynamic Index Fields Rendering

Once document type is selected, the controller repopulates the view with Model.IndexList. The view then:

  • Loops through each IndexDefinition
  • Chooses the correct input type by AttributeType and other flags
  • Renders textareas, date pickers, number inputs, selects, etc.
@for (var i = 0; i < Model.IndexList.Count; i++) {
    var idx = Model.IndexList[i];
    if (idx.AttributeType == AttributeType.Date) {
        <input asp-for="@idx.IndexValue" type="date" />
    } else if (idx.LinkEmployeeData) {
        <select asp-for="@idx.IndexValue" asp-items="@Model.EmployeeData"></select>
    }
    // ...other cases...
}

4.5 Document Preview Embedding

Two <embed> tags keep a live PDF preview in sync:

<embed id="frPDF" width="100%" height="100%"
       src="@Url.Action("DocumentPreview","LegalImaging", new { id = indexTagId })#zoom=FitH"
       type="application/pdf" />
  • src: Calls LegalImagingController.DocumentPreview(Guid id)
  • #zoom=FitH: Fits width on load.

5. Data Models & View Models

DocumentImaging (simplified)

Property Type Description
BatchIds List<Guid> IDs representing the batch of uploads.
ReferenceId Guid Unique document reference.
FilePath string Temp storage path of the uploaded PDF.
ContentType string MIME type of file (e.g. application/pdf).
DocumentTypes IEnumerable<SelectListItem> Predefined document type options.
IndexList List<IndexDefinition> Metadata fields for the chosen doc type.
EmployeeData / JobData / CustomerData / StateData IEnumerable<SelectListItem> Lookup data for linked attributes.

IndexDefinition (key fields)

Property Type Use‑Case
Id int Metadata field identifier.
AttributeName string Label displayed in form.
AttributeType AttributeType enum Determines input type (Text, Number…).
IsRequired bool Triggers client/server validation.
IsMultiValue bool Multi‑select vs single.
LinkEmployeeData bool Use EmployeeData for dropdown.
MultiValueTypes IEnumerable Static multi‑value options.

6. Third‑party Integrations

Library Purpose
Syncfusion EJ2 (Imported but commented) advanced inputs
Dropzone File drag&drop styling (CSS only)
Bootstrap Datepicker Date inputs (CSS only)
Select2 Enhanced <select> styling & search

7. Scripts & Styles

Styles Section

@section styles {
  <link href="~/libs/bootstrap-datepicker/css/bootstrap-datepicker.min.css" rel="stylesheet" />
  <link href="~/libs/dropzone/min/dropzone.min.css" rel="stylesheet" />
}

Scripts Section

@section Scripts {
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css" rel="stylesheet" />
  <script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script>
  <script>
    $(document).ready(function() {
      $('.js-example-basic-single').select2();
    });
  </script>
}
  • Select2 initialization on all .js-example-basic-single selects.

8. Sequence UML Diagram

@startuml
actor User
participant Browser
participant "LegalImagingController" as Controller
participant "SaveDocument.cshtml" as View

User -> Browser: GET /LegalImaging/SaveDocument
Browser -> Controller: HTTP GET
Controller -> View: Render(ViewModel)
User -> View: Select DocumentType + Submit
View -> Controller: HTTP POST SaveDoc(model)
Controller -> Service: Fetch Index Definitions
Service --> Controller: List<IndexDefinition>
Controller -> View: Render(updatedModel)
User -> View: Fill Metadata + Submit
View -> Controller: HTTP POST Save(model)
Controller -> Service: Persist Document & Metadata
Service --> Controller: Success
Controller -> Browser: Redirect to Confirmation
@enduml

9. Usage Examples

1. Initial Load

GET /LegalImaging/SaveDocument?batchIds=...&referenceId=...
  • Returns: SaveDocument.cshtml with only “Select Document Type” form and PDF preview.

2. Get Index Definitions

POST /LegalImaging/SaveDoc
Content-Type: application/x-www-form-urlencoded

DocumentType=Contract&batchId=guid1,guid2
  • Controller Action:
    public IActionResult SaveDoc(DocumentImaging model) {
        model.IndexList = _metadataService.GetIndexDefinitions(model.DocumentType);
        return View("SaveDocument", model);
    }
    
  • View: Rerenders, now showing dynamic fields.

3. Save Document & Metadata

POST /LegalImaging/Save
Content-Type: application/x-www-form-urlencoded

// All hidden fields + IndexList[i].IndexValue fields
  • Controller:
    [HttpPost]
    public IActionResult Save(DocumentImaging model) {
        _imagingService.SaveDocumentWithMetadata(model);
        return RedirectToAction("Index");
    }
    

10. Conclusion

🎯 SaveDocument.cshtml is a dynamic, multi‑step Razor view that enables:

  • Document type selection
  • Metadata (index) field discovery and rendering
  • Real‑time PDF preview
  • Final submission of document + metadata

By leveraging ASP.NET Core MVC, Razor, and popular libraries like Select2, it provides a smooth user experience for legal imaging workflows.

Feel free to extend:

  • Add client‑side validation
  • Introduce real‑time index type switching
  • Integrate more advanced Syncfusion controls for richer UX

Happy coding! 🚀