📄 Documentation: HistoryListViewModel.cs


📑 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Class Diagram (UML)
  4. Key Functional Areas
  5. View Models & Data Models
  6. Usage Examples
  7. Sample Code Blocks
  8. Error Handling & Return Types
  9. Third-Party Integrations
  10. Conclusion

🔍 Overview & Purpose

HistoryListViewModel is part of the IrbyImaging.Models namespace and lives under the folder Models/History. It aggregates a set of historical records and related device details for a given asset. This view model is designed to:

  • Serve as a Data Transfer Object (DTO) for passing historical data and device metadata from the server to the UI layer (e.g., Razor views, MVC controllers, Web APIs).
  • Group multiple granular view models into one coherent package.
  • Simplify rendering of history data and associated device details in a UI page or component.

⚙️ Dependencies & Technologies

Technology / Namespace Purpose
System Base .NET classes
System.Collections.Generic Collection types (ICollection<T>)
IrbyImaging.Models Contains other view models referenced here

No external NuGet packages are required for this simple DTO.


📈 Class Diagram (UML)

Below is a PlantUML snippet illustrating the relationships:

@startuml
class HistoryListViewModel {
    +Guid AssetId
    +ICollection<HistoryViewModel> Histories
    +ComputerDetailViewModel ComputerList
    +MobileDeviceDetailViewModel MobileList
    +DeskPhoneDetailViewModel DeskPhoneList
    +DockDetailViewModel DocksList
    +MonitorDetailViewModel MonitorsList
    +NetworkEquipmentDetailViewModel NetworkEquipmentsList
    +OfficePrinterDetailViewModel OfficePrintersList
    +PrinterDetailViewModel PrintersList
    +SafetyEquipmentDetailViewModel SafetyEquipmentsList
}
HistoryListViewModel *-- HistoryViewModel
HistoryListViewModel *-- ComputerDetailViewModel
HistoryListViewModel *-- MobileDeviceDetailViewModel
HistoryListViewModel *-- DeskPhoneDetailViewModel
HistoryListViewModel *-- DockDetailViewModel
HistoryListViewModel *-- MonitorDetailViewModel
HistoryListViewModel *-- NetworkEquipmentDetailViewModel
HistoryListViewModel *-- OfficePrinterDetailViewModel
HistoryListViewModel *-- PrinterDetailViewModel
HistoryListViewModel *-- SafetyEquipmentDetailViewModel
@enduml

🔑 Key Functional Areas

Asset Identifier

  • Property: Guid AssetId
  • Description: The unique identifier for the asset whose history and device details are being represented.

Histories Collection

  • Property: ICollection<HistoryViewModel> Histories
  • Description: A collection of HistoryViewModel items, each representing a single change, event, or transaction in the asset’s lifecycle.

Device Detail View Models

These properties map out detailed lists of various device categories associated with the asset:

Property Type Description
ComputerList ComputerDetailViewModel Details of computers assigned or historically used.
MobileList MobileDeviceDetailViewModel Details of mobile devices (phones, tablets).
DeskPhoneList DeskPhoneDetailViewModel Desk phone hardware details.
DocksList DockDetailViewModel Docking stations information.
MonitorsList MonitorDetailViewModel Monitor peripherals.
NetworkEquipmentsList NetworkEquipmentDetailViewModel Routers, switches, and related network gear.
OfficePrintersList OfficePrinterDetailViewModel Office printer details.
PrintersList PrinterDetailViewModel Other printers (e.g., label, 3D).
SafetyEquipmentsList SafetyEquipmentDetailViewModel Safety devices (e.g., fire extinguisher tags).

🧩 View Models & Data Models

Each child view model encapsulates properties relevant to its device type. For example, ComputerDetailViewModel may include:

public class ComputerDetailViewModel {
    public Guid ComputerId { get; set; }
    public string Manufacturer { get; set; }
    public string Model { get; set; }
    public DateTime PurchaseDate { get; set; }
    // ... other properties
}

The pattern is repeated across MobileDeviceDetailViewModel, DeskPhoneDetailViewModel, etc., maintaining consistency.


⚙️ Usage Examples

1. Instantiating HistoryListViewModel

var historyVm = new HistoryListViewModel {
    AssetId = Guid.NewGuid(),
    Histories = new List<HistoryViewModel> {
        new HistoryViewModel {
            EventId = Guid.NewGuid(),
            ChangeDate = DateTime.UtcNow,
            Description = "Asset created"
        }
    },
    ComputerList = new ComputerDetailViewModel {
        ComputerId = Guid.NewGuid(),
        Manufacturer = "Contoso",
        Model = "X100",
        PurchaseDate = new DateTime(2021, 1, 15)
    },
    // Initialize other lists similarly...
};

2. Passing to a Controller / API

public IActionResult AssetHistory(Guid id) {
    // 1. Fetch data from database
    // 2. Map to HistoryListViewModel
    // 3. Return to view or JSON
    var model = _historyService.GetHistoryList(id);
    return View("History", model);
}

🛠️ Sample Code Blocks

Full Source of HistoryListViewModel.cs

// Namespace and using directives
using System;
using System.Collections.Generic;

namespace IrbyImaging.Models {
    /// <summary>
    /// Aggregates historical records and device detail lists for a single asset.
    /// </summary>
    public class HistoryListViewModel {
        public Guid AssetId { get; set; }
        public ICollection<HistoryViewModel> Histories { get; set; }
        public ComputerDetailViewModel ComputerList { get; set; }
        public MobileDeviceDetailViewModel MobileList { get; set; }
        public DeskPhoneDetailViewModel DeskPhoneList { get; set; }
        public DockDetailViewModel DocksList { get; set; }
        public MonitorDetailViewModel MonitorsList { get; set; }
        public NetworkEquipmentDetailViewModel NetworkEquipmentsList { get; set; }
        public OfficePrinterDetailViewModel OfficePrintersList { get; set; }
        public PrinterDetailViewModel PrintersList { get; set; }
        public SafetyEquipmentDetailViewModel SafetyEquipmentsList { get; set; }
    }
}

🚨 Error Handling & Return Types

  • Error Handling
    • As a simple DTO, HistoryListViewModel does not implement any validation or error handling itself.
    • Validation, null-checks, and exception management should occur in services or controllers before instantiation.
  • Return Types
    • Typically returned from MVC actions (IActionResult) or Web API endpoints (ActionResult<HistoryListViewModel>).

🔗 Third-Party Integrations

  • None. This class is framework-agnostic and only depends on .NET Core / .NET Framework base libraries.

🏁 Conclusion

HistoryListViewModel is a centralized, strongly-typed container for presenting an asset’s history alongside its related device details. By grouping multiple specialized view models, it simplifies data transport between the backend and UI, providing a clean and extensible structure for future device types or history extensions.

Use this view model in your service layer to gather data, map domain entities into the view models, and pass it to your views or API responses. Its flat structure and typed properties ensure intellisense support and compile-time safety when rendering complex history pages or dashboards in your application.


👍 Happy Coding!