📄 DocumentCategories.cshtml Documentation

Welcome to the in‑depth documentation for the Razor view file
IrbyImaging/Views/AccountingImaging/DocumentCategories.cshtml.
This document will guide you through its purpose, key features,
dependencies, and how to use it—complete with code snippets,
UML diagrams, and usage examples.


📑 Table of Contents

  1. Overview & Purpose
  2. ViewModel & Data Models
    2.1. DocumentCategoryView
    2.2. DocumentCategoryDto
  3. Key Functional Areas
    3.1. Page Initialization
    3.2. “Add New Category” Form
    3.3. Syncfusion EJ2 TreeGrid
    3.4. Search 🔍
    3.5. Modal Detail View
    3.6. Export Toolbar
    3.7. Date Formatting
    3.8. Grid-Line Toggle
  4. Dependencies & Technologies
  5. Helper Methods & Utilities
  6. API Endpoints Overview
  7. UML Diagrams
    7.1. Class Diagram
    7.2. Sequence Diagram
  8. Sample Code Snippets
  9. Usage Example
  10. Conclusion & Best Practices

1. Overview & Purpose

This Razor view renders a hierarchical list of Document Categories
for the Accounting imaging module. It empowers users to:

  • ✅ View categories in a collapsible TreeGrid
  • ➕ Add new categories
  • ✏️ Edit or 🗑️ Delete existing categories
  • 🔍 Search within categories
  • 📤 Export to Excel, CSV, PDF or Print
  • 📋 View sub‑types in a modal dialog

Designed with Syncfusion EJ2 components and jQuery, it delivers
a rich interactive UI for managing document‑category metadata.


2. ViewModel & Data Models

This view is strongly typed to the DocumentCategoryView model.
Below is a conceptual outline of the ViewModel and its nested DTO.

2.1. DocumentCategoryView

public class DocumentCategoryView
{
    public int Id { get; set; }
    public string ImagingType { get; set; }
    public bool IsLegal { get; set; }
    public bool IsSafety { get; set; }
    public bool IsIT { get; set; }
    public bool IsAccounting { get; set; }
    public bool IsBidding { get; set; }

    // Hierarchical list of categories
    public IEnumerable<DocumentCategoryDto> DocList { get; set; }
}

2.2. DocumentCategoryDto

public class DocumentCategoryDto
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string TypeList { get; set; }
    public bool IsAvailable { get; set; }
    public bool IsDeleted { get; set; }
    public string AddedBy { get; set; }
    public DateTime AddedDate { get; set; }
    public string ModifiedBy { get; set; }
    public DateTime? ModifiedDate { get; set; }

    // Child categories (for the TreeGrid)
    public List<DocumentCategoryDto> Children { get; set; }
}

3. Key Functional Areas

3.1. Page Initialization

@{
    ViewBag.Title     = "Document Categories";
    ViewBag.pTitle    = "Document Categories";
    ViewBag.pageTitle = "Document Categories";
}
<h2>Document Categories</h2>
  • Sets page titles via ViewBag.
  • Renders the main <h2> header.

3.2. “Add New Category” Form

<div class="col-lg-2">
  <form asp-action="CreateCategory">
    @Html.HiddenFor(m => m.ImagingType)
    @Html.HiddenFor(m => m.IsLegal)
    ...
    <div class="form-group">
      <input type="submit"
             value="Add New Document Category"
             class="btn btn-success irby-green"/>
    </div>
  </form>
</div>
  • Hidden fields carry context flags (Legal, Safety, IT, etc.).
  • A green button to navigate to the CreateCategory action.

3.3. Syncfusion EJ2 TreeGrid

<ejs-treegrid id="TreeGrid"
              load="load"
              dataSource="Model.DocList"
              childMapping="Children"
              treeColumnIndex="0"
              allowFiltering="true"
              allowSorting="true"
              allowPaging="true"
              toolbar="@(new List<string>() {"ExcelExport","CsvExport","PdfExport","Print"})"
              frozenColumns="2">
  <!-- Column Definitions -->
  <e-treegrid-columns>
    <e-treegrid-column field="Name" headerText="Name" width="220"></e-treegrid-column>
    <e-treegrid-column field="TypeList" headerText="Type List"
                       template="#typetemplate" width="150"></e-treegrid-column>
    <!-- ... more columns ... -->
    <e-treegrid-column field="Edit" template="#edittemplate" width="150"></e-treegrid-column>
    <e-treegrid-column field="Delete" template="#deletetemplate" width="150"></e-treegrid-column>
  </e-treegrid-columns>
</ejs-treegrid>
  • Binds to Model.DocList (hierarchical data).
  • Filtering, sorting, paging, and export toolbar enabled.
  • Frozen first two columns for better UX.

<input type="text" id="searchText" />
<ejs-button id="Search" content="Search" cssClass="e-primary"></ejs-button>

<script>
  document.getElementById('Search')
          .addEventListener('click', function () {
    var text = document.getElementById('searchText').value;
    var grid = document.getElementById('TreeGrid').ej2_instances[0];
    grid.search(text);
  });
</script>
  • A simple text input + Syncfusion button.
  • On click, invokes the TreeGrid’s .search() method.

3.5. Modal Detail View

<div id="myModal" class="modal">
  <div class="modal-dialog">
    <div class="modal-content" id="myModalContent"></div>
  </div>
</div>
<script>
  var TeamDetailPostBackURL = '/AccountingImaging/myModalCategory';
  $(document).on('click', '.anchorDetail', function() {
    var id = $(this).data('id');
    $.get(TeamDetailPostBackURL, { id: id })
     .done(function(html) {
        $('#myModalContent').html(html);
        $('#myModal').modal('show');
     })
     .fail(function() {
        alert("Dynamic content load failed.");
     });
  });
</script>
  • Clicking “View Types” (.anchorDetail) fires AJAX to load a partial view.
  • Renders into the Bootstrap modal.

3.6. Export Toolbar

function toolbarClick(args) {
  var tree = document.getElementById("TreeGrid")
                    .ej2_instances[0];
  if (args.item.id.endsWith('_excelexport')) {
    tree.excelExport({ isCollapsedStatePersist: true });
  }
  else if (args.item.id.endsWith('_pdfexport')) {
    tree.pdfExport({ isCollapsedStatePersist: true });
  }
  else if (args.item.id.endsWith('_csvexport')) {
    tree.csvExport();
  }
}
  • Excel, PDF, CSV exports preserve the collapsed state.

3.7. Date Formatting

function load() {
  var tree = document.getElementById("TreeGrid").ej2_instances[0];
  tree.columns.forEach(function(col) {
    if (col.field === 'AddedDate' || col.field === 'ModifiedDate') {
      col.format = { type: 'date', format: 'M/d/yyyy' };
    }
  });
}
  • On TreeGrid load, formats date columns to M/d/yyyy.

3.8. Grid-Line Toggle

function onChange(e) {
  var tree = document.getElementById("TreeGrid").ej2_instances[0];
  tree.gridLines = e.value;  // e.g., 'Both', 'None', 'Horizontal'
}
  • Dynamically toggles grid lines (if bound to a dropdown or checkbox).

4. Dependencies & Technologies

Technology / Library Purpose
ASP.NET Core MVC Server‑side framework & Razor view engine
Syncfusion EJ2 TreeGrid Hierarchical grid, filtering, exporting, toolbar
jQuery 3.5.1 DOM manipulation & AJAX
DataTables 1.10.25 (Optional) Table features loaded for future use
DataTables Buttons Export buttons (Excel, PDF, Print)
JSZip Excel generation for DataTables
PDFMake PDF generation
Bootstrap Layout & Modal dialog styling
MetisMenu, Simplebar, Node‑waves UI/UX enhancements

5. Helper Methods & Utilities

  • load()
    Configures date formatting on TreeGrid load.
  • toolbarClick(args)
    Handles Excel/PDF/CSV export actions.
  • onChange(e)
    Toggles grid-line visibility.
  • AJAX partial load via .anchorDetail click.

6. API Endpoints Overview

Endpoint Verb Description
/AccountingImaging/DocumentCategories GET Renders this view
/AccountingImaging/CreateCategory GET/POST* Creates a new category form/post
/AccountingImaging/EditCategory/{id} GET Edit existing category
/AccountingImaging/DeleteCategory/{id} GET Delete a category
/AccountingImaging/myModalCategory GET Returns partial view for “View Types”

* By default, form submissions use GET unless explicitly set to POST.


7. UML Diagrams

7.1. Class Diagram

classDiagram
    class DocumentCategoryView {
      +int Id
      +string ImagingType
      +bool IsLegal
      +bool IsSafety
      +bool IsIT
      +bool IsAccounting
      +bool IsBidding
      +IEnumerable~DocumentCategoryDto~ DocList
    }
    class DocumentCategoryDto {
      +int Id
      +string Name
      +string TypeList
      +bool IsAvailable
      +bool IsDeleted
      +string AddedBy
      +DateTime AddedDate
      +string ModifiedBy
      +DateTime? ModifiedDate
      +List~DocumentCategoryDto~ Children
    }
    DocumentCategoryView "1" --> "*" DocumentCategoryDto
    DocumentCategoryDto "1" --> "*" DocumentCategoryDto : Children

7.2. Sequence Diagram

sequenceDiagram
    participant U as User
    participant V as DocumentCategoriesView
    participant TG as Syncfusion TreeGrid
    participant C as AccountingImagingController

    U->>V: GET /DocumentCategories
    V->>TG: Initialize with Model.DocList
    loop Browse / Interact
      U->>V: Click “Search”
      V->>TG: grid.search(text)
      U->>V: Click “View Types”
      V->>C: AJAX GET /myModalCategory?id
      C-->>V: Partial HTML
      V->>U: Show modal
      U->>V: Click Export PDF
      V->>TG: tree.pdfExport()
    end

8. Sample Code Snippets

8.1. Razor — TreeGrid Declaration

<ejs-treegrid id="TreeGrid"
              dataSource="Model.DocList"
              childMapping="Children"
              allowPaging="true"
              toolbar="@(new List<string>() { "ExcelExport","CsvExport","PdfExport","Print"})">
  <e-treegrid-columns>
    <e-treegrid-column field="Name" headerText="Name"></e-treegrid-column>
    <!-- ... -->
  </e-treegrid-columns>
</ejs-treegrid>

8.2. JavaScript — AJAX Load

$(document).on('click', '.anchorDetail', function() {
  var id = $(this).data('id');
  $.get('/AccountingImaging/myModalCategory', { id: id })
   .done(html => {
     $('#myModalContent').html(html);
     $('#myModal').modal('show');
   });
});

9. Usage Example

public class AccountingImagingController : Controller
{
    public IActionResult DocumentCategories()
    {
        // Retrieve hierarchical categories from database/service
        var categories = _repo.GetDocumentCategories();

        var vm = new DocumentCategoryView {
            Id            = 0,
            ImagingType   = "Accounting",
            IsAccounting  = true,
            DocList       = categories
        };

        return View(vm);
    }
}

10. Conclusion & Best Practices

🎯 DocumentCategories.cshtml provides a dynamic,
feature‑rich interface for managing document categories in the
Accounting context.

Best Practices

  • Ensure the ViewModel is populated with the correct hierarchy.
  • Lazy‑load large data sets or implement server‑side paging if data grows.
  • Leverage Syncfusion’s event hooks for custom behaviors.
  • Keep JavaScript concise and modular (extract to separate .js files).

With this documentation, you have a complete reference to understand,
maintain, and extend the Document Categories UI in your ASP.NET Core MVC project.
Happy coding! 🚀


End of Document
Generated on 🗓️ today’s date