MobileDeviceListViewModel Documentation πŸ“±


Table of Contents

  1. Overview & Purpose
  2. Class Diagram (UML)
  3. Dependencies & Technologies
  4. Inheritance & Hierarchy
  5. Properties Description
  6. Sample Code Blocks & Usage Examples
  7. Sample JSON Payload
  8. 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 ListViewModel to 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 MobileDeviceDetailViewModel items 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!