📚 DocumentCategoryView.cs Documentation


📋 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Key Functional Areas
  4. View Models
    4.1 DocumentCategoryView
    4.2 DocumentCategoryViewDetail
  5. Property Reference
  6. UML Class Diagram
  7. Sample Code Snippets & Usage Examples
  8. Conclusion

🧐 Overview & Purpose

DocumentCategoryView.cs defines two view models used in the IrbyImaging UI layer:

  • DocumentCategoryView
    Represents a top‑level document category, including metadata, flags, and associated document types/details.

  • DocumentCategoryViewDetail
    Represents a detailed view of a single document type under a category.

These classes are designed to decouple the DomainClasses (e.g., DocumentCategory, DocumentType) from the Razor/Blazor views or API controllers. By using view models, the UI can safely display, bind forms, and validate data without exposing internal domain logic.


🔌 Dependencies & Technologies

Category Details
Language C# (.NET 5/6/7)
Project Structure IrbyImaging.UI.Models
Annotations System.ComponentModel.DataAnnotations
Domain Types IrbyImaging.DomainClasses.ImagingType
Utility Classes IrbyImaging.Utility (if used for helpers)

🔑 Key Functional Areas

  • Metadata Properties
    • Id, Name, Description
  • Availability & Deletion Flags
    • IsAvailable, IsDeleted
  • Category‑Specific Flags
    • IsSafety, IsLegal, IsIT, IsHR, IsAccounting, IsBidding
  • Imaging Type
    • ImagingType (enum from domain)
  • Document Type Info
    • DocType, TypeList, DocTypeList
  • Audit Fields
    • AddedBy, AddedDate, ModifiedBy, ModifiedDate
  • Nested Details
    • DocList holds a list of DocumentCategoryViewDetail

📑 View Models

1. DocumentCategoryView

namespace IrbyImaging.UI.Models
{
    public class DocumentCategoryView
    {
        public Guid Id { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }

        // Status Flags
        public bool IsAvailable { get; set; }
        public bool IsDeleted   { get; set; }

        // Category Flags
        public bool IsSafety     { get; set; }
        public bool IsLegal      { get; set; }
        public bool IsIT         { get; set; }
        public bool IsAccounting { get; set; }
        public bool IsBidding    { get; set; }
        public bool IsHR         { get; set; }

        // Domain Enum
        public ImagingType ImagingType { get; set; }

        // Document Type Info
        public string DocType { get; set; }
        public List<string> TypeList { get; set; }

        // Audit Fields
        [Display(Name = "Added By")]   public string AddedBy   { get; set; }
        [Display(Name = "Added Date")] public DateTime AddedDate { get; set; }
        [Display(Name = "Modified By")]   public string ModifiedBy   { get; set; }
        [Display(Name = "Modified Date")] public DateTime ModifiedDate { get; set; }

        // Nested Document Details
        public List<DocumentCategoryViewDetail> DocList    { get; set; }
        public List<DocumentTypeViewDetail>     DocTypeList { get; set; }

        // Additional UI Value
        public string Value { get; set; }
    }
}

📝 Purpose

  • Encapsulate Category-level data for display & editing in UI.
  • Combine flags, types, and nested details into one cohesive model.
  • Provide DataAnnotations for form labels & validation.

2. DocumentCategoryViewDetail

namespace IrbyImaging.UI.Models
{
    public class DocumentCategoryViewDetail
    {
        public Guid Id { get; set; }
        public string Name        { get; set; }
        public string Description { get; set; }

        // Status Flags
        public bool IsAvailable { get; set; }
        public bool IsDeleted   { get; set; }

        // Category & Type Flags
        public bool isSafety     { get; set; }
        public bool isLegal      { get; set; }
        public bool isIT         { get; set; }
        public bool isAccounting { get; set; }
        public bool isBidding    { get; set; }

        public ImagingType ImagingType { get; set; }

        // Document Type Info
        public string DocType { get; set; }
        public List<string> TypeList { get; set; }

        // Audit Fields
        [Display(Name = "Added By")]   public string AddedBy     { get; set; }
        [Display(Name = "Added Date")] public DateTime AddedDate   { get; set; }
        [Display(Name = "Modified By")]   public string ModifiedBy   { get; set; }
        [Display(Name = "Modified Date")] public DateTime ModifiedDate { get; set; }
    }
}

📝 Purpose

  • Represent a single Document Type within a Category.
  • Mirror many of the same flags & audit fields as the parent model.
  • Useful for tables, detail views, or inline editing.

🗂 Property Reference

Below is a summary table of the most important properties and their purposes:

Property Type Purpose
Id Guid Unique identifier
Name string Display name
Description string Additional details
IsAvailable bool UI toggle to show/hide
IsDeleted bool Soft‑delete indicator
IsSafety bool Category: Safety
IsLegal bool Category: Legal
IsIT bool Category: IT
IsAccounting bool Category: Accounting
IsBidding bool Category: Bidding
IsHR bool Category: HR
ImagingType ImagingType (Enum) Domain enum: Legal, Safety, etc.
DocType string Single document – type name
TypeList List Multi-select for document types
DocList List Child items for detailed rendering
DocTypeList List Document‑type lookup list
AddedBy/Date string/DateTime Audit – who & when created
ModifiedBy/Date string/DateTime Audit – who & when last modified

📊 UML Class Diagram

classDiagram
    direction LR
    class DocumentCategoryView {
        +Guid Id
        +string Name
        +string Description
        +bool IsAvailable
        +bool IsDeleted
        +bool IsSafety
        +bool IsLegal
        +bool IsIT
        +bool IsAccounting
        +bool IsBidding
        +bool IsHR
        +ImagingType ImagingType
        +string DocType
        +List~string~ TypeList
        +string AddedBy
        +DateTime AddedDate
        +string ModifiedBy
        +DateTime ModifiedDate
        +List~DocumentCategoryViewDetail~ DocList
        +List~DocumentTypeViewDetail~ DocTypeList
        +string Value
    }
    class DocumentCategoryViewDetail {
        +Guid Id
        +string Name
        +string Description
        +bool IsAvailable
        +bool IsDeleted
        +bool isSafety
        +bool isLegal
        +bool isIT
        +bool isAccounting
        +bool isBidding
        +ImagingType ImagingType
        +string DocType
        +List~string~ TypeList
        +string AddedBy
        +DateTime AddedDate
        +string ModifiedBy
        +DateTime ModifiedDate
    }

    DocumentCategoryView "1" --> "*" DocumentCategoryViewDetail : contains

💻 Sample Code Snippets & Usage Examples

1. Manual Mapping from Domain Entity

// Assuming you have a domain class DocumentCategory
DocumentCategory domain = repository.GetCategoryById(id);

var viewModel = new DocumentCategoryView {
    Id          = domain.Id,
    Name        = domain.Name,
    Description = domain.Description,
    IsAvailable = !domain.IsArchived,
    IsDeleted   = domain.IsDeleted,
    // Map flags
    IsSafety     = domain.Categories.Contains("Safety"),
    IsLegal      = domain.Categories.Contains("Legal"),
    // … other flags …
    ImagingType = domain.ImagingType,
    // Audit fields
    AddedBy     = domain.CreatedBy,
    AddedDate   = domain.CreatedDate,
    ModifiedBy  = domain.UpdatedBy,
    ModifiedDate= domain.UpdatedDate,
    // Child items
    DocList = domain.DocumentTypes
                   .Select(dt => new DocumentCategoryViewDetail {
                       Id          = dt.Id,
                       Name        = dt.Name,
                       Description = dt.Description,
                       IsAvailable = dt.IsActive,
                       // …
                   }).ToList()
};

2. Razor Page Example

@model DocumentCategoryView

<h2>@Model.Name</h2>
<p>@Model.Description</p>

<table class="table">
    <thead>
        <tr>
            <th>Type</th><th>Available?</th><th>Created</th><th>Modified</th>
        </tr>
    </thead>
    <tbody>
    @foreach (var detail in Model.DocList) {
        <tr>
            <td>@detail.Name (@detail.DocType)</td>
            <td>@(detail.IsAvailable ? "✔️" : "❌")</td>
            <td>@detail.AddedDate.ToShortDateString()</td>
            <td>@detail.ModifiedDate.ToShortDateString()</td>
        </tr>
    }
    </tbody>
</table>

3. Form Binding & Validation

<EditForm Model=@Model OnValidSubmit="HandleSubmit">
    <DataAnnotationsValidator />
    <ValidationSummary />

    <InputText @bind-Value="Model.Name" class="form-control" />
    <InputTextArea @bind-Value="Model.Description" class="form-control" />
    <InputCheckbox @bind-Value="Model.IsSafety" /> Safety
    <InputCheckbox @bind-Value="Model.IsLegal" /> Legal
    <!-- … other inputs … -->

    <button type="submit" class="btn btn-primary">Save</button>
</EditForm>

🏁 Conclusion

The DocumentCategoryView and DocumentCategoryViewDetail classes are UI‑friendly wrappers for domain entities, encapsulating:

  • 🏷️ Metadata (ID, Name, Description)
  • ✅ Flags (Availability, Category types)
  • 🧩 Child collections (Document type details)
  • 🕒 Audit information

They simplify rendering, editing, and validation in the UI layer—ensuring clear separation of concerns and maintainable code. Use these view models in your Controllers, Razor/Blazor pages, or API endpoints to present and process document category data seamlessly! 🚀