📋 DockListViewModel Documentation
Table of Contents
- Overview & Purpose
- Key Functional Areas
- Dependencies & Technologies
- Architecture & UML Diagram
- View Models & Data Models
- Helper Methods & Utilities
- Error Handling & Return Types
- API Endpoints Overview
- Third‑Party Integrations
- Sample Code Blocks & Usage Examples
- Conclusion
1. Overview & Purpose
File: IrbyImaging/Models/Dock/DockListViewModel.cs
Assembly: IrbyImaging.UI
Author: kvamshi
Created: 03-31-2022
DockListViewModelis a simple ViewModel designed to carry a collection of dock details along with any inherited list‐related metadata (paging, sorting, etc.) from its base classListViewModel.This model is typically used in an MVVM or API scenario to transport a list of docks from the server (or UI layer) to a consumer (such as a Razor page, a JSON API client, or a front-end framework).
2. Key Functional Areas
- Inheritance
- Extends
ListViewModelto reuse common list properties (e.g.,PageNumber,PageSize,TotalCount, etc.).
- Extends
- Data Container
- Holds an
ICollection<DockDetailViewModel>representing individual dock entries.
- Holds an
- UI / API Friendly
- Ready for serialization to JSON or for binding in Razor/XAML views.
3. Dependencies & Technologies
| Technology / Namespace | Purpose |
|---|---|
System.Collections.Generic |
Provides the ICollection<T> interface. |
IrbyImaging.Models |
Houses the ListViewModel and DockDetailViewModel. |
- .NET Target:
- .NET Standard / .NET Core / .NET Framework (depending on the rest of the solution).
- Serialization:
- Compatible with built‑in JSON serializers (e.g.,
System.Text.Json,Newtonsoft.Json).
- Compatible with built‑in JSON serializers (e.g.,
4. Architecture & UML Diagram
classDiagram
%% Base list model
class ListViewModel {
<<abstract>>
+int PageNumber
+int PageSize
+int TotalCount
+IEnumerable<T> Items
}
%% This file
class DockListViewModel {
+ICollection~DockDetailViewModel~ Docks
}
%% Dependents
class DockDetailViewModel {
+int Id
+string Name
+string Location
+bool IsActive
// ... other properties
}
ListViewModel <|-- DockListViewModel
DockListViewModel *-- DockDetailViewModel : contains >
ListViewModel(abstract): Common list metadata (pagination).DockListViewModel: Inherits fromListViewModel.DockDetailViewModel: Represents the details of a single dock.
5. View Models & Data Models
5.1 ListViewModel (Base Class)
Although not in this file, ListViewModel typically looks like:
public abstract class ListViewModel
{
public int PageNumber { get; set; }
public int PageSize { get; set; }
public int TotalCount { get; set; }
public IEnumerable<object> Items { get; set; }
}
5.2 DockDetailViewModel
public class DockDetailViewModel
{
public int Id { get; set; }
public string Name { get; set; }
public string Location { get; set; }
public bool IsActive { get; set; }
// ...additional fields
}
5.3 DockListViewModel (This File)
public class DockListViewModel : ListViewModel
{
/// <summary>
/// Gets or sets the detailed list of docks.
/// </summary>
public ICollection<DockDetailViewModel> Docks { get; set; }
}
6. Helper Methods & Utilities
🚧 None in this file
This class is purely a data container. All logic (paging, filtering) should be implemented elsewhere (services, controllers, or base classes).
7. Error Handling & Return Types
- No built‑in error handling directly in this ViewModel.
- Return Type:
- When used in a controller:
public IActionResult GetDocks(int page, int size) { var viewModel = _dockService.GetPagedDocks(page, size); return Ok(viewModel); // 200 OK with JSON payload }
- When used in a controller:
8. API Endpoints Overview
No direct API endpoints defined here. Typically returned by:
[HttpGet("api/docks")]
public ActionResult<DockListViewModel> GetDocks(int page = 1, int size = 10)
{
var result = _dockService.GetDockList(page, size);
return Ok(result);
}
Sample JSON Response:
{
"pageNumber": 1,
"pageSize": 10,
"totalCount": 42,
"items": [], // if inherited ListViewModel has Items
"docks": [
{ "id":1, "name":"Dock A", "location":"North Pier", "isActive":true },
{ "id":2, "name":"Dock B", "location":"East Pier", "isActive":false }
// ...
]
}
9. Third‑Party Integrations
- Serialization:
- Works seamlessly with JSON serializers (no special attributes required).
- Validation / Mapping:
- Friendly with tools like AutoMapper for projecting domain models → view models.
10. Sample Code Blocks & Usage Examples
10.1 Instantiation
var dockList = new DockListViewModel
{
PageNumber = 1,
PageSize = 5,
TotalCount = 12,
Docks = new List<DockDetailViewModel>
{
new DockDetailViewModel { Id = 1, Name = "A1", Location = "North", IsActive = true },
new DockDetailViewModel { Id = 2, Name = "B2", Location = "East", IsActive = false }
}
};
10.2 Returning from a Controller (ASP.NET Core)
[ApiController]
[Route("api/[controller]")]
public class DocksController : ControllerBase
{
private readonly IDockService _dockService;
public DocksController(IDockService dockService)
{
_dockService = dockService;
}
[HttpGet]
public ActionResult<DockListViewModel> GetAll(int page = 1, int size = 10)
{
var vm = _dockService.GetPagedDocks(page, size);
return Ok(vm);
}
}
10.3 Consuming in Razor Page / View
@model IrbyImaging.Models.DockListViewModel
<h2>Dock List (Page @Model.PageNumber of @((Model.TotalCount + Model.PageSize - 1) / Model.PageSize))</h2>
<ul>
@foreach (var dock in Model.Docks)
{
<li>
<strong>@dock.Name</strong> – @dock.Location
@(dock.IsActive ? "✅ Active" : "❌ Inactive")
</li>
}
</ul>
11. Conclusion
🎯 DockListViewModel is a lightweight, focused ViewModel designed to encapsulate a paged list of docks (DockDetailViewModel). It:
- Inherits common list metadata from
ListViewModel. - Contains an
ICollection<DockDetailViewModel>for dock entries. - Is serialization‑ready and easily wired into controllers or UI views.
Use this ViewModel to standardize how your application returns or binds lists of dock data, ensuring consistent paging and metadata across your UI/API layers.
Happy Coding! 🚀