📄 DeskPhoneListViewModel.cs Documentation
Assembly:
IrbyImaging.UI
Namespace:IrbyImaging.Models
Created: 03‑31‑2022 by kvamshi
Last Modified: 03‑31‑2022 by kvamshi
Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Class Diagram (UML)
- Key Functional Areas
- Properties
- Usage Examples
- Error Handling & Return Types
- Related Types
- Conclusion
1. Overview & Purpose
DeskPhoneListViewModel is a view model designed to carry a paged list of desk‑phone details from your backend logic into your UI layer (e.g., MVC Razor, Blazor, Angular, etc.). It inherits from a generic ListViewModel to provide common list metadata (pagination, total count, etc.) and adds a strongly‑typed collection of DeskPhoneDetailViewModel.
🔑 Primary Goal:
Provide a structured, paginated representation of all desk‑phones for display in lists, tables, or grids.
2. Dependencies & Technologies
| Technology | Purpose |
|---|---|
| .NET (≥ 4.x/.NET Core) | Runtime & Base Class Library |
System.Collections.Generic |
ICollection<T> support |
| XML Documentation | Inline summaries for tooling (IntelliSense) |
| (Optional) ASP.NET MVC / Razor / Blazor | UI binding |
3. Class Diagram (UML)
classDiagram
direction LR
ListViewModel <|-- DeskPhoneListViewModel
DeskPhoneListViewModel : +ICollection<DeskPhoneDetailViewModel> DeskPhones { get; set; }
ListViewModel : +int PageNumber { get; set; }
ListViewModel : +int PageSize { get; set; }
ListViewModel : +int TotalCount { get; set; }
class DeskPhoneDetailViewModel {
+int Id
+string Model
+string Extension
+string Status
}
📊 ListViewModel is assumed to define common pagination properties:
PageNumberPageSizeTotalCount
4. Key Functional Areas
- Inheritance
ExtendsListViewModelto inherit pagination metadata. - Data Transport
Carries a collection of desk‑phone details (DeskPhones) from controller/service to view. - Flexibility
Can be consumed by MVC views, Web APIs, or SPA frameworks.
5. Properties
| Property | Type | Description |
|---|---|---|
| DeskPhones | ICollection<DeskPhoneDetailViewModel> |
The paginated list of desk‑phone DTOs. |
/// <summary>
/// Gets or sets the desk phones.
/// </summary>
/// <value>The desk phones.</value>
public ICollection<DeskPhoneDetailViewModel> DeskPhones { get; set; }
- ICollection ensures compatibility with lists, arrays, and other collection types.
6. Usage Examples
6.1 Instantiation in an API/Controller
public IActionResult GetDeskPhones(int page = 1, int pageSize = 10)
{
// 1. Query your data source for desk phones (e.g., database call)
var allPhones = _repository.GetAllDeskPhones();
// 2. Paginate
var pagedItems = allPhones
.Skip((page - 1) * pageSize)
.Take(pageSize)
.ToList();
// 3. Map to DetailViewModel
var detailVMs = pagedItems
.Select(p => new DeskPhoneDetailViewModel {
Id = p.Id,
Model = p.Model,
Extension = p.Extension,
Status = p.Status
})
.ToList();
// 4. Build the ListViewModel
var viewModel = new DeskPhoneListViewModel {
PageNumber = page,
PageSize = pageSize,
TotalCount = allPhones.Count,
DeskPhones = detailVMs
};
return Ok(viewModel);
}
6.2 Binding in a Razor View
@model IrbyImaging.Models.DeskPhoneListViewModel
<h2>Desk Phones (Page @Model.PageNumber of @((Model.TotalCount + Model.PageSize - 1) / Model.PageSize))</h2>
<table class="table">
<thead>
<tr>
<th>ID</th>
<th>Model</th>
<th>Extension</th>
<th>Status</th>
</tr>
</thead>
<tbody>
@foreach(var phone in Model.DeskPhones)
{
<tr>
<td>@phone.Id</td>
<td>@phone.Model</td>
<td>@phone.Extension</td>
<td>@phone.Status</td>
</tr>
}
</tbody>
</table>
7. Error Handling & Return Types
- Return Type (API):
- Typically
IActionResult(ASP.NET Core) returningOk(viewModel)orBadRequest(...).
- Typically
- Validation:
- Validate incoming
pageandpageSizeparameters (e.g., must be > 0).
- Validate incoming
- Null Checks:
- Ensure
DeskPhonesis initialized to an empty list if no data found to avoidNullReferenceException.
- Ensure
8. Related Types
| Type | Description |
|---|---|
ListViewModel |
Base class carrying pagination metadata. |
DeskPhoneDetailViewModel |
DTO for an individual desk‑phone record. |
IDeskPhoneRepository (example) |
Data access abstraction to fetch phones. |
9. Conclusion
🎯 DeskPhoneListViewModel is a lightweight, focused view model to transport a paginated set of desk‑phone entries into your presentation layer. By inheriting from a reusable ListViewModel, it avoids boilerplate, ensures consistency across all paged lists, and keeps your UI code clean and strongly‑typed.
Happy Coding! 🚀
IrbyImaging.UI Team