TicketDetailsViewModel.cs Documentation 📝


Table of Contents

  1. Overview & Purpose 🔍
  2. Dependencies & Technologies ⚙️
  3. Key Functional Areas 🗂️
  4. Class Properties 💼
  5. UML Class Diagram 📊
  6. API Endpoints Overview 🌐
  7. Usage Examples 🚀
  8. Conclusion 🎯

1. Overview & Purpose 🔍

TicketDetailsViewModel is a ViewModel in the MVC/MVVM pattern used by the IrbyImaging application’s UI layer.
It aggregates all data required to display or edit a support ticket:

  • Core ticket metadata (ID, number, status, type)
  • Contact & response details (callback no., email)
  • Job-related info (description, shipping address)
  • Multiple request categories (hardware, software, enterprise, access, systems)
  • Update history
  • Audit fields (created on/by)
  • A filter to exclude completed items

This flattened, annotation‑rich structure simplifies data binding, validation, and rendering in Razor views or XAML UIs.


2. Dependencies & Technologies ⚙️

Namespace / Library Purpose
System Core types (DateTime, collections, byte[])
System.ComponentModel.DataAnnotations [Display(Name="…")] metadata for UI labels
IrbyImaging.DomainClasses Domain model (Update, request domain entities)
  • Target Framework: .NET 6+ (or compatible)
  • Architectural Pattern: MVC / MVVM

📌 This ViewModel has no direct database code—persistence is handled by separate services/repositories.


3. Key Functional Areas 🗂️

  1. Ticket Identification & Metadata
  2. Contact & Response Info
  3. Descriptions & Job Details
  4. Categorized Requests
  5. Update History
  6. Audit & Filter Controls

Each area corresponds to one or more properties in the class.


4. Class Properties 💼

Property Type Description
TicketId string Unique identifier (e.g., GUID).
TicketNumber int Sequential, human‑friendly number.
Customer string Name/company requesting service.
ImageContents byte[] Attached image (screenshot, photo, etc.).
CallbackNumber string 📞 Display name: “Callback Number”
Email string 📧 Display name: “Response Email”
Status string Current ticket status (Open, Closed, etc.).
Type string Category/type of ticket.
JobDetails string 📝 Display name: “Job Description”
ShippingAddress string 📦 Display name: “Shipping Address”
EmployeNumber string 👤 Display name: “Employee Number”
Description string 🏷️ Display name: “Ticket Description”
HardwareRequests ICollection<RequestOptionForDetailsViewModel> List of hardware items requested.
SoftwareRequests ICollection<RequestOptionForDetailsViewModel> List of software items requested.
EnterpriseRequests ICollection<RequestOptionForDetailsViewModel> Enterprise‐level service requests.
AccessRequests ICollection<RequestOptionForDetailsViewModel> Shared access/permissions requests.
SystemRequests ICollection<RequestOptionForDetailsViewModel> Irby Systems‐specific requests.
Updates ICollection<Update> Timeline of status/comments changes.
CreatedOn DateTime When the ticket was created.
CreatedBy string Who created the ticket.
ExcludeCompletedItems bool UI filter toggle for completed request items.

Note: [Display(Name="…")] attributes drive the labels in Razor forms, auto‑generated editors, and display templates.


5. UML Class Diagram 📊

@startuml
class TicketDetailsViewModel {
  + string TicketId
  + int TicketNumber
  + string Customer
  + byte[] ImageContents
  + string CallbackNumber
  + string Email
  + string Status
  + string Type
  + string JobDetails
  + string ShippingAddress
  + string EmployeNumber
  + string Description
  + ICollection<RequestOptionForDetailsViewModel> HardwareRequests
  + ICollection<RequestOptionForDetailsViewModel> SoftwareRequests
  + ICollection<RequestOptionForDetailsViewModel> EnterpriseRequests
  + ICollection<RequestOptionForDetailsViewModel> AccessRequests
  + ICollection<RequestOptionForDetailsViewModel> SystemRequests
  + ICollection<Update> Updates
  + DateTime CreatedOn
  + string CreatedBy
  + bool ExcludeCompletedItems
}
RequestOptionForDetailsViewModel <|-- TicketDetailsViewModel : uses
Update <|-- TicketDetailsViewModel : uses
@enduml

6. API Endpoints Overview 🌐

While this is a UI ViewModel, it is typically populated in controllers or API endpoints:

HTTP Verb URL Purpose Returns
GET /Tickets/Details/{id} Fetch & render ticket details page ViewResult with ViewModel
GET /api/tickets/{id} Provide JSON for SPA or AJAX clients TicketDetailsViewModel JSON

⚠️ Make sure your controller action maps domain entities into this ViewModel before returning JSON or a View.


7. Usage Examples 🚀

7.1 Instantiation & Mapping

// TicketController.cs
public IActionResult Details(Guid id)
{
    var ticket = _ticketService.GetById(id);
    if (ticket == null) return NotFound();

    // Map domain model → view model
    var vm = new TicketDetailsViewModel
    {
        TicketId             = ticket.Id.ToString(),
        TicketNumber         = ticket.Number,
        Customer             = ticket.CustomerName,
        ImageContents        = ticket.ImageData,
        CallbackNumber       = ticket.CallbackPhone,
        Email                = ticket.ResponseEmail,
        Status               = ticket.Status.ToString(),
        Type                 = ticket.Category,
        JobDetails           = ticket.JobDescription,
        ShippingAddress      = ticket.ShippingAddress,
        EmployeNumber        = ticket.EmployeeId,
        Description          = ticket.Description,
        HardwareRequests     = ticket.Requests
                                    .Where(r => r.Type == RequestType.Hardware)
                                    .Select(r => new RequestOptionForDetailsViewModel(r))
                                    .ToList(),
        // … map other categories similarly …
        Updates              = ticket.Updates,
        CreatedOn            = ticket.CreatedOn,
        CreatedBy            = ticket.CreatedByUser,
        ExcludeCompletedItems= false
    };

    return View(vm);
}

7.2 Razor View Rendering

@model TicketDetailsViewModel

<h1>Ticket @Model.TicketNumber: <span class="badge">@Model.Status</span></h1>
<p><strong>Customer:</strong> @Model.Customer</p>
<p><strong>Requested On:</strong> @Model.CreatedOn:g</p>

@if (Model.ImageContents != null) {
  <img src="data:image/png;base64,@(Convert.ToBase64String(Model.ImageContents))"
       alt="Ticket Image"
       style="max-width:100%; border:1px solid #ccc;" />
}

<h2>Requests 📋</h2>
@foreach (var list in new[] {
      (Label: "Hardware",    Items: Model.HardwareRequests),
      (Label: "Software",    Items: Model.SoftwareRequests),
      (Label: "Enterprise",  Items: Model.EnterpriseRequests),
      (Label: "Access",      Items: Model.AccessRequests),
      (Label: "System",      Items: Model.SystemRequests)
    })
{
    <h3>@list.Label</h3>
    <ul>
      @foreach (var req in list.Items) {
        <li>@req.OptionName (@req.Quantity)</li>
      }
    </ul>
}

<h2>Updates 📝</h2>
<ul>
  @foreach (var upd in Model.Updates) {
    <li>
      <strong>@upd.UpdatedOn:g</strong>: @upd.Comment
    </li>
  }
</ul>

8. Conclusion 🎯

The TicketDetailsViewModel is a comprehensive container that presents and structures all data needed by the UI when viewing or editing a support ticket. Its use of DataAnnotations, strongly‑typed properties, and collection navigations ensures:

  • Clear separation between domain logic and presentation logic
  • Easy unit testing of view‑specific behaviors
  • Rapid UI prototyping & binding in Razor or XAML

As your application evolves, you can extend this ViewModel with:

  • Validation attributes ([Required], [StringLength])
  • SelectLists for drop‑downs
  • Method helpers for common UI transformations

Use the examples above as a blueprint for mapping, rendering, and API exposure. Happy coding! 🚀