š DockDetailViewModel Documentation
File:
IrbyImaging/Models/Dock/DockDetailViewModel.cs
Assembly: IrbyImaging.UI
Author: kvamshi
Created: 03ā31ā2022
Last Modified: 03ā31ā2022
Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Class Definition & Inheritance
- UML Class Diagram
- Key Functional Areas
- ViewModel in MVVM / MVC Context
- Sample Code Blocks & Usage Examples
- Extending DockDetailViewModel
- Error Handling & Return Types
- Conclusion
1. Overview & Purpose
DockDetailViewModel is a simple ViewModel class in the IrbyImaging UI layer that inherits from a more generic DetailViewModel. It serves as the dedicated dataācarrier for presenting and editing āDockā details in the user interface.
-
š¢ Domain Context
A āDockā in Irby Imaging might represent a physical docking station, a database record, or any entity requiring detailālevel UI interaction. -
šÆ Primary Purpose
- Centralize properties and commands for the Dock detail view.
- Promote separation of concerns by decoupling UI from business logic/data models.
2. Dependencies & Technologies
| Technology / Library | Version | Purpose |
|---|---|---|
| .NET | ā„ .NET Standard 2.0 | Base platform for UI and ViewModels |
| C# | 8.0+ | Language features (inheritance, etc.) |
| MVVM / MVC Pattern | ā | Architectural pattern for UI apps |
| IrbyImaging.Models | ā | Contains DetailViewModel base class |
3. Class Definition & Inheritance
namespace IrbyImaging.Models
{
/// <summary>
/// Class DockDetailViewModel.
/// Implements the <see cref="IrbyImaging.Models.DetailViewModel" />
/// </summary>
public class DockDetailViewModel : DetailViewModel
{
// Currently inherits all members from DetailViewModel.
// Extend with Dock-specific properties or commands here.
}
}
- Namespace:
IrbyImaging.Models - Inherits From:
DetailViewModel - Implements / Overrides: None (but ready for future overrides)
4. UML Class Diagram
@startuml
title DockDetailViewModel UML
class DetailViewModel {
<<abstract>>
+int Id
+string Name
+string Description
+DateTime CreatedOn
+void LoadDetails()
}
class DockDetailViewModel {
<<concrete>>
// Inherits all properties/methods
}
DetailViewModel <|-- DockDetailViewModel
@enduml
The above diagram shows DockDetailViewModel inheriting from the abstract/base DetailViewModel class.
5. Key Functional Areas
- Data Properties
- Inherited from
DetailViewModel(e.g.,Id,Name,Description).
- Inherited from
- Commands & Actions
LoadDetails(),Save(),Delete(), etc., inherited from the base.
- Validation
- Leverages any validation logic defined on
DetailViewModel(e.g., attributeādriven).
- Leverages any validation logic defined on
- Notification
- Implements
INotifyPropertyChanged(in base) to update bound UI elements.
- Implements
6. ViewModel in MVVM / MVC Context
| Concern | MVC Controller | MVVM ViewModel |
|---|---|---|
| Responsibility | Handle HTTP or UI requests, return Views/JSON | Expose properties & commands for View binding |
| Data Binding | Razor/HTML | XAML/Blazor/C# Binding |
| Lifetime | Per HTTP request | Per UserControl / Window |
DockDetailViewModel sits between the Dock View (e.g., a Razor page or WPF UserControl) and the Model (domain / data layer).
7. Sample Code Blocks & Usage Examples
7.1. Razor View (ASP.NET MVC)
@model IrbyImaging.Models.DockDetailViewModel
<h2>Dock Details</h2>
<div>
<label>ID:</label> @Model.Id
</div>
<div>
<label>Name:</label>
<input asp-for="Name" />
<span asp-validation-for="Name"></span>
</div>
<div>
<button type="submit">Save</button>
</div>
7.2. Instantiation & Data Loading (C#)
public class DockController : Controller
{
public IActionResult Details(int id)
{
var viewModel = new DockDetailViewModel();
viewModel.LoadDetails(id); // Method from DetailViewModel
return View(viewModel);
}
[HttpPost]
public IActionResult Save(DockDetailViewModel model)
{
if (!ModelState.IsValid)
return View("Details", model);
model.Save(); // Saves via base class
return RedirectToAction("Index");
}
}
8. Extending DockDetailViewModel
You can customize DockDetailViewModel by adding Dockāspecific properties or commands:
public class DockDetailViewModel : DetailViewModel
{
public bool IsLocked { get; set; }
public string LocationCode { get; set; }
public ICommand LockDockCommand { get; }
public ICommand UnlockDockCommand { get; }
public DockDetailViewModel()
{
LockDockCommand = new RelayCommand(LockDock, () => !IsLocked);
UnlockDockCommand = new RelayCommand(UnlockDock, () => IsLocked);
}
private void LockDock() => IsLocked = true;
private void UnlockDock() => IsLocked = false;
}
9. Error Handling & Return Types
- Inherited Behavior
DetailViewModelmay throw or capture exceptions on data operations (LoadDetails,Save).- Ensure you wrap calls in try/catch or use global exception filters in controllers.
- Validation
- Data annotations on properties surface validation errors back to the UI.
10. Conclusion
š DockDetailViewModel is a lightweight, inheritable class ready to power any āDockā detail scenario in the IrbyImaging UI. By extending DetailViewModel, it inherits common dataāloading, saving, and notification functionalityāwhile remaining flexible to add dockāspecific properties and commands.
Whether youāre building an ASP.NET MVC site, a WPF application, or a Blazor front end, this ViewModel can be wired directly into your views to maintain clean separation of concerns, reusable code, and robust data validation.
š Next Steps:
- Review
DetailViewModelto understand available members. - Add domaināspecific properties & commands.
- Wire up your UI (Razor/Blazor/WPF) to this ViewModel for seamless data binding!
Happy coding! š ļøš¢