PrinterListViewModel.cs
# ๐ IrbyImaging.UI โ PrinterListViewModel Documentation
---
> **File:** `IrbyImaging/Models/Printer/PrinterListViewModel.cs`
> **Assembly:** `IrbyImaging.UI`
> **Author:** `kvamshi`
> **Created:** 03-31-2022
> **Last Modified:** 03-31-2022
---
## ๐๏ธ Table of Contents
1. [Overview & Purpose](#overview--purpose)
2. [Dependencies & Technologies](#dependencies--technologies)
3. [UML Class Diagram](#uml-class-diagram)
4. [View Models & Data Models](#view-models--data-models)
5. [Key Functional Areas](#key-functional-areas)
6. [Helper Methods & Utilities](#helper-methods--utilities)
7. [Error Handling & Return Types](#error-handling--return-types)
8. [API Endpoints Overview](#api-endpoints-overview)
9. [ThirdโParty Integrations](#third%E2%80%91party-integrations)
10. [Sample Code Blocks & Usage Examples](#sample-code-blocks--usage-examples)
11. [Conclusion](#conclusion)
---
## 1. Overview & Purpose ๐
The `PrinterListViewModel` is a **simple ViewModel** used in the *IrbyImaging* UI layer to transport a collection of printers from the backend to the UI.
- **Namespace:** `IrbyImaging.Models`
- **Inheritance:** Inherits from `ListViewModel` to gain common paging/filter properties.
- **Primary Role:** Encapsulate a list of `PrinterDetailViewModel` objects for display in printer management screens (e.g., lists, dropdowns).
---
## 2. Dependencies & Technologies ๐
| Dependency | Purpose |
|-----------------------------------------|------------------------------------------------------------|
| `System.Collections.Generic` | Provides `ICollection<T>` for strongly-typed collections. |
| `IrbyImaging.Models.ListViewModel` | Base type with shared list behavior (paging, sorting). |
| `IrbyImaging.Models.PrinterDetailViewModel` | Represents individual printer details. |
**Technologies:**
- .NET Standard / .NET Core (C#)
- ASP.NET MVC / Web API (Usage context)
---
## 3. UML Class Diagram ๐
```mermaid
classDiagram
ListViewModel <|-- PrinterListViewModel
PrinterListViewModel : +ICollection<PrinterDetailViewModel> Printers
class ListViewModel {
<<abstract>>
+int Page
+int PageSize
+string Sort
+string Filter
}
class PrinterDetailViewModel {
+int Id
+string Name
+string Status
+string Location
+Dictionary<string,string> Properties
}
4. View Models & Data Models ๐ผ๏ธ
-
ListViewModel (Base Class)
Provides common fields for any paged list (e.g.,Page,PageSize,Sort,Filter). -
PrinterDetailViewModel
Holds printer-specific properties:IdNameStatusLocation- (Optional) Other metadata via a
Propertiesdictionary.
-
PrinterListViewModel (This File)
public class PrinterListViewModel : ListViewModel { /// <summary> /// Gets or sets the printers. /// </summary> public ICollection<PrinterDetailViewModel> Printers { get; set; } }
5. Key Functional Areas ๐
- Collection Container
- Holds
Printers: a list ofPrinterDetailViewModel.
- Holds
- Inheritance for Paging & Filtering
- Leverages
ListViewModelto allow controllers to pass pagination or filter options alongside data.
- Leverages
- Serialization-Friendly
- Simple CLR types making it ideal for JSON serialization in Web APIs or MVC Views.
6. Helper Methods & Utilities ๐ ๏ธ
Note: This class contains no methodsโonly a property. All helpers (e.g., mapping, validation) happen elsewhere (AutoMapper profiles, service layers, etc.).
7. Error Handling & Return Types โโก๏ธโ
-
Error Handling:
- N/A (this is a plain DTO/ViewModel โ no internal logic).
-
Return Types:
- The
PrinterListViewModelitself is typically returned from controller actions or API endpoints as JSON or passed to Razor Views.
- The
8. API Endpoints Overview ๐
Contextual Example
Although no endpoints are defined here, imagine a Web API controller:
[HttpGet("api/printers")]
public IActionResult GetPrinters([FromQuery] PrinterListViewModel query)
{
var result = _printerService.GetPaginatedPrinters(query);
return Ok(result); // returns PrinterListViewModel as JSON
}
9. ThirdโParty Integrations ๐ค
- AutoMapper (common for mapping domain models to
PrinterDetailViewModel). - Newtonsoft.Json or System.Text.Json for JSON (de)serialization.
10. Sample Code Blocks & Usage Examples ๐
10.1. Creating a Model in Controller
public IActionResult PrinterIndex(int page = 1)
{
// Simulated service call
var printers = _printerService.GetAllPrinters();
var vm = new PrinterListViewModel
{
Page = page,
PageSize = 20,
Sort = "Name",
Printers = printers.Select(p => new PrinterDetailViewModel {
Id = p.Id,
Name = p.Name,
Status = p.Status,
Location = p.Location
}).ToList()
};
return View(vm); // Pass to Razor view
}
10.2. Razor View Snippet
@model IrbyImaging.Models.PrinterListViewModel
<h2>๐จ๏ธ Printer List</h2>
<table>
<thead>
<tr>
<th>Name</th>
<th>Status</th>
<th>Location</th>
</tr>
</thead>
<tbody>
@foreach(var printer in Model.Printers)
{
<tr>
<td>@printer.Name</td>
<td>@printer.Status</td>
<td>@printer.Location</td>
</tr>
}
</tbody>
</table>
11. Conclusion โ
The PrinterListViewModel is a lightweight, extensible container designed for displaying and transporting printer collections in the IrbyImaging UI. By inheriting from ListViewModel, you get builtโin pagination/filter support, and by carrying a typed collection of PrinterDetailViewModel, the class ensures type safety, serialization readiness, and easy integration with MVC views or Web API endpoints.
Happy coding! ๐จ๏ธโจ