šŸ“„ 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

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Class Definition & Inheritance
  4. UML Class Diagram
  5. Key Functional Areas
  6. ViewModel in MVVM / MVC Context
  7. Sample Code Blocks & Usage Examples
  8. Extending DockDetailViewModel
  9. Error Handling & Return Types
  10. 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

  1. Data Properties
    • Inherited from DetailViewModel (e.g., Id, Name, Description).
  2. Commands & Actions
    • LoadDetails(), Save(), Delete(), etc., inherited from the base.
  3. Validation
    • Leverages any validation logic defined on DetailViewModel (e.g., attribute‐driven).
  4. Notification
    • Implements INotifyPropertyChanged (in base) to update bound UI elements.

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
    • DetailViewModel may 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 DetailViewModel to understand available members.
  • Add domain‐specific properties & commands.
  • Wire up your UI (Razor/Blazor/WPF) to this ViewModel for seamless data binding!

Happy coding! šŸ› ļøšŸš¢