π SafetyEquipmentDetailViewModel.cs Documentation
π Table of Contents
- π Overview & Purpose
- π¦ Dependencies & Technologies
- π§© Inheritance & UML Diagram
- π Key Functional Areas
- π Detailed Property Reference
- π οΈ Usage Examples
- β Validation & Error Handling
- π Integration & MVC View Snippet
- π― Conclusion
π Overview & Purpose
The SafetyEquipmentDetailViewModel is part of the IrbyImaging.UI assembly. It extends a common DetailViewModel to encapsulate all the data required for displaying detailed safety equipment information in an ASP.NET MVC or Razor Pages application.
Intended Use
- Supply strongly-typed data to a detail/edit view for safety equipment.
- Leverage Data Annotations for display names and data formatting.
- Compute UI-centric flags (e.g., warranty status) to visually guide end users.
π¦ Dependencies & Technologies
| Technology / Library | Version/Notes |
|---|---|
| .NET (Core / Framework) | Any supporting DateTimeOffset |
| ASP.NET MVC / Razor Pages | For model binding & views |
| System.ComponentModel.DataAnnotations | For [Display], [DataType] |
The model resides in the namespace:
namespace IrbyImaging.Models
π§© Inheritance & UML Diagram
+---------------------------+
| DetailViewModel | β Base class with common properties (Id, Name, etc.)
+---------------------------+
β²
β
+----------------------------------------+
| SafetyEquipmentDetailViewModel |
+----------------------------------------+
| + string OperatingSystem |
| + string AssetNumber |
| + string UnitNumber |
| + string CpsNumber |
| + DateTimeOffset PurchaseDate |
| + DateTimeOffset EndOfWarranty |
| + bool IsApproachingEndOfWarranty |
| + bool IsOutOfWarranty |
| + string WarrantyColorClass |
+----------------------------------------+
- Note:
SafetyEquipmentDetailViewModelinherits fromDetailViewModel(common properties likeId,Name, etc., are defined there).
π Key Functional Areas
-
Identification Properties
- Asset tracking via JDE Asset & Unit numbers
- CPS (Component Part Serial) number
-
Warranty & Certification
PurchaseDate(the tested or purchase date)EndOfWarranty(certification expiration)- Color-coded UI class (
WarrantyColorClass)
-
Status Indicators
IsApproachingEndOfWarranty(true if within a warning window)IsOutOfWarranty(true if expired)
π Detailed Property Reference
| Property | Type | Attributes | Description |
|---|---|---|---|
| OperatingSystem π | string |
[Display("Operating System/Size")] |
OS or size specification of the safety equipment |
| AssetNumber π·οΈ | string |
[Display("JDE Asset Number")] |
Unique JDE asset identifier |
| UnitNumber π’ | string |
[Display("JDE Unit Number")] |
JDE unit number within the asset |
| CpsNumber π | string |
[Display("CPS Number")] |
Component Part Serial number |
| PurchaseDate π | DateTimeOffset |
[DataType(DataType.Date)][Display("Tested Date")] |
Date of purchase or last test |
| EndOfWarranty β | DateTimeOffset |
[DataType(DataType.Date)][Display("End Certification Date")] |
Certification expiry date |
| IsApproachingEndOfWarranty β οΈ | bool |
β | Flag indicating near-expiry (used for warning color coding) |
| IsOutOfWarranty β | bool |
β | Flag indicating warranty/certification has expired |
| WarrantyColorClass π¨ | string |
β | CSS class (e.g., "text-warning", "text-danger") for UI color |
π οΈ Usage Examples
Instantiating in C#
var model = new SafetyEquipmentDetailViewModel
{
Id = 101,
Name = "Portable Gas Detector",
OperatingSystem = "OS v3.1 / Compact",
AssetNumber = "ASSET-12345",
UnitNumber = "UNIT-67890",
CpsNumber = "CPS-54321",
PurchaseDate = DateTimeOffset.Parse("2021-04-15"),
EndOfWarranty = DateTimeOffset.Parse("2023-04-15"),
IsApproachingEndOfWarranty = DateTimeOffset.Now.AddDays(30) >= DateTimeOffset.Parse("2023-04-15"),
IsOutOfWarranty = DateTimeOffset.Now > DateTimeOffset.Parse("2023-04-15"),
WarrantyColorClass = (DateTimeOffset.Now > DateTimeOffset.Parse("2023-04-15"))
? "text-danger"
: "text-warning"
};
Checking Warranty Status
if (model.IsOutOfWarranty)
{
Console.WriteLine("β οΈ This equipment is out of warranty!");
}
else if (model.IsApproachingEndOfWarranty)
{
Console.WriteLine("β οΈ Warranty nearing expiration!");
}
else
{
Console.WriteLine("β
Equipment is within warranty.");
}
β Validation & Error Handling
- Required Attributes: No
[Required]attributes are active by default, but you can uncomment or add them as needed to enforce user input. - Date Formatting: The
[DataType(DataType.Date)]annotation ensures HTML5 date pickers and consistent formatting. - Display Names: Controlled via
[Display(Name = "...")]to render friendly labels in views.
π Integration & MVC View Snippet
Below is a Razor snippet illustrating how to render this ViewModel in an ASP.NET MVC view:
@model IrbyImaging.Models.SafetyEquipmentDetailViewModel
<h2>Safety Equipment Details</h2>
<dl class="row">
<dt class="col-sm-3">@Html.DisplayNameFor(m => m.OperatingSystem)</dt>
<dd class="col-sm-9">@Html.DisplayFor(m => m.OperatingSystem)</dd>
<dt class="col-sm-3">@Html.DisplayNameFor(m => m.AssetNumber)</dt>
<dd class="col-sm-9">@Html.DisplayFor(m => m.AssetNumber)</dd>
<dt class="col-sm-3">@Html.DisplayNameFor(m => m.UnitNumber)</dt>
<dd class="col-sm-9">@Html.DisplayFor(m => m.UnitNumber)</dd>
<dt class="col-sm-3">@Html.DisplayNameFor(m => m.CpsNumber)</dt>
<dd class="col-sm-9">@Html.DisplayFor(m => m.CpsNumber)</dd>
<dt class="col-sm-3">@Html.DisplayNameFor(m => m.PurchaseDate)</dt>
<dd class="col-sm-9">@Html.DisplayFor(m => m.PurchaseDate)</dd>
<dt class="col-sm-3">@Html.DisplayNameFor(m => m.EndOfWarranty)</dt>
<dd class="col-sm-9">
<span class="@Model.WarrantyColorClass">
@Html.DisplayFor(m => m.EndOfWarranty)
</span>
</dd>
</dl>
π― Conclusion
The SafetyEquipmentDetailViewModel is your goβto model for displaying, editing, and validating safety equipment records in the IrbyImaging UI. Its combination of typed properties, display annotations, and warranty-status flags makes it straightforward to integrate into ASP.NET MVC or Razor Pages viewsβcomplete with colorβcoded visual cues for critical warranty information. Happy coding! π