MobileDeviceListViewModel Documentation π±
Table of Contents
- Overview & Purpose
- Class Diagram (UML)
- Dependencies & Technologies
- Inheritance & Hierarchy
- Properties Description
- Sample Code Blocks & Usage Examples
- Sample JSON Payload
- Conclusion
1. Overview & Purpose
MobileDeviceListViewModel is a ViewModel class used in the IrbyImaging.UI layer to represent a paginated list of mobile devices, along with metadata about their warranty status. Typically, this model is populated in a controller or service and passed to a Razor view or returned by an API endpoint to render on the UI.
π Key points
- Extends a generic
ListViewModelto inherit pagination properties (e.g., CurrentPage, PageSize, TotalCount). - Adds domainβspecific metrics: how many devices are out of warranty and how many are approaching endβofβwarranty.
- Contains a collection of
MobileDeviceDetailViewModelitems for display.
2. Class Diagram (UML) π
βββββββββββββββββββββββββββββββ
β ListViewModel β β Base class (provides paging)
βββββββββββββββββββββββββββββββ
β + CurrentPage : int β
β + PageSize : int β
β + TotalCount : int β
βββββββββββββββ²ββββββββββββββββ
β extends
βββββββββββββββ΄ββββββββββββββββββββββββ
β MobileDeviceListViewModel β
βββββββββββββββββββββββββββββββββββββββ
β + NumberOutOfWarranty βββββ
β + NumberApproachingEndOfWarranty β β
β + MobileDevices : ICollection<Detail>βββββ
βββββββββββββββββββββββββββββββββββββββ
3. Dependencies & Technologies π οΈ
| Dependency/Namespace | Purpose |
|---|---|
System.Collections.Generic |
Collection interfaces (ICollection<T>) |
IrbyImaging.Models |
Projectβs domain and shared view model namespace |
ListViewModel (custom, projectβwide) |
Base view model that provides paging functionality |
Technologies
- .NET / C#
- ASP.NET MVC or ASP.NET Core MVC (for controllers and views)
- Razor / Blazor (for frontend rendering)
4. Inheritance & Hierarchy π
// Base class (exists elsewhere in project)
public class ListViewModel
{
public int CurrentPage { get; set; }
public int PageSize { get; set; }
public int TotalCount { get; set; }
// Potentially Other Paging/Filtering fields
}
// This file
public class MobileDeviceListViewModel : ListViewModel
{
...
}
Why inherit?
- To reuse common pagination/filtering properties.
- To keep code DRY and maintainable across multiple βListβ ViewModels (e.g.,
UserListViewModel,AssetListViewModel, etc.).
5. Properties Description π·οΈ
| Property | Type | Description |
|---|---|---|
| NumberOutOfWarranty | string |
Count of devices already out of warranty. E.g., "5" |
| NumberApproachingEndOfWarranty | string |
Count of devices approaching end-of-warranty. E.g., "10" |
| MobileDevices | ICollection<MobileDeviceDetailViewModel> |
List of detailed info for each mobile device (model, serial, warranty date, etc.). |
π‘ Note: Both numeric counters are exposed as string for flexibility in formatting (e.g.,
"5 devices"vs. plain integer).
6. Sample Code Blocks & Usage Examples π
6.1 Populating in a Controller (ASP.NET MVC)
public class MobileDeviceController : Controller
{
private readonly IMobileDeviceService _service;
public MobileDeviceController(IMobileDeviceService service)
{
_service = service;
}
public async Task<IActionResult> Index(int page = 1)
{
var pageSize = 20;
// 1. Fetch paged data + warranty stats
var result = await _service.GetPaginatedDevicesAsync(page, pageSize);
// 2. Map to ViewModel
var vm = new MobileDeviceListViewModel
{
CurrentPage = page,
PageSize = pageSize,
TotalCount = result.TotalCount,
NumberOutOfWarranty = result.Stats.OutOfWarrantyCount.ToString(),
NumberApproachingEndOfWarranty = result.Stats.ApproachingEndOfWarrantyCount.ToString(),
MobileDevices = result.Items
.Select(d => new MobileDeviceDetailViewModel {
Id = d.Id,
ModelName = d.ModelName,
SerialNumber = d.SerialNumber,
WarrantyEndDate = d.WarrantyEndDate
})
.ToList()
};
return View(vm);
}
}
6.2 Razor View Example (Index.cshtml)
@model IrbyImaging.Models.MobileDeviceListViewModel
<h2>Mobile Devices π±</h2>
<div class="stats">
<span>Out of Warranty: @Model.NumberOutOfWarranty</span> |
<span>Approaching End: @Model.NumberApproachingEndOfWarranty</span>
</div>
<table class="table">
<thead>
<tr>
<th>Model</th><th>Serial</th><th>Warranty Ends</th>
</tr>
</thead>
<tbody>
@foreach(var device in Model.MobileDevices)
{
<tr>
<td>@device.ModelName</td>
<td>@device.SerialNumber</td>
<td>@device.WarrantyEndDate.ToShortDateString()</td>
</tr>
}
</tbody>
</table>
@* Paging controls *@
<div>
Page @Model.CurrentPage of @((Model.TotalCount + Model.PageSize - 1) / Model.PageSize)
</div>
7. Sample JSON Payload π
If exposed via a Web API endpoint (GET /api/mobiledevices?page=1&pageSize=20):
{
"currentPage": 1,
"pageSize": 20,
"totalCount": 53,
"numberOutOfWarranty": "5",
"numberApproachingEndOfWarranty": "10",
"mobileDevices": [
{
"id": "abc123",
"modelName": "iPhone 13",
"serialNumber": "C02X1234",
"warrantyEndDate": "2023-11-15T00:00:00"
},
{
"id": "def456",
"modelName": "Galaxy S22",
"serialNumber": "R58K9876",
"warrantyEndDate": "2024-02-20T00:00:00"
}
// β¦ more items
]
}
8. Conclusion π―
MobileDeviceListViewModel is a lightweight, reusable ViewModel tailored for displaying a list of mobile devices in the IrbyImaging UI. By inheriting from ListViewModel, it automatically supports paging and filtering. The addition of warrantyβspecific metrics (out-of-warranty vs. approaching end-of-warranty) makes it immediately useful for business dashboards and reports.
Embrace this pattern for all listβbased pages in your application to maintain consistency and reduce boilerplate!