SaveDoc.cshtml Documentation 📝

Welcome to the comprehensive guide for IrbyImaging/Views/HRImaging/SaveDoc.cshtml. This Razor view powers the “Save Uploaded Document” page in the HR Imaging module. Below you’ll find a Table of Contents, detailed explanations of each section, code snippets, UML diagrams, and tips on how to use and extend it.


Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. View Model & Data Model
  4. Key Functional Areas
    4.1. Document Type Selection
    4.2. Dynamic Index Fields Generation
    4.3. Roles MultiSelect
    4.4. Save Document Flow
    4.5. PDF Preview Panel
  5. Helper Methods & Utilities
  6. Third‑Party Integrations
  7. Error Handling & Validation
  8. API Endpoints Overview
  9. Sample Code Snippets & Usage
  10. UML Diagram
  11. Conclusion

1. Overview & Purpose 📋

SaveDoc.cshtml is the final step in the HR Imaging process. It enables users to:

  • Select a document type
  • Fetch its indexing metadata
  • Enter index values (text, dates, numbers, dropdowns)
  • Assign role‑based access
  • Preview the PDF
  • Save the document and its metadata

This page binds to the IrbyImaging.Models.DocumentImaging view model, marshals data from multiple lookups (employees, jobs, customers, states), and posts back to the controller for persistence.


2. Dependencies & Technologies 📦

Category Library / Tool Purpose
Frontend Styling Bootstrap, SimpleBar, MetisMenu Layout, scrollbars, menus
JS Utilities jQuery DOM manipulation
Select2 Enhanced <select>s with search
Spin.js Loading spinner overlay
bootstrap-datepicker Date picker styling
dropzone (CSS only) Drag‑and‑drop upload styling
ASP.NET Core MVC Razor, Tag Helpers View rendering & model binding
JSON Handling Newtonsoft.Json JSON serialization if needed
Syncfusion EJ2 <ejs-multiselect> Multi‑select UI component

3. View Model & Data Model 🏗️

View Model: DocumentImaging

public class DocumentImaging {
  public Guid ReferenceId { get; set; }  
  public IEnumerable<Guid> BatchIds { get; set; }  
  public string FilePath { get; set; }  
  public string ContentType { get; set; }  
  public int IndexTag { get; set; }  
  public List<IndexField> IndexList { get; set; }  
  public IEnumerable<SelectListItem> DocumentTypes { get; set; }  
  public IEnumerable<SelectListItem> EmployeeData { get; set; }  
  public IEnumerable<SelectListItem> JobData { get; set; }  
  public IEnumerable<SelectListItem> CustomerData { get; set; }  
  public IEnumerable<SelectListItem> CustomerData1 { get; set; }  
  public IEnumerable<SelectListItem> StateData { get; set; }  
}

IndexField Model:

Property Type Use
Id int Unique identifier
AttributeName string Display label
AttributeType AttributeType (Enum) Text, Character, Date, Number, Currency, Boolean
IsRequired bool Must be filled
IsMultiValue bool Renders multi‑select
LinkEmployeeData bool Populate from EmployeeData
LinkJobData bool Populate from JobData
LinkCustomerData bool Populate from CustomerData / CustomerData1
IndexValue string Holds the entered / selected value
MultiValueTypes IEnumerable<SelectListItem> Options for multi‑value selects

4. Key Functional Areas 🔑

4.1 Document Type Selection 🎯

Users pick a document type to fetch the correct indexing schema:

<label class="col-md-3 col-form-label">Document Type</label>
<div class="col-md-9">
  <select asp-for="DocumentType"
          asp-items="@Model.DocumentTypes"
          class="form-control">
    <option value="" disabled selected>
      Select Document Type
    </option>
  </select>
</div>
<button type="submit" id="searchDocument" class="btn btn-primary">
  Get Indexes
</button>
  • POSTs back to HRImagingController.SaveDoc
  • Populates Model.IndexList

4.2 Dynamic Index Fields Generation 🔄

The view loops through Model.IndexList and, based on metadata, renders the appropriate input:

  • Text / Character → <textarea>
  • Date → <input type="date">
  • Number/Currency → <input type="number"> (step, min)
  • Boolean → <select> with Yes/No
  • State → dropdown bound to Model.StateData
  • MultiValue → <select multiple> with MultiValueTypes
  • Linked Data → dropdowns bound to EmployeeData, JobData, CustomerData
@for (var i = 0; i < Model.IndexList.Count; i++) {
  var field = Model.IndexList[i];
  if (field.AttributeType == AttributeType.Date) {
    <div class="row mb-4">
      <label class="col-form-label col-lg-3">
        @field.AttributeName
      </label>
      <div class="col-lg-9">
        <input asp-for="@field.IndexValue"
               type="date"
               id="@field.AttributeName" />
      </div>
    </div>
  }
}

4.3 Roles MultiSelect 👥

Users can assign which roles may access the saved document:

<ejs-multiselect id="roles"
                 dataSource="ViewBag.Roles"
                 placeholder="Select Roles">
  <e-multiselect-fields text="Name" value="RoleId"></e-multiselect-fields>
</ejs-multiselect>
  • Syncfusion EJ2 component
  • Multi‑select with checkboxes

4.4 Save Document Flow 💾

  1. Hidden fields keep track of:
    • DocumentImageId
    • BatchIds
    • FilePath
    • DocumentType
  2. Anti‑Forgery token
  3. User clicks Save Document → triggers jQuery to show loading overlay & spinner → form submits to HRImaging/Save
$("#saveDocument").click(function() {
  $("#loading").fadeIn();
  var spinner = new Spinner(opts).spin(document.getElementById('loading'));
});

4.5 PDF Preview Panel 📄

An embedded PDF viewer allows users to double‑check the scanned document:

<embed id="frPDF"
       src="@Url.Action("DocumentPreview","HRImaging", new { id = Model.IndexTag })#zoom=FitH"
       type="application/pdf"
       width="800" height="800" />
  • Zoom set to fit horizontal width
  • Streams directly from DocumentPreview action

5. Helper Methods & Utilities 🛠️

  • guidList Builder:
    var guidList = string.Join(",", Model.BatchIds);
    
  • Select2 Initialization:
    $(document).ready(function() {
      $('.js-example-basic-single').select2();
    });
    
  • Loading Overlay Styles in <style> block

6. Third‑Party Integrations 🔗

Library Usage
Syncfusion EJ2 <ejs-multiselect> for roles
Select2 Enhanced single/multi <select>s
Spin.js Custom loading spinner
Dropzone (CSS only) drag/drop upload styling
bootstrap-datepicker Date‑picker styling (CSS only)

7. Error Handling & Validation 🚨

  • @Html.ValidationSummary(true) shows model errors
  • Individual <input>s / <select> can leverage asp-validation-for
  • [ValidateAntiForgeryToken] attribute on POST actions

8. API Endpoints Overview 🌐

Route / Action Verb Description
HRImaging/SaveDoc (GET/POST) GET Renders the view → POST fetches indexes
HRImaging/Save (POST) POST Persists document metadata & file
HRImaging/DocumentPreview GET Streams PDF for embed preview

9. Sample Code Snippets & Usage 💡

Controller: Prepare the model

public IActionResult SaveDoc(Guid referenceId, List<Guid> batchIds) {
  var model = new DocumentImaging {
    ReferenceId = referenceId,
    BatchIds    = batchIds,
    DocumentTypes = GetDocTypeSelectList(),
    EmployeeData = GetEmployeeSelectList(),
    JobData      = GetJobSelectList(),
    CustomerData = GetCustomerSelectList(),
    StateData    = GetStateSelectList(),
    IndexList    = new List<IndexField>() // initially empty
  };
  return View(model);
}

Controller: Handle Save

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

  _documentService.SaveDocumentWithIndexes(model);
  return RedirectToAction("Index");
}

10. UML Diagram 📊

@startuml
class DocumentImaging {
  +Guid ReferenceId
  +IEnumerable<Guid> BatchIds
  +string FilePath
  +List<IndexField> IndexList
  +IEnumerable<SelectListItem> DocumentTypes
  +…
}
class IndexField {
  +int Id
  +string AttributeName
  +AttributeType AttributeType
  +string IndexValue
  +bool IsRequired
  +bool IsMultiValue
  +bool LinkEmployeeData
  +…
}
DocumentImaging "1" --> "0..*" IndexField
@enduml

11. Conclusion 🎉

SaveDoc.cshtml delivers a dynamic, extensible, and user‑friendly interface for capturing document metadata in the HR imaging workflow. By leveraging ASP.NET Core Razor, Syncfusion EJ2, Select2, and Spin.js, it:

  • Adapts to any document type
  • Renders custom index fields automatically
  • Provides PDF preview
  • Ensures role‑based access
  • Includes robust validation & spinner UX

Use this guide to customize, extend, or integrate this view into your own workflow. Happy documenting! 🚀