πŸ“„ SaveDoc.cshtml Documentation

Welcome to the comprehensive documentation for IrbyImaging/Views/LegalImaging/SaveDoc.cshtml. This Razor view is part of an ASP.NET MVC application that handles the saving and indexing of legal, safety, and IT documents, complete with a live PDF preview.


πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Key Functional Areas
  3. Dependencies & Technologies
  4. View Model & Data Models
  5. Dynamic Indexing Form Logic
  6. API Endpoints & Form Actions
  7. Helper Scripts & Utilities
  8. Error Handling & Validation
  9. UML Diagram
  10. Usage Examples
  11. Conclusion

🧐 1. Overview & Purpose

SaveDoc.cshtml provides a user interface for:

  • Selecting a Document Type
  • Retrieving relevant index fields based on that type
  • Prompting the user to enter or select index values
  • Previewing the PDF in an embedded viewer
  • Persisting the indexed document to the server

πŸ“Œ Intended for legal, safety, and IT document workflows, this view ensures consistent metadata capture before saving.


πŸ”‘ 2. Key Functional Areas

Section Description
Initialization Reads Model.BatchIds, sets category, builds guidList.
Styles Includes Datepicker & Dropzone CSS.
Form #1: Document Type Dropdown to choose document type & fetch indexes.
Form #2: Save Document Dynamically renders index fields based on Model.IndexList.
PDF Preview Embeds a scalable PDF viewer using DocumentPreview action.
Scripts jQuery, Select2, Spinner (spin.js), loading overlay.

πŸ› οΈ 3. Dependencies & Technologies

  • ASP.NET MVC & Razor
  • Syncfusion EJ2 (Syncfusion.JavaScript, Syncfusion.EJ2)
  • Newtonsoft.Json
  • Bootstrap (v4/5)
  • jQuery
  • Select2 (enhanced <select>)
  • Spin.js (loading spinner)
  • Bootstrap Datepicker & Dropzone CSS

πŸ“¦ 4. View Model & Data Models

public class DocumentImaging {
  public Guid DocumentImageId { get; set; }
  public string FilePath { get; set; }
  public string ContentType { get; set; }
  public Guid ReferenceId { get; set; }     // docId
  public Guid IndexTag { get; set; }        // indexTagId
  public bool IsLegalDocument { get; set; }
  public bool IsSafety { get; set; }
  public bool IsIT { get; set; }
  public IEnumerable<Guid> BatchIds { get; set; }
  public List<SelectListItem> DocumentTypes { get; set; }
  public string DocumentType { get; set; }
  public List<IndexField> IndexList { get; set; }
  public IEnumerable<SelectListItem> EmployeeData { get; set; }
  public IEnumerable<SelectListItem> JobData { get; set; }
  public IEnumerable<SelectListItem> CustomerData { get; set; }
  public IEnumerable<SelectListItem> StateData { get; set; }
  // ...
}

public class IndexField {
  public Guid Id { get; set; }
  public string AttributeName { get; set; }
  public string IndexValue { get; set; }
  public AttributeType AttributeType { get; set; }
  public bool IsMultiValue { get; set; }
  public bool IsRequired { get; set; }
  public bool LinkEmployeeData { get; set; }
  public bool LinkJobData { get; set; }
  public bool LinkCustomerData { get; set; }
  public IEnumerable<SelectListItem> MultiValueTypes { get; set; }
}

✨ 5. Dynamic Indexing Form Logic

The view loops through each IndexField in Model.IndexList and selects an input type based on:

  1. AttributeType (Text, Character, Date, Number, Currency, Boolean, etc.)
  2. IsMultiValue
  3. LinkEmployeeData / LinkJobData / LinkCustomerData
  4. Special-cases (e.g., Customer Number, Customer Name, State fields)

Input Mapping Table

Condition Control
Text or Character & not multi/link & not state <textarea>
LinkEmployeeData <select asp-items="@Model.EmployeeData">
LinkJobData <select asp-items="@Model.JobData">
LinkCustomerData + Customer Number <select asp-items="@Model.CustomerData">
LinkCustomerData + Customer Name (read-only) <textarea readonly>
Contains "State" <select asp-items="@Model.StateData">
IsMultiValue <select asp-items="@Model.IndexList[i].MultiValueTypes">
Date <input type="date">
Number <input type="number" step="0.01">
Currency $ <input type="number" step="0.01">
Boolean <select> with Yes/No
Default <textarea>
@for (var i = 0; i < Model.IndexList.Count; i++)
{
  var field = Model.IndexList[i];
  <label>@field.AttributeName</label>
  @* Render input based on field.AttributeType, etc. *@
}

πŸ”— 6. API Endpoints & Form Actions

Form Action Controller Method Purpose
Select Document Type SaveDoc LegalImaging POST Fetch index list for chosen DocumentType
Save Document Save LegalImaging POST Persist document + index metadata
PDF Preview DocumentPreview/{id} LegalImaging GET Streams PDF for client-side embed
[HttpGet]
public IActionResult DocumentPreview(Guid id) { /* return FileStream */ }

[HttpPost]
public IActionResult SaveDoc(DocumentImaging model) { /* populate IndexList */ }

[HttpPost]
public IActionResult Save(DocumentImaging model) { /* save to DB */ }

🧩 7. Helper Scripts & Utilities

  • Select2 Initialization
    $('.js-example-basic-single').select2();
    
  • Loading Overlay & Spinner
    $("#saveDocument").click(function() {
      $("#loading").fadeIn();
      new Spinner(opts).spin(document.getElementById('loading'));
    });
    
  • Auto-populate Customer Name
    $("#Customer\\ Number").on("change", function () {
      let [ , ...rest ] = $(this).val().split("-");
      $("#Customer\\ Name").val(rest.join("-"));
    });
    

🚨 8. Error Handling & Validation

  • Anti-Forgery Token: @Html.AntiForgeryToken()
  • Validation Summary: @Html.ValidationSummary(true, "", new { @class = "text-danger" })
  • Field-level Data Annotations on DocumentImaging and IndexField ensure required flags, valid types, etc.

πŸ“ˆ 9. UML Diagram

classDiagram
    LegalImagingController <|-- SaveDoc
    LegalImagingController <|-- Save
    LegalImagingController <|-- DocumentPreview

    class LegalImagingController {
      +IActionResult SaveDoc(DocumentImaging model)
      +IActionResult Save(DocumentImaging model)
      +IActionResult DocumentPreview(Guid id)
    }

    class DocumentImaging {
      +Guid DocumentImageId
      +string FilePath
      +bool IsLegalDocument
      +bool IsSafety
      +bool IsIT
      +List<IndexField> IndexList
      +List<SelectListItem> DocumentTypes
      +IEnumerable<SelectListItem> EmployeeData
      +...
    }

    class IndexField {
      +Guid Id
      +string AttributeName
      +AttributeType AttributeType
      +bool IsMultiValue
      +bool LinkEmployeeData
      +bool LinkJobData
      +bool LinkCustomerData
      +IEnumerable<SelectListItem> MultiValueTypes
      +string IndexValue
    }

πŸ› οΈ 10. Usage Examples

  1. Controller Invocation

    public IActionResult SaveDoc()
    {
        var model = new DocumentImaging {
          BatchIds = GetCurrentBatchIds(),
          DocumentTypes = GetDocumentTypes(),
          // ...
        };
        return View(model);
    }
    
  2. Rendering the View

    @model IrbyImaging.Models.DocumentImaging
    <!-- SaveDoc.cshtml -->
    
  3. Submit & Save

    • Click Get Indexes to populate fields
    • Fill metadata
    • Click Save Document to persist

🎯 11. Conclusion

SaveDoc.cshtml is a dynamic, data-driven Razor view designed to streamline document indexing and storage. By combining ASP.NET MVC, Syncfusion, and modern JavaScript plugins, it provides an intuitive interface for:

  • Selecting document types
  • Dynamically generating metadata fields
  • Previewing PDF content
  • Ensuring robust validation & user feedback

Whether you’re managing legal, safety, or IT documentation, this view offers a consistent, extensible, and user-friendly approach to document imaging workflows. πŸš€


Happy Coding! πŸ“