šŸ“„ SaveDoc.cshtml Documentation


File: IrbyImaging/Views/AccountingImaging/SaveDoc.cshtml
Purpose: Razor view for selecting a document type, entering indexing metadata, previewing the PDF, and ultimately saving the document in the accounting imaging workflow.


Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Data Model & ViewModel
  4. Key Functional Areas
    4.1. Document Type Selection Form
    4.2. Dynamic Document Indexing Form
    4.3. PDF Preview
    4.4. Loading Spinner & Scripts
  5. Detailed Code Walkthrough
    5.1. Pre‐Render Logic & Variables
    5.2. Form #1: Get Indexes
    5.3. Form #2: Save Document
  6. UML Sequence Diagram
  7. Usage Example in Controller
  8. Error Handling & Validation
  9. Third‐Party Integrations
  10. Conclusion

1. Overview & Purpose

This Razor view is part of the AccountingImaging area. It guides the user through:

  • Step 1: Selecting the document type from a dropdown.
  • Step 2: Fetching the required index fields (metadata) for that document type (Get Indexes).
  • Step 3: Filling in those fields dynamically.
  • Step 4: Previewing the PDF document on the right.
  • Step 5: Submitting the metadata & file for persistence.

šŸ’” Goal: Provide a fluid, single-page interface for uploading, indexing, previewing, and saving accounting documents.


2. Dependencies & Technologies

Technology / Library Purpose
ASP.NET Core MVC Razor Server‐side view engine & tag helpers
jQuery DOM manipulations, event handling
Select2 Enhanced dropdowns & multi‐select
Bootstrap (CSS/JS) Layout, styling, responsive grid
Spin.js Loading spinner animation
Bootstrap Datepicker (CSS imported, ready if date fields are needed)
Dropzone (CSS imported, for custom file drop UI if needed)
Syncfusion (commented) Option for advanced controls (multi‐select, grids)
Newtonsoft.Json JSON serialization (imported but unused here)

3. Data Model & ViewModel

namespace IrbyImaging.Models
{
  public class DocumentImaging
  {
    public Guid DocumentImageId { get; set; }
    public string FilePath { get; set; }
    public string Preview { get; set; }
    public string ImagingType { get; set; }
    public bool IsLegalDocument { get; set; }   // flags for category
    public bool IsSafety { get; set; }
    public bool IsIT { get; set; }
    public bool IsAccounting { get; set; }
    public bool IsBidding { get; set; }
    public List<Guid> BatchIds { get; set; }    // batch membership
    public string IndexTag { get; set; }        // preview identifier
    public string ContentType { get; set; }
    public IEnumerable<SelectListItem> DocumentTypes { get; set; }
    public string DocumentType { get; set; }    // selected type key
    public IEnumerable<IndexViewModel> IndexList { get; set; }
    // EmployeeData, JobData, CustomerData, StateData, etc.
  }

  public class IndexViewModel
  {
    public int Id { get; set; }
    public string AttributeName { get; set; }
    public AttributeType AttributeType { get; set; }
    public bool IsRequired { get; set; }
    public bool IsMultiValue { get; set; }
    public bool LinkEmployeeData { get; set; }
    public bool LinkJobData { get; set; }
    public bool LinkCustomerData { get; set; }
    public string IndexValue { get; set; }           // bound value
    public IEnumerable<SelectListItem> MultiValueTypes { get; set; }
  }

  public enum AttributeType { Text, Character, Date, Number, Currency, Boolean }
}

4. Key Functional Areas

4.1. Document Type Selection Form

šŸ“‹ Purpose: Let the user pick one of the available Document Types for the specified category (accounting) and retrieve the indexing schema.

  • Form posts back to SaveDoc action.
  • Hidden fields carry context (batch IDs, flags, file path, etc.).
  • A <select asp-for="DocumentType"> is populated from Model.DocumentTypes.
  • Get Indexes button triggers the POST → loads Model.IndexList.

4.2. Dynamic Document Indexing Form

āœļø Purpose: Once the server returns the list of required indexes (IndexList), this form renders a loop with varied input types:

  • TextArea for free‐text/index fields.
  • Select for multi‐value or linked data (employee, job, customer).
  • Date, Number, Currency, Boolean inputs based on AttributeType.
  • Hides/shows controls conditionally (e.g., ā€œCustomer Numberā€ → auto‐populate ā€œCustomer Nameā€).

4.3. PDF Preview

šŸ–¼ļø An <embed> on the right side loads:

<embed 
  id="frPDF" 
  height="800" width="800"
  src="@Url.Action("DocumentPreview","LegalImaging", new { id = Model.IndexTag })#zoom=FitH"
  type="application/pdf">

Allows inline preview of the document while indexing.

4.4. Loading Spinner & Scripts

  • Spin.js shows a full‐screen spinner when Save Document is clicked.
  • Select2 enhances <select> elements (.js-example-basic-single).
  • A small jQuery snippet links Customer Number → Customer Name automatically.

5. Detailed Code Walkthrough

5.1. Pre‐Render Logic & Variables

@{
  ViewData["Title"] = "Save Uploaded Document";

  // Extract batch IDs into a comma‐separated string
  var guidList = String.Join(",", Model.BatchIds);
  var category = Model.IsLegalDocument ? "legal"
               : Model.IsSafety       ? "safety"
               : Model.IsIT           ? "it"
               : Model.IsAccounting   ? "accounting"
               : Model.IsBidding      ? "bidding"
               : null;
}
  • guidList: all batch GUIDs for grouping.
  • category: computed from boolean flags.

5.2. Form #1: Get Indexes

<form asp-action="SaveDoc" method="post" id="validation-form">
  @* Hidden context *@
  @Html.HiddenFor(m => m.DocumentImageId)
  @Html.HiddenFor(m => m.FilePath)
  @Html.HiddenFor(m => m.BatchIds, new { Value = guidList })
  @Html.Hidden("category", category)

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

  <button type="submit" id="searchDocument" class="btn btn-primary">
    Get Indexes
  </button>
</form>
  • asp-action="SaveDoc" posts back to the same view to populate IndexList.

5.3. Form #2: Save Document

<form asp-action="Save" method="post" class="form-horizontal">
  @* Same hidden context + selected DocumentType *@
  @Html.HiddenFor(m => m.DocumentType)
  @Html.Hidden("category", category)

  @if (Model.IndexList.Any()) {
    <h4>Save Documents</h4>
    <div data-repeater-list="outer-group">
      @for (var i = 0; i < Model.IndexList.Count; i++)
      {
        var idx = Model.IndexList[i];
        <input type="hidden" asp-for="Model.IndexList[i].Id" />
        <!-- Dynamically pick input based on idx.AttributeType, IsMultiValue, LinkEmployeeData, etc. -->
      }
    </div>
    <button type="submit" id="saveDocument" class="btn btn-primary">
      Save Document
    </button>
  }
</form>
  • Loops through Model.IndexList.
  • Each item’s controls are rendered conditionally (see Key Functional Areas).

6. UML Sequence Diagram

sequenceDiagram
  participant U as User
  participant V as SaveDoc View
  participant C as AccountingImagingController
  participant S as ImagingService
  participant DB as Database

  U->>V: GET /SaveDoc?category=accounting&batchIds=…
  V->>C: invokes SaveDoc(GET)
  C->>S: Load DocumentTypes
  S-->>C: List<SelectListItem>
  C-->>V: View(model)
  V->>U: Show Document Type dropdown

  U->>V: POST SaveDoc with DocumentType=Invoice
  V->>C: SaveDoc(POST)
  C->>S: Load IndexList for Invoice
  S-->>C: List<IndexViewModel>
  C-->>V: View(model w/ IndexList)
  V->>U: Show dynamic index fields & Save button

  U->>V: POST Save with metadata
  V->>C: Save(DocumentImaging)
  C->>S: Persist Document + Index Values
  S->>DB: INSERT Document, IndexValues
  DB-->>S: OK
  S-->>C: OK
  C-->>U: Redirect to Confirmation

7. Usage Example in Controller

public class AccountingImagingController : Controller
{
  private readonly IImagingService _service;

  [HttpGet]
  public IActionResult SaveDoc(string category, List<Guid> batchIds)
  {
    var model = new DocumentImaging {
      IsAccounting = (category=="accounting"),
      BatchIds = batchIds,
      DocumentTypes = _service.GetDocumentTypes(category)
    };
    return View(model);
  }

  [HttpPost]
  [ValidateAntiForgeryToken]
  public IActionResult SaveDoc(DocumentImaging model)
  {
    if (String.IsNullOrEmpty(model.DocumentType))
      ModelState.AddModelError("DocumentType","Please select a document type.");

    model.IndexList = _service.GetIndexFields(
      model.DocumentType,
      model.Category
    );
    return View(model);
  }

  [HttpPost]
  [ValidateAntiForgeryToken]
  public IActionResult Save(DocumentImaging model)
  {
    if (!ModelState.IsValid) {
      // repopulate IndexList & return view
    }
    _service.SaveDocumentWithIndexes(model);
    return RedirectToAction("Confirmation");
  }
}

8. Error Handling & Validation

  • @Html.ValidationSummary(true) displays server‐side model errors.
  • Required fields are enforced in the controller & by IndexViewModel.IsRequired.
  • Unselected DocumentType triggers a ModelState error.
  • The forms carry anti‐forgery tokens.

9. Third‑Party Integrations

Library Usage
Select2 .select2() enhances <select> for linked data (Employee, Customer).
Spin.js Shows a loading indicator (#loading) while document is saving.
Bootstrap Grid and button styling.
Dropzone CSS Loaded (but not used in this file) for potential drag‐and‐drop UI.
Syncfusion References imported but commented out—optionally used for multi‐select.

10. Conclusion

This view (SaveDoc.cshtml) orchestrates a two‐step process to:

  1. Select the correct document type
  2. Index the document metadata dynamically
  3. Preview the PDF inline
  4. Save the document & metadata

The design is highly configurable: as new document types or attributes are added in the service layer, SaveDoc automatically adapts its form. With built‑in validation and third‑party enhancements (Select2, Spin.js), it provides a smooth user experience for accounting document imaging. šŸŽ‰


End of Documentation