📄 EditCategory.cshtml Documentation

Module: IrbyImaging/Views/AccountingImaging/EditCategory.cshtml
Purpose: Razor view for editing an existing Document Category under the Accounting Imaging module.


📑 Table of Contents

  1. 🔍 Overview & Purpose
  2. 📦 Dependencies & Technologies
  3. 🏗️ MVC Structure
    3.1. Controller Actions
    3.2. Model: DocumentCategoryView
    3.3. View: EditCategory.cshtml
  4. 🔑 Key Functional Areas
    4.1. Category‐String Mapping
    4.2. Form Rendering & Validation
    4.3. Action Buttons & Routing
  5. 🛠️ Helper Methods & Utilities
  6. 🌐 API Endpoints Overview
  7. 📱 Third‑Party Integrations
  8. 💻 Sample Code Blocks
  9. 📊 UML Sequence Diagram
  10. 🔄 Usage Examples
  11. 🏁 Conclusion

🔍 Overview & Purpose

This Razor view provides a UI for editing an already‐existing document category within the Accounting Imaging module. It renders a form populated with:

  • The category’s Name (read‐only).
  • A text box to update the Description.
  • Checkboxes for IsAvailable (active/inactive) and IsDeleted (soft‐delete).

Upon submission, it POSTs to the EditDocCategory action in the AccountingImagingController. A “Back to List” button returns the user to the document‐category listing for the current imaging type.


📦 Dependencies & Technologies

Technology / Library Purpose
ASP.NET Core MVC (Razor) View‐engine for rendering dynamic HTML
Syncfusion EJ2 (Imported but not directly used in this view)
Bootstrap 5 Layout & form styling (bootstrap.bundle.min.js)
MetisMenu Sidebar navigation
SimpleBar Custom scrollbars
Waves Material‐style “wave” click effect

Note: The @using Syncfusion.* statements hint at potential client‐side widgets, though none are instantiated here.


🏗️ MVC Structure

3.1 Controller Actions

public class AccountingImagingController : Controller
{
    // GET: /AccountingImaging/EditCategory/{id}
    public IActionResult EditCategory(int id)
    {
        var model = _service.GetDocumentCategoryViewById(id);
        return View(model);
    }

    // POST: /AccountingImaging/EditDocCategory
    [HttpPost]
    public IActionResult EditDocCategory(DocumentCategoryView model)
    {
        if (!ModelState.IsValid)
            return View("EditCategory", model);

        _service.UpdateDocumentCategory(model);
        return RedirectToAction("DocumentCategories", new { category = model.ImagingType.ToString().ToLower() });
    }

    // GET: /AccountingImaging/DocumentCategories?category={category}
    public IActionResult DocumentCategories(string category)
    {
        var list = _service.GetCategoriesByType(category);
        return View(list);
    }
}

3.2 Model: DocumentCategoryView

Property Type Description
Id int Primary key of the category
Name string Category name (read‐only in UI)
Description string Free‐form description
IsAvailable bool Toggle whether category is visible/usable
IsDeleted bool Soft delete flag
ImagingType enum ImagingType Indicates domain (Legal, Safety, IT, Accounting, Bidding)
IsLegal bool (computed) True if ImagingType == Legal
IsSafety bool (computed) True if ImagingType == Safety
IsIT bool (computed) True if ImagingType == IT
IsAccounting bool (computed) True if ImagingType == Accounting
IsBidding bool (computed) True if ImagingType == Bidding

Computed IsX flags are used to decide routing and UI context.

3.3 View: EditCategory.cshtml

@model IrbyImaging.UI.Models.DocumentCategoryView
@using Syncfusion.JavaScript
@using Syncfusion.JavaScript.Models
@using Syncfusion.EJ2

@{
    ViewBag.Title     = "Edit Document Category";
    ViewBag.pTitle    = "Edit Document Category";
    ViewBag.pageTitle = "Edit Document Category";

    // Determine the route‐parameter string for “Back to List”
    var category = Model.ImagingType.ToString().ToLower(); 
}

<h2>Update Document Type</h2>
<hr />

<div class="row">
  <div class="col-md-4">
    <form asp-action="EditDocCategory">
      <!-- Hidden fields for preserving state -->
      @Html.HiddenFor(m => m.Id)
      @Html.HiddenFor(m => m.ImagingType)
      @Html.HiddenFor(m => m.IsLegal)
      @* ...other IsX flags *@

      <div asp-validation-summary="ModelOnly" class="text-danger"></div>

      <div class="form-group">
        <label asp-for="Name"></label>
        <input asp-for="Name" class="form-control" required readonly />
        <span asp-validation-for="Name" class="text-danger"></span>
      </div>

      <div class="form-group">
        <label asp-for="Description"></label>
        <input asp-for="Description" class="form-control" />
        <span asp-validation-for="Description" class="text-danger"></span>
      </div>

      <div class="form-group">
        <label asp-for="IsAvailable"></label>
        <input asp-for="IsAvailable" type="checkbox" />
        <span asp-validation-for="IsAvailable" class="text-danger"></span>
      </div>

      <div class="form-group">
        <label asp-for="IsDeleted"></label>
        <input asp-for="IsDeleted" type="checkbox" />
        <span asp-validation-for="IsDeleted" class="text-danger"></span>
      </div>

      <div class="form-group">
        <a asp-action="DocumentCategories"
           asp-controller="AccountingImaging"
           asp-route-category="@category"
           class="btn btn-danger irby-red">
           ← Back to List
        </a>
        <input type="submit" value="Update" class="btn btn-success irby-green" />
      </div>
    </form>
  </div>
</div>

<!-- JS Dependencies -->
<script src="~/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="~/libs/metismenu/metisMenu.min.js"></script>
<script src="~/libs/simplebar/simplebar.min.js"></script>
<script src="~/libs/node-waves/waves.min.js"></script>

🔑 Key Functional Areas

4.1 Category‐String Mapping

At the top of the view:

var category = Model.ImagingType.ToString().ToLower();
ImagingType Enum category string
Legal "legal"
Safety "safety"
IT "it"
Accounting "accounting"
Bidding "bidding"

This ensures the “Back to List” link navigates to the correct filter.

4.2 Form Rendering & Validation

  • HiddenFor: Preserves Id, ImagingType, and all IsX flags.
  • asp-validation-summary: Renders model‐level errors.
  • asp-for: Binds inputs to model properties, rendering server‐ and client‐side validation attributes.

4.3 Action Buttons & Routing

  • Back to List:
    • asp-action="DocumentCategories"
    • asp-route-category="@category"
    • Returns to filtered category list.
  • Update:
    • Submits to EditDocCategory (HTTP POST).
    • If model‐state is valid, updates and redirects.

🛠️ Helper Methods & Utilities

  • No custom helper methods inside this view.
  • Leverages built‑in HTML Helpers (Html.HiddenFor, asp-for, asp-action).

🌐 API Endpoints Overview

Action HTTP route Purpose
EditCategory GET /AccountingImaging/EditCategory/{id} Renders the edit form
EditDocCategory POST /AccountingImaging/EditDocCategory Updates record; on success, redirects.
DocumentCategories GET /AccountingImaging/DocumentCategories?category={cat} Shows filtered category list

📱 Third‑Party Integrations

  • Syncfusion EJ2

    Imported at top but no EJ2 components instantiated. Possibly prepared for future widget enhancements.

  • Bootstrap, MetisMenu, SimpleBar, Waves

    UI layout, sidebar menu, custom scrollbars, click effects.


💻 Sample Code Blocks

Sample Controller Usage

// GET: show the form
public IActionResult EditCategory(int id) =>
    View(_mapper.Map<DocumentCategoryView>(_service.GetById(id)));

// POST: process form
[HttpPost]
public IActionResult EditDocCategory(DocumentCategoryView model)
{
    if (!ModelState.IsValid)
        return View("EditCategory", model);

    _service.Update(model);
    return RedirectToAction("DocumentCategories", 
             new { category = model.ImagingType.ToString().ToLower() });
}

Sample Model Definition

public class DocumentCategoryView
{
    public int Id { get; set; }
    [Required] public string Name { get; set; }
    public string Description { get; set; }
    public bool IsAvailable { get; set; }
    public bool IsDeleted { get; set; }
    public ImagingType ImagingType { get; set; }
    // Computed flags:
    public bool IsAccounting => ImagingType == ImagingType.Accounting;
    // …other IsX…
}

📊 UML Sequence Diagram

sequenceDiagram
    participant U as User
    participant V as EditCategory.cshtml
    participant C as AccountingImagingController
    participant S as DocumentCategoryService
    participant DB as Repository/DB

    U->>C: GET /EditCategory/123
    C->>S: GetById(123)
    S->>DB: SELECT * FROM DocumentCategories WHERE Id=123
    DB-->>S: Entity
    S-->>C: DocumentCategoryView
    C-->>V: Render view(model)

    U->>V: Submit POST form
    V->>C: EditDocCategory(model)
    C->>S: UpdateDocumentCategory(model)
    S->>DB: UPDATE ...
    DB-->>S: Success
    S-->>C: OK
    C-->>U: Redirect to DocumentCategories?category=accounting

🔄 Usage Examples

  1. Navigate to Edit
    Browse to:
    https://<host>/AccountingImaging/EditCategory/123

  2. Fill Form

    • Name is read‐only.
    • Description can be modified.
    • Toggle IsAvailable / IsDeleted.
  3. Submit
    Click Update → server updates and redirects back to the filtered list.

  4. Cancel
    Click ← Back to List → returns to the listing of your current category type.


🏁 Conclusion

This EditCategory.cshtml view is a straightforward, validated form for updating document‐category metadata in the Accounting Imaging sub‐module. It adheres to ASP.NET Core MVC conventions, leverages built‑in HTML helpers for model binding and validation, and integrates existing UI libraries for a consistent look and feel across the IrbyImaging application.

Feel free to extend it with Syncfusion EJ2 widgets (e.g., rich‑text editors, dropdowns) or custom client‑side logic as your requirements evolve. 🎯


End of Documentation