SaveDocument.cshtml 📄

Path: IrbyImaging/Views/HRImaging/SaveDocument.cshtml
Purpose: Render the “Save Uploaded Document” page for the HR Imaging module. It allows users to preview scanned PDFs, select document types, retrieve index metadata fields dynamically, and then save the document along with its indexing information.


Table of Contents 📑

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Data Models & ViewModels
  4. Layout & Sections
  5. Key Functional Areas
  6. Third‐Party Integrations & Plugins
  7. Sample Code Blocks
  8. Usage Examples
  9. Error Handling & Validation
  10. UML Sequence Diagram
  11. Conclusion

Overview & Purpose 🚀

This Razor view is part of the HRImaging area in the IrbyImaging solution. It enables:

  • PDF Preview: Displaying the scanned document for visual confirmation.
  • Document‐Type Selection: Allowing the user to pick a DocumentType from a dropdown.
  • Index Metadata Retrieval: Fetching a dynamic set of fields (text, date, number, selects) based on the chosen document type.
  • Metadata Entry & Save: Capturing user‐entered metadata (indexes) and saving the document batch with all associated data.
  • Access Control: Adding user roles (via multiselect) that can view/manage the document.

Dependencies & Technologies ⚙️

Technology / Library Purpose
ASP.NET Core MVC (Razor) Server‐side view rendering
Syncfusion EJ2 / ejs‐multiselect Rich JavaScript dropdown & multitple select UI
jQuery DOM manipulation & event handling
Select2 Enhanced <select> with search/filtering
Bootstrap Datepicker Date‐picker styling & functionality
Dropzone.js (Prepared CSS included – for drag‐drop uploads)
Newtonsoft.Json JSON serialization (if needed)

Data Models & ViewModels 📝

public class DocumentImaging
{
    public Guid DocumentImageId { get; set; }
    public string FilePath { get; set; }
    public string Preview { get; set; }
    public IList<Guid> BatchIds { get; set; }
    public Guid ReferenceId { get; set; }
    public string ContentType { get; set; }
    public string IndexTag { get; set; }

    // Populated on initial GET
    public IEnumerable<SelectListItem> DocumentTypes { get; set; }

    // Populated after “Get Indexes” POST
    public IList<IndexField> IndexList { get; set; }

    // Data sources for linked dropdowns
    public IEnumerable<SelectListItem> EmployeeData { get; set; }
    public IEnumerable<SelectListItem> JobData { get; set; }
    public IEnumerable<SelectListItem> CustomerData { get; set; }
    public IEnumerable<SelectListItem> StateData { get; set; }

    // For multi‐value fields (boolean, list, etc.)
    public IEnumerable<SelectListItem> MultiValueTypes { get; set; }
}

public class IndexField
{
    public Guid Id { get; set; }
    public string AttributeName { 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 string IndexValue { get; set; }
    public IEnumerable<SelectListItem> MultiValueTypes { get; set; }
}

Layout & Sections 🎨

  • Layout: ~/Views/Shared/_Layout.cshtml
  • Title: Set via ViewData["Title"] = "Save Uploaded Document"
  • Sections:
    • @section styles { … } — includes CSS for datepicker & Dropzone.
    • @section Scripts { … } — loads jQuery, Select2 CSS/JS, and initializes Select2 on <select>s.

Key Functional Areas 🔑

1. Document Type Selection & “Get Indexes” 🔍

<form asp-action="SaveDoc" method="post" id="validation-form">
  @Html.HiddenFor(m => m.DocumentImageId)
  @Html.HiddenFor(m => m.FilePath)
  @Html.HiddenFor(m => m.Preview)
  @Html.HiddenFor(m => m.BatchIds, new { Value = lists })
  @Html.AntiForgeryToken()

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

  <input type="hidden" id="batchId" value="@guidList" />
  <button type="submit" id="searchDocument"
          class="btn btn-primary">Get Indexes</button>
</form>
  • Hidden fields: Pass along batch IDs, file path, preview URI.
  • Dropdown: <select> lists all available document types from Model.DocumentTypes.
  • Submit: Calls HRImagingController.SaveDoc to load the relevant index fields.

2. PDF Preview 📑

<embed id="frPDF"
       src="@Url.Action("DocumentPreview","HRImaging", new { id = indexTagId })#zoom=FitH"
       width="100%" height="800px" type="application/pdf" />
  • Displays the scanned PDF inside an <embed> tag.
  • indexTagId ensures the PDF is referenced correctly in the controller.

3. Dynamic Indexing Form & Save ✔️

@if (Model.IndexList.Any())
{
  <form asp-action="Save" method="post" id="validation-form">
    @* Hidden fields to carry context *@
    @Html.HiddenFor(m => m.DocumentType)
    @Html.HiddenFor(m => m.HRDocumentType)
    @Html.HiddenFor(m => m.BatchIds, new { Value = lists })
    @Html.AntiForgeryToken()

    <h4>Search Documents (Metadata Entry)</h4>
    @for (var i = 0; i < Model.IndexList.Count; i++)
    {
      var field = Model.IndexList[i];
      // 1) Emit hidden metadata about each field
      <input type="hidden" asp-for="@field.Id" />
      <input type="hidden" asp-for="@field.AttributeType" />
      // 2) Render input UI according to AttributeType & flags
      @* e.g., Textarea, <select> with EmployeeData, date input, number input, etc. *@
    }

    <label>Add Roles</label>
    <ejs-multiselect id="roles" dataSource="ViewBag.Roles" placeholder="Select a Role">
      <e-multiselect-fields text="Name" value="RoleId"></e-multiselect-fields>
    </ejs-multiselect>

    <input type="hidden" id="batchId" value="@guidList" />
    <button type="submit" class="btn btn-primary">Save Document</button>
  </form>
}
  • Dynamic Field Rendering:

    • Text/Character → <textarea>
    • Date → <input type="date">
    • Number/Currency → <input type="number"> (+ “$” prefix for currency)
    • Boolean → <select> with Yes/No
    • Linked Data (Employee/Job/Customer/State) → <select> populated from Model.EmployeeData, etc.
    • Multi‐value → <select> with Model.MultiValueTypes.
  • Roles Multiselect:
    Uses Syncfusion <ejs-multiselect> to assign roles that can access/manage the document.


Third‐Party Integrations & Plugins 🔗

Plugin Usage
Syncfusion EJ2 <ejs-multiselect> for roles & other linked lists.
Select2 Enhanced single‐select styling & search.
Bootstrap Datepicker CSS is included (JS can be added if needed).
Dropzone (CSS only) Prepared for drag‐and‐drop upload UIs.

Initialization snippet for Select2:

@section Scripts {
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <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>
}

Sample Code Blocks 💻

Controller Actions (illustrative):

public class HRImagingController : Controller
{
  [HttpGet]
  public IActionResult SaveDocument(Guid referenceId, List<Guid> batchIds)
  {
    var model = new DocumentImaging {
      ReferenceId   = referenceId,
      BatchIds      = batchIds,
      DocumentTypes = _service.GetDocumentTypes()
    };
    return View(model);
  }

  [HttpPost]
  public IActionResult SaveDoc(DocumentImaging model)
  {
    // 1. Validate DocumentType
    // 2. Load dynamic IndexList from DB
    model.IndexList = _service.GetIndexFields(model.DocumentType);
    // repopulate lookups
    model.EmployeeData = _service.GetEmployees();
    // ...
    return View("SaveDocument", model);
  }

  [HttpPost]
  public IActionResult Save(DocumentImaging model)
  {
    if (!ModelState.IsValid)
      return View("SaveDocument", model);

    _service.SaveIndexedDocument(model);
    return RedirectToAction("Index", "HRImaging");
  }
}

Usage Examples 🖥️

  1. Initial Access
    GET

    /HRImaging/SaveDocument?referenceId={docGuid}&batchIds={guid1,guid2}
    
  2. Retrieve Index Fields
    After selecting a type and clicking Get Indexes, POST to:

    /HRImaging/SaveDoc
    
  3. Save Completed Document
    When metadata is filled, clicking Save Document triggers POST to:

    /HRImaging/Save
    

Error Handling & Validation ❗

  • @Html.ValidationSummary(true) displays model‐level errors at the top.
  • Each input control can be decorated with data annotations for field‐level validation.
  • On form POSTs, server‐side validation (ModelState.IsValid) must be checked in controller actions.
  • Anti‐Forgery token (@Html.AntiForgeryToken()) protects against CSRF attacks.

UML Sequence Diagram 📊

@startuml
actor User
User -> SaveDocumentView : GET /HRImaging/SaveDocument
SaveDocumentView -> Controller : SaveDocument(referenceId, batchIds)
Controller -> Service : GetDocumentTypes()
Service --> Controller : List<SelectListItem>
Controller -> SaveDocumentView : view(model)

User -> SaveDocumentView : Select Type + Get Indexes
SaveDocumentView -> Controller : POST /SaveDoc
Controller -> Service : GetIndexFields(documentType)
Service --> Controller : IndexList
Controller -> SaveDocumentView : view(model with IndexList)

User -> SaveDocumentView : Fill metadata + Save
SaveDocumentView -> Controller : POST /Save
Controller -> Service : SaveIndexedDocument(model)
Service --> Controller : Success
Controller -> User : RedirectToAction(Index)
@enduml

Conclusion 🎉

The SaveDocument.cshtml view is a rich, data‐driven interface for capturing and saving scanned HR documents with their metadata. It leverages:

  • Two‐step workflow: select/document‐type → retrieve metadata fields → save.
  • Dynamic form generation based on IndexList.
  • Inline PDF preview for user validation.
  • Third‐party widgets (Syncfusion, Select2) for an enhanced UX.

By following this pattern, you can easily extend support for new document types, metadata attributes, or integrate additional lookup sources. Happy coding!