📄 DetailViewModel Documentation
File Path: IrbyImaging/Models/Shared/DetailViewModel.cs
Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Data Annotations & Display Attributes
- ViewModel Properties Reference
- Sample Code & Usage Examples
- UML Diagram
- Error Handling & Return Types
- API Endpoints Overview
- Helper Methods / Utilities
- Third-party Integrations
- Conclusion
1. Overview & Purpose
DetailViewModel is an abstract base class used throughout the IrbyImaging application to represent the common properties of any detailed asset or entity displayed in the UI. It serves as a standardized data container for:
- Displaying asset identification (ID, make & model, serial number).
- Presenting ownership and status information.
- Facilitating data binding in MVC or Razor Pages.
🎯 Intended Use:
Inherit from DetailViewModel to define concrete view models for pages like Asset Details, User Profiles, or Equipment Records. This ensures consistency in how core fields are presented and validated.
2. Dependencies & Technologies
| Dependency | Purpose |
|---|---|
System |
Base .NET types (e.g., Guid, DateTimeOffset). |
System.ComponentModel.DataAnnotations |
Data annotations for display and validation. |
IrbyImaging.Utility |
Contains the AssetStatus enum and related helpers. |
Technologies:
- .NET Standard / .NET Core
- ASP.NET MVC / Razor Pages
- Data Annotations for model metadata
3. Key Functional Areas
🔑 Identifier Handling
- Id (Guid): Universally unique identifier for the asset/entity.
🏷️ Asset Details
- MakeAndModel (string): Manufacturer and model combined (e.g., “Canon EOS R5”).
- SerialNumber (string): Unique hardware serial number.
👤 Ownership Info
- OwnerId (Guid): Reference to the user or department owning the asset.
- OwnerFullName (string): Display name of the assigned owner.
🔖 Status Representation
- Status (AssetStatus): Enum representing current asset lifecycle status (e.g., InService, Retired).
- StatusColor (string): UI-friendly color code or CSS class reflecting the
Status.
4. Data Annotations & Display Attributes
DetailViewModel leverages data annotations to:
- Control display names in UI forms and tables.
- Enforce data types (e.g., date picking for purchase date).
| Property | Annotation | Effect in UI |
|---|---|---|
| MakeAndModel | [Display(Name = "Make/Model")] |
Label shows “Make/Model”. |
| SerialNumber | [Display(Name = "Serial Number")] |
Label shows “Serial Number”. |
| PurchaseDate | [DataType(DataType.Date)][Display(Name = "Purchase Date")] |
Renders a date-picker. |
| OwnerFullName | [Display(Name = "Assigned To")] |
Label shows “Assigned To”. |
5. ViewModel Properties Reference
| Property Name | Type | Description |
|---|---|---|
Id |
Guid |
Unique ID of the entity. |
MakeAndModel |
string |
Combined make and model string. |
SerialNumber |
string |
Hardware serial number. |
Status |
AssetStatus |
Enum representing asset state. |
PurchaseDate |
DateTimeOffset |
Date when the asset was purchased. |
OwnerId |
Guid |
Unique ID of the owner (user or department). |
OwnerFullName |
string |
Full name of the assigned owner. |
Notes |
string |
Additional free-text notes. |
StatusColor |
string |
CSS color or class indicating status visually. |
6. Sample Code & Usage Examples
6.1 Inheriting from DetailViewModel
using IrbyImaging.Models;
public class CameraDetailViewModel : DetailViewModel
{
[Display(Name = "Resolution")]
public string Resolution { get; set; }
[Display(Name = "Lens Type")]
public string LensType { get; set; }
}
Usage in Controller:
public IActionResult Details(Guid id)
{
// Fetch domain model, map to view model
var camera = _cameraService.GetById(id);
var vm = new CameraDetailViewModel
{
Id = camera.Id,
MakeAndModel = camera.Make + " " + camera.Model,
SerialNumber = camera.Serial,
Status = camera.Status,
StatusColor = _statusColorService.GetColor(camera.Status),
PurchaseDate = camera.PurchasedOn,
OwnerId = camera.AssignedUser.Id,
OwnerFullName = camera.AssignedUser.FullName,
Notes = camera.Notes,
Resolution = camera.Resolution,
LensType = camera.LensType
};
return View(vm);
}
6.2 Razor View Binding
@model CameraDetailViewModel
<h2>Camera Details</h2>
<dl class="row">
<dt class="col-sm-3">@Html.DisplayNameFor(m => m.MakeAndModel)</dt>
<dd class="col-sm-9">@Model.MakeAndModel</dd>
<dt class="col-sm-3">@Html.DisplayNameFor(m => m.PurchaseDate)</dt>
<dd class="col-sm-9">@Model.PurchaseDate.ToString("d")</dd>
<dt class="col-sm-3">Status</dt>
<dd class="col-sm-9">
<span class="badge" style="background-color:@Model.StatusColor">
@Model.Status
</span>
</dd>
<!-- More fields... -->
</dl>
7. UML Diagram
@startuml
skinparam classAttributeIconSize 0
abstract class DetailViewModel {
+Guid Id
+string MakeAndModel
+string SerialNumber
+AssetStatus Status
+DateTimeOffset PurchaseDate
+Guid OwnerId
+string OwnerFullName
+string Notes
+string StatusColor
}
class CameraDetailViewModel {
+string Resolution
+string LensType
}
DetailViewModel <|-- CameraDetailViewModel
@enduml
8. Error Handling & Return Types
- Error Handling: N/A – This is a simple data carrier.
- Return Types: All properties are basic CLR types; no
null-forgiving policy is implemented. Consumers should handle potentialnullstrings.
9. API Endpoints Overview
None defined here. This ViewModel is used by MVC controllers or Razor Pages. API endpoints would typically accept or return subclasses of
DetailViewModel.
10. Helper Methods / Utilities
None directly in this file.
TheStatusColoris typically resolved by a helper service inIrbyImaging.Utility.
11. Third-party Integrations
- None embedded.
- Relies on DataAnnotations from .NET for metadata and display.
12. Conclusion
🎉 DetailViewModel provides a solid, consistent foundation for any “detail” screen across the IrbyImaging application. By centralizing core fields—such as asset ID, status, ownership, and purchase data—it promotes:
- ✅ Reusability across multiple view models
- ✅ Consistency in display and validation
- ✅ Ease of maintenance when adding common fields
Feel free to extend this abstract class to build rich, domain-specific view models for Cameras, Printers, or any other asset type in your system.
Generated by the IrbyImaging Documentation Generator 🛠️