๐ OutstandingViewModel.cs Documentation
Location
IrbyImaging/Models/Shared/OutstandingViewModel.cs
๐ Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- UML Class Diagram
- Properties & Annotations
- DataAnnotations & UI Integration
- Key Functional Areas
- Sample Code Snippets & Usage Examples
- MVC Controller Integration
- Conclusion
๐ Overview & Purpose
The OutstandingViewModel serves as a ViewModel in the IrbyImaging UI layer. It bundles all information needed to display an โoutstanding assetโ in lists, tables, and detail pages. Typical use cases:
- ๐ฅ๏ธ Render an equipment or asset table in a Razor/MVC view
- ๐ Generate dynamic links to the appropriate controller
- ๐ฏ Provide a stronglyโtyped model for data binding and validation
๐ ๏ธ Dependencies & Technologies
| Technology / Namespace | Purpose |
|---|---|
System |
Base .NET types (e.g., Guid, DateTimeOffset) |
System.ComponentModel.DataAnnotations |
UI metadata & validation attributes ([Display], [DataType]) |
IrbyImaging.Utility |
Holds shared enums: AssetStatus, AssetCategory |
| ASP.NET MVC / Razor Views | Consumes this ViewModel for rendering UI |
๐ UML Class Diagram
+-----------------------------------+
| OutstandingViewModel |
+-----------------------------------+
| - Id: Guid |
| - MakeAndModel: string |
| - SerialNumber: string |
| - Status: AssetStatus |
| - PurchaseDate: DateTimeOffset |
| - OwnerId: Guid |
| - OwnerFullName: string |
| - Category: AssetCategory |
+-----------------------------------+
| + Controller: string { get } |
+-----------------------------------+
๐ Properties & Annotations
| Property | Type | Annotation | Description |
|---|---|---|---|
| Id | Guid |
โ | Unique identifier of the asset. |
| MakeAndModel | string |
[Display(Name="Make/Model")] |
Manufacturer and model info. |
| SerialNumber | string |
[Display(Name="Serial Number")] |
Assetโs unique serial number. |
| Status | AssetStatus |
โ | Current asset state (e.g., New, InUse, Retired). |
| PurchaseDate | DateTimeOffset |
[DataType(Date)], [Display(...)] |
Date when asset was purchased or tested. |
| OwnerId | Guid |
โ | Identifier of the employee/user assigned to the asset. |
| OwnerFullName | string |
[Display(Name="Assigned To")] |
Full name of the assigned owner. |
| Category | AssetCategory |
โ | Category classification (e.g., Camera, Light). |
| Controller | string (readonly) |
โ | Derived: "{Category}s", used for generating MVC routes. |
๐ท๏ธ DataAnnotations & UI Integration
- [Display(Name = "...")]
- Controls label text in Razor helpers (
@Html.LabelFor, scaffolding).
- Controls label text in Razor helpers (
- [DataType(DataType.Date)]
- Renders a date picker or formatted date string in views.
Example in Razor:
@model OutstandingViewModel
<table class="table">
<thead>
<tr>
<th>@Html.DisplayNameFor(m => m.MakeAndModel)</th>
<th>@Html.DisplayNameFor(m => m.SerialNumber)</th>
<th>@Html.DisplayNameFor(m => m.PurchaseDate)</th>
<th>@Html.DisplayNameFor(m => m.OwnerFullName)</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.OutstandingItems) {
<tr>
<td>@item.MakeAndModel</td>
<td>@item.SerialNumber</td>
<td>@item.PurchaseDate.ToShortDateString()</td>
<td>@item.OwnerFullName</td>
<td>
@Html.ActionLink("Details", item.Controller, new { id = item.Id }, htmlAttributes: new { @class="btn btn-info" })
</td>
</tr>
}
</tbody>
</table>
๐ Key Functional Areas
- Identification
Idties the asset to backend data stores (DB primary key).
- Categorization
Category&Controllerenable dynamic routing to specialized controllers (e.g.,/Cameras/Details/{id}).
- Ownership & Status
OwnerId,OwnerFullName, andStatustrack assignment and lifecycle stage.
- Presentation
- Display-friendly names & formats via data annotations.
๐ก Sample Code Snippets & Usage Examples
1. Instantiating in Controller
public ActionResult Outstanding()
{
var assets = _assetService.GetOutstandingAssets();
var viewModels = assets.Select(a => new OutstandingViewModel {
Id = a.Id,
MakeAndModel = $"{a.Make} {a.Model}",
SerialNumber = a.SerialNumber,
Status = a.Status,
PurchaseDate = a.PurchasedOn,
OwnerId = a.AssignedTo.Id,
OwnerFullName = $"{a.AssignedTo.FirstName} {a.AssignedTo.LastName}",
Category = a.Category
});
return View(viewModels);
}
2. Generating a Link in Razor
@foreach(var vm in Model)
{
<div>
@Html.ActionLink("View Details", vm.Controller,
new { id = vm.Id }, new { @class = "btn btn-primary" })
</div>
}
๐ MVC Controller Integration
- Dynamic Controller Name
TheControllerproperty returns a string like"Cameras","Lights", etc.:public string Controller => $"{Category}s"; - Routing Example
IfCategory = AssetCategory.Camera,Controller == "Cameras".
The link@Html.ActionLink("Go", "Details", "Cameras", new { id = vm.Id }, null)will direct to/Cameras/Details/{id}.
๐ Conclusion
The OutstandingViewModel is a lightweight yet powerful ViewModel designed to:
- Standardize how outstanding assets are displayed in the UI
- Leverage DataAnnotations for cleaner, more maintainable views
- Dynamically route to the correct MVC controllers via its
Controllerproperty
By following the patterns illustrated above, developers can quickly scaffold new assetโrelated pages, ensure consistency across the application, and provide endโusers with a clear, userโfriendly interface. ๐
Happy Coding! โจ