📄 TicketSearch.cs Documentation
Table of Contents
- Overview & Purpose
- Namespaces & Dependencies
- Class Definition & Structure
- Properties
- Data Annotations
- UML Class Diagram
- Usage in ASP.NET MVC / Razor Views
- Sample Code Blocks & Scenarios
- Conclusion
1. Overview & Purpose
🎯 TicketSearch is a simple ViewModel (or DataModel) used within the IrbyImaging.UI project to represent ticket information in the UI layer. It encapsulates the key fields you need when searching, listing, or displaying ticket summaries on a web page or dashboard.
- Intended Use:
- Populate a search results grid
- Pass search criteria between Controller and View
- Serialize/deserialize ticket summaries in AJAX or API responses
2. Namespaces & Dependencies
using System;
using System.ComponentModel.DataAnnotations;
| Namespace | Purpose |
|---|---|
| System | Base .NET types (Guid, DateTime, String) |
| System.ComponentModel.DataAnnotations | Supports data annotation attributes (e.g., date) |
3. Class Definition & Structure
namespace IrbyImaging.UI.Models
{
/// <summary>
/// Represents a ticket row in a search or listing UI.
/// </summary>
public class TicketSearch
{
public Guid Id { get; set; }
public int TicketNumber { get; set; }
public string CustomerName { get; set; }
[DataType(DataType.Date)]
public DateTime CreatedOn { get; set; }
public string Description { get; set; }
public string Status { get; set; }
public string Type { get; set; }
public string LastUpdate { get; set; }
[DataType(DataType.Date)]
public DateTime UpdatedOn { get; set; }
}
}
- Assembly: IrbyImaging.UI
- Author: kvamshi
- Created/Modified: 05-17-2022
4. Properties
| Property | Type | Data Annotation | Description |
|---|---|---|---|
| Id | Guid | – | Unique identifier for the ticket. |
| TicketNumber | int | – | Human‐readable ticket number. |
| CustomerName | string | – | Name of the customer who opened the ticket. |
| CreatedOn | DateTime | [DataType(DataType.Date)] |
Date when the ticket was created. |
| Description | string | – | Short description or summary of the ticket. |
| Status | string | – | Current status (e.g., “Open”, “In Progress”, “Closed”). |
| Type | string | – | Ticket classification or category (e.g., “Bug”, “FAQ”). |
| LastUpdate | string | – | Textual info on the last update (e.g., by whom). |
| UpdatedOn | DateTime | [DataType(DataType.Date)] |
Last modification date of the ticket. |
5. Data Annotations
[DataType(DataType.Date)]- Ensures that when rendered in a Razor view, only the date portion is displayed (no time).
- Triggers specific client‐side date pickers in ASP.NET MVC templates.
6. UML Class Diagram
classDiagram
class TicketSearch {
+Guid Id
+int TicketNumber
+string CustomerName
+DateTime CreatedOn
+string Description
+string Status
+string Type
+string LastUpdate
+DateTime UpdatedOn
}
7. Usage in ASP.NET MVC / Razor Views
-
Controller: Populate a list of
TicketSearchfrom your service/repository.public IActionResult Search(string query) { var tickets = _ticketService.SearchTickets(query) .Select(t => new TicketSearch { Id = t.Id, TicketNumber = t.Number, CustomerName = t.Customer.Name, CreatedOn = t.Created, Description = t.Summary, Status = t.Status, Type = t.Category, LastUpdate = t.LastModifiedBy, UpdatedOn = t.LastModifiedDate }) .ToList(); return View(tickets); } -
View: Render in a table.
@model IEnumerable<IrbyImaging.UI.Models.TicketSearch> <table class="table"> <thead> <tr> <th>Ticket #</th><th>Customer</th><th>Created</th> <th>Status</th><th>Type</th><th>Last Updated</th> </tr> </thead> <tbody> @foreach(var t in Model) { <tr> <td>@t.TicketNumber</td> <td>@t.CustomerName</td> <td>@t.CreatedOn.ToShortDateString()</td> <td>@t.Status</td> <td>@t.Type</td> <td>@t.UpdatedOn.ToShortDateString()</td> </tr> } </tbody> </table>
8. Sample Code Blocks & Scenarios
a) Instantiation
var searchResult = new TicketSearch {
Id = Guid.NewGuid(),
TicketNumber = 12345,
CustomerName = "Acme Corp",
CreatedOn = DateTime.UtcNow.Date,
Description = "Login failure on portal",
Status = "Open",
Type = "Bug",
LastUpdate = "Assigned to John Doe",
UpdatedOn = DateTime.UtcNow.Date
};
b) JSON Serialization
// Using System.Text.Json
var json = JsonSerializer.Serialize(searchResult, new JsonSerializerOptions {
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
});
Console.WriteLine(json);
c) LINQ Filtering
List<TicketSearch> tickets = GetTickets();
var openBugs = tickets
.Where(t => t.Status == "Open" && t.Type == "Bug")
.OrderByDescending(t => t.CreatedOn)
.ToList();
9. Conclusion
✅ TicketSearch.cs is a lightweight, annotation‐driven model designed to surface essential ticket information in UI scenarios.
- Why use it?
- Clean separation of concerns (ViewModel vs. DataModel)
- Simplifies data binding in Razor views
- Leverages standard .NET data annotations for formatting
Use this class as the primary data carrier for any ticket search, list, or summary endpoints in your MVC or API layers. 🚀