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:

    • Id
    • Name
    • Status
    • Location
    • (Optional) Other metadata via a Properties dictionary.
  • PrinterListViewModel (This File)

    public class PrinterListViewModel : ListViewModel
    {
        /// <summary>
        /// Gets or sets the printers.
        /// </summary>
        public ICollection<PrinterDetailViewModel> Printers { get; set; }
    }
    

5. Key Functional Areas ๐Ÿš€

  1. Collection Container
    • Holds Printers: a list of PrinterDetailViewModel.
  2. Inheritance for Paging & Filtering
    • Leverages ListViewModel to allow controllers to pass pagination or filter options alongside data.
  3. 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 PrinterListViewModel itself is typically returned from controller actions or API endpoints as JSON or passed to Razor Views.

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! ๐Ÿ–จ๏ธโœจ