π₯οΈ ComputerDetailViewModel Documentation
π Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Class Diagram (UML)
- Properties & Data Annotations
- Usage Examples
- Sample Code Blocks
- Conclusion
π― Overview & Purpose
ComputerDetailViewModel is a ViewModel in the IrbyImaging.Models namespace designed to carry detailed information about a computer asset from the back-end to the UI layer (e.g., Razor Views in an ASP.NET MVC or Blazor application).
- Primary Use Case: Display and edit computer-specific details (warranty, CPS number, JDE asset identifiers, etc.) on a detail page.
- Inheritance: Extends
DetailViewModel(assumed to contain common fields such asId,Name,CreatedOn, etc.).
π§ Dependencies & Technologies
| Technology / Package | Purpose |
|---|---|
| .NET / C# | Core language & runtime |
| System.ComponentModel.DataAnnotations | Data validation and display metadata |
| System | Base types (string, DateTimeOffset, etc.) |
π Key Functional Areas
-
Asset Identification
- JDE Asset Number (
AssetNumber) - JDE Unit Number (
UnitNumber) - CPS Number (
CpsNumber) β marked as required.
- JDE Asset Number (
-
Warranty Management
- End Of Warranty Date (
EndOfWarranty) - Flags
IsOutOfWarrantyIsApproachingEndOfWarranty
- UI Styling Helper
WarrantyColorClass(CSS class name to colorβcode warranty status).
- End Of Warranty Date (
-
System Information
- Operating System (
OperatingSystem)
- Operating System (
-
Workflow & Review
- Needs IT Review? (
NeedsReview) - Assigned Employee (
EmployeeId)
- Needs IT Review? (
π Class Diagram (UML)
classDiagram
class DetailViewModel {
<<abstract>>
+string Id
+DateTimeOffset CreatedOn
+string CreatedBy
+DateTimeOffset? ModifiedOn
+string ModifiedBy
}
class ComputerDetailViewModel {
<<DetailViewModel>>
+string OperatingSystem
+string AssetNumber
+string UnitNumber
+string CpsNumber
+DateTimeOffset EndOfWarranty
+bool IsOutOfWarranty
+bool IsApproachingEndOfWarranty
+string WarrantyColorClass
+string EmployeeId
+bool NeedsReview
}
DetailViewModel <|-- ComputerDetailViewModel
π Properties & Data Annotations
| Property | Type | Annotations | Description |
|---|---|---|---|
| OperatingSystem | string |
[Display(Name="Operating System")] |
OS installed on the computer. |
| AssetNumber | string |
[Display(Name="JDE Asset Number")] |
Internal asset identifier in the JDE system. |
| UnitNumber | string |
[Display(Name="JDE Unit Number")] |
JDE unit number. |
| CpsNumber | string |
[Required], [Display(Name="CPS Number")] |
Unique CPS (Computer Purchase System) number. Mandatory field. |
| EndOfWarranty | DateTimeOffset |
[DataType(DataType.Date)],[Display(Name="End Of Warranty")] |
Expiry date of the manufacturerβs warranty. |
| IsOutOfWarranty | bool |
β | Flag indicating if warranty has expired. |
| IsApproachingEndOfWarranty | bool |
β | Flag indicating if warranty is nearing expiry (e.g., within 30 days). |
| WarrantyColorClass | string |
β | CSS class to visually represent warranty status in the UI ("text-danger", "text-warning", "text-success"). |
| EmployeeId | string |
β | Identifier of the employee responsible for or assigned to the computer. |
| NeedsReview | bool |
[Display(Name="Needs IT Review?")] |
Indicates whether the computer record requires an IT review. |
π οΈ Sample Code Blocks
1. Initializing a new ComputerDetailViewModel
var computerVm = new ComputerDetailViewModel
{
Id = "12345",
OperatingSystem = "Windows 11 Pro",
AssetNumber = "JDE-100234",
UnitNumber = "UN-5678",
CpsNumber = "CPS-20220331",
EndOfWarranty = DateTimeOffset.UtcNow.AddMonths(6),
IsApproachingEndOfWarranty = false,
IsOutOfWarranty = false,
WarrantyColorClass = "text-success",
EmployeeId = "EMP00123",
NeedsReview = false,
CreatedOn = DateTimeOffset.UtcNow,
CreatedBy = "admin"
};
2. Rendering in a Razor View
@model IrbyImaging.Models.ComputerDetailViewModel
<div class="computer-details">
<h2>Computer Details</h2>
<dl class="row">
<dt class="col-sm-3">Operating System:</dt>
<dd class="col-sm-9">@Model.OperatingSystem</dd>
<dt class="col-sm-3">JDE Asset Number:</dt>
<dd class="col-sm-9">@Model.AssetNumber</dd>
<dt class="col-sm-3">CPS Number:</dt>
<dd class="col-sm-9">
<span class="@Model.WarrantyColorClass">@Model.CpsNumber</span>
</dd>
<dt class="col-sm-3">End Of Warranty:</dt>
<dd class="col-sm-9">
@Model.EndOfWarranty.ToString("yyyy-MM-dd")
@if (Model.IsApproachingEndOfWarranty) {
<span class="badge bg-warning">Approaching Expiry</span>
}
</dd>
<dt class="col-sm-3">Needs IT Review?</dt>
<dd class="col-sm-9">
@if (Model.NeedsReview) {
<span class="badge bg-danger">Yes</span>
} else {
<span class="badge bg-success">No</span>
}
</dd>
</dl>
</div>
π‘ Usage Examples
-
Form Binding & Validation
- Bind
CpsNumberas a required field in an Edit form. - Display validation messages automatically via DataAnnotations.
- Bind
-
Warranty Status Logic
- In your controller/service layer, calculate and set:
viewModel.IsOutOfWarranty = DateTimeOffset.UtcNow > viewModel.EndOfWarranty; viewModel.IsApproachingEndOfWarranty = !viewModel.IsOutOfWarranty && (viewModel.EndOfWarranty - DateTimeOffset.UtcNow).TotalDays <= 30; viewModel.WarrantyColorClass = viewModel.IsOutOfWarranty ? "text-danger" : viewModel.IsApproachingEndOfWarranty ? "text-warning" : "text-success"; - This logic powers the colored badges and CSS classes for urgency.
- In your controller/service layer, calculate and set:
π Conclusion
The ComputerDetailViewModel bridges back-end data and front-end display for computer asset details within the IrbyImaging solution. By leveraging DataAnnotations, CSS helpers, and clear property definitions, it ensures:
- Consistent metadata for display labels and validation.
- Centralized logic for warranty status and UI styling.
- A clear contract for controllers and views to interact seamlessly.
With this ViewModel in your MVC or Blazor application, you can quickly scaffold detail and edit pages, ensuring both developer productivity and a polished user experience.
Happy coding! π