📋 SafetyEquipmentListViewModel Documentation
📖 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Class Definition
- UML Class Diagram
- Usage Examples
- Integration in Controllers & Views
- Error Handling & Validation
- Related ViewModels & Data Models
- Conclusion
1. Overview & Purpose
The SafetyEquipmentListViewModel is part of the IrbyImaging.UI assembly and lives under the namespace IrbyImaging.Models. It is a ViewModel tailored for displaying paginated lists of safety‐equipment items in the UI layer of an MVC or Razor Pages application.
💡 Why use it?
- Encapsulates paging, sorting, and filtering functionality (via its base class
ListViewModel). - Adds domain‐specific summary data (warranty counts).
- Carries a collection of detailed equipment items (
SafetyEquipmentDetailViewModel) to the view.
2. Dependencies & Technologies
| Category | Details |
|---|---|
| Framework | .NET 5 / .NET 6 or later |
| Language | C# 8.0+ |
| Assemblies | IrbyImaging.UI |
| Namespaces | System.Collections.Generic, IrbyImaging.Models |
| Design Pattern | MVC / MVVM (ViewModel in presentation layer) |
3. Key Functional Areas
-
Paging & Sorting
Inherits fromListViewModelwhich typically provides:PageNumberPageSizeTotalCountSortField, etc.
-
Warranty Summaries
NumberOutOfWarrantyNumberApproachingEndOfWarranty
-
Detailed Equipment Collection
SafetyEquipments: A list ofSafetyEquipmentDetailViewModelitems.
4. Class Definition
// File: IrbyImaging/Models/SafetyEquipment/SafetyEquipmentListViewModel.cs
using System.Collections.Generic;
namespace IrbyImaging.Models
{
/// <summary>
/// ViewModel for listing safety equipment with warranty summaries.
/// Inherits common list functionality from ListViewModel.
/// </summary>
public class SafetyEquipmentListViewModel : ListViewModel
{
/// <summary>
/// Gets or sets the count of equipment already out of warranty.
/// </summary>
public string NumberOutOfWarranty { get; set; }
/// <summary>
/// Gets or sets the count of equipment approaching end of warranty.
/// </summary>
public string NumberApproachingEndOfWarranty { get; set; }
/// <summary>
/// Gets or sets the detailed safety equipment items.
/// </summary>
public ICollection<SafetyEquipmentDetailViewModel> SafetyEquipments { get; set; }
}
}
Inheritance Hierarchy
| Base Class | Derived Class | Purpose |
|---|---|---|
ListViewModel |
SafetyEquipmentListViewModel | Adds domain‑specific props to generic list VM |
Properties
| Property | Type | Description |
|---|---|---|
| NumberOutOfWarranty | string |
Count of items out of warranty. |
| NumberApproachingEndOfWarranty | string |
Count of items approaching end of warranty. |
| SafetyEquipments | ICollection<SafetyEquipmentDetailViewModel> |
Collection of detailed safety equipment view models. |
5. UML Class Diagram
+---------------------------------------------+
| ListViewModel |
|---------------------------------------------|
| - PageNumber : int |
| - PageSize : int |
| - TotalCount : int |
| - SortField : string |
| + ... (paging & sorting methods) |
+-------------------^-------------------------+
|
+---------------------------------------------+
| SafetyEquipmentListViewModel |
| : ListViewModel |
|---------------------------------------------|
| + NumberOutOfWarranty : string |
| + NumberApproachingEndOfWarranty : string |
| + SafetyEquipments : ICollection<SafetyEquipmentDetailViewModel> |
+---------------------------------------------+
6. Usage Examples
Instantiating & Populating
var vm = new SafetyEquipmentListViewModel
{
// From ListViewModel:
PageNumber = 1,
PageSize = 10,
TotalCount = 42,
SortField = "ExpiryDate",
// Warranty summaries:
NumberOutOfWarranty = "5",
NumberApproachingEndOfWarranty = "3",
// Detailed items:
SafetyEquipments = new List<SafetyEquipmentDetailViewModel>
{
new SafetyEquipmentDetailViewModel
{
Id = 1001,
Name = "Lead Apron",
ExpiryDate = DateTime.Now.AddMonths(2),
IsUnderWarranty = true
},
// ... more items ...
}
};
Rendering in a Razor View
@model IrbyImaging.Models.SafetyEquipmentListViewModel
<h1>🦺 Safety Equipment Dashboard</h1>
<div>
<strong>Out of Warranty:</strong> @Model.NumberOutOfWarranty
|
<strong>Approaching Warranty End:</strong> @Model.NumberApproachingEndOfWarranty
</div>
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Expiry Date</th>
<th>Under Warranty?</th>
</tr>
</thead>
<tbody>
@foreach(var item in Model.SafetyEquipments)
{
<tr>
<td>@item.Id</td>
<td>@item.Name</td>
<td>@item.ExpiryDate:MM/dd/yyyy</td>
<td>@(item.IsUnderWarranty ? "✅ Yes" : "❌ No")</td>
</tr>
}
</tbody>
</table>
7. Integration in Controllers & Views
-
Controller Action
public IActionResult Index() { // 1) Fetch or build the ViewModel (via a service or repository) var viewModel = _safetyEquipmentService.GetSafetyEquipmentList(); // 2) Pass to the view return View(viewModel); } -
Razor View
Use the strongly‐typed@model SafetyEquipmentListViewModelto render tables, summaries, and paging controls (if implemented inListViewModel).
8. Error Handling & Validation
- Validation for individual fields can be applied on
SafetyEquipmentDetailViewModelusing DataAnnotations (e.g.,[Required],[Range]). - Null‐checks: Ensure
SafetyEquipmentsis initialized (e.g., tonew List<...>()) to avoid null‑reference exceptions in the view. - Service Layer: Handle data retrieval errors/exceptions and populate an error message property on a Result wrapper or TempData for UI display.
9. Related ViewModels & Data Models
| Model / Class | Description |
|---|---|
ListViewModel |
Base class providing paging/sorting/filtering support. |
SafetyEquipmentDetailViewModel |
Contains detailed fields of a single equipment item. |
SafetyEquipment (Entity) |
Domain object mapped to database tables. |
10. Conclusion
The SafetyEquipmentListViewModel is a simple yet powerful ViewModel that:
- Reuses common list‑related properties via inheritance
- Extends functionality to cover warranty tracking
- Contains a typed collection of detailed safety‐equipment items
This clean separation of concerns makes UIs more maintainable and testable. ✅
🎉 Happy Developing! 🎉