๐Ÿ“˜ OutstandingViewModel.cs Documentation

Location
IrbyImaging/Models/Shared/OutstandingViewModel.cs


๐Ÿ“‘ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. UML Class Diagram
  4. Properties & Annotations
  5. DataAnnotations & UI Integration
  6. Key Functional Areas
  7. Sample Code Snippets & Usage Examples
  8. MVC Controller Integration
  9. Conclusion

๐ŸŒŸ Overview & Purpose

The OutstandingViewModel serves as a ViewModel in the IrbyImaging UI layer. It bundles all information needed to display an โ€œoutstanding assetโ€ in lists, tables, and detail pages. Typical use cases:

  • ๐Ÿ–ฅ๏ธ Render an equipment or asset table in a Razor/MVC view
  • ๐Ÿ”— Generate dynamic links to the appropriate controller
  • ๐ŸŽฏ Provide a stronglyโ€‘typed model for data binding and validation

๐Ÿ› ๏ธ Dependencies & Technologies

Technology / Namespace Purpose
System Base .NET types (e.g., Guid, DateTimeOffset)
System.ComponentModel.DataAnnotations UI metadata & validation attributes ([Display], [DataType])
IrbyImaging.Utility Holds shared enums: AssetStatus, AssetCategory
ASP.NET MVC / Razor Views Consumes this ViewModel for rendering UI

๐Ÿ“ UML Class Diagram

+-----------------------------------+
|        OutstandingViewModel       |
+-----------------------------------+
| - Id: Guid                        |
| - MakeAndModel: string            |
| - SerialNumber: string            |
| - Status: AssetStatus             |
| - PurchaseDate: DateTimeOffset    |
| - OwnerId: Guid                   |
| - OwnerFullName: string           |
| - Category: AssetCategory         |
+-----------------------------------+
| + Controller: string { get }      |
+-----------------------------------+

๐Ÿ” Properties & Annotations

Property Type Annotation Description
Id Guid โ€“ Unique identifier of the asset.
MakeAndModel string [Display(Name="Make/Model")] Manufacturer and model info.
SerialNumber string [Display(Name="Serial Number")] Assetโ€™s unique serial number.
Status AssetStatus โ€“ Current asset state (e.g., New, InUse, Retired).
PurchaseDate DateTimeOffset [DataType(Date)], [Display(...)] Date when asset was purchased or tested.
OwnerId Guid โ€“ Identifier of the employee/user assigned to the asset.
OwnerFullName string [Display(Name="Assigned To")] Full name of the assigned owner.
Category AssetCategory โ€“ Category classification (e.g., Camera, Light).
Controller string (readonly) โ€“ Derived: "{Category}s", used for generating MVC routes.

๐Ÿท๏ธ DataAnnotations & UI Integration

  1. [Display(Name = "...")]
    • Controls label text in Razor helpers (@Html.LabelFor, scaffolding).
  2. [DataType(DataType.Date)]
    • Renders a date picker or formatted date string in views.

Example in Razor:

@model OutstandingViewModel

<table class="table">
  <thead>
    <tr>
      <th>@Html.DisplayNameFor(m => m.MakeAndModel)</th>
      <th>@Html.DisplayNameFor(m => m.SerialNumber)</th>
      <th>@Html.DisplayNameFor(m => m.PurchaseDate)</th>
      <th>@Html.DisplayNameFor(m => m.OwnerFullName)</th>
      <th>Actions</th>
    </tr>
  </thead>
  <tbody>
  @foreach (var item in Model.OutstandingItems) {
    <tr>
      <td>@item.MakeAndModel</td>
      <td>@item.SerialNumber</td>
      <td>@item.PurchaseDate.ToShortDateString()</td>
      <td>@item.OwnerFullName</td>
      <td>
        @Html.ActionLink("Details", item.Controller, new { id = item.Id }, htmlAttributes: new { @class="btn btn-info" })
      </td>
    </tr>
  }
  </tbody>
</table>

๐Ÿ”‘ Key Functional Areas

  1. Identification
    • Id ties the asset to backend data stores (DB primary key).
  2. Categorization
    • Category & Controller enable dynamic routing to specialized controllers (e.g., /Cameras/Details/{id}).
  3. Ownership & Status
    • OwnerId, OwnerFullName, and Status track assignment and lifecycle stage.
  4. Presentation
    • Display-friendly names & formats via data annotations.

๐Ÿ’ก Sample Code Snippets & Usage Examples

1. Instantiating in Controller

public ActionResult Outstanding()
{
    var assets = _assetService.GetOutstandingAssets();
    var viewModels = assets.Select(a => new OutstandingViewModel {
        Id             = a.Id,
        MakeAndModel   = $"{a.Make} {a.Model}",
        SerialNumber   = a.SerialNumber,
        Status         = a.Status,
        PurchaseDate   = a.PurchasedOn,
        OwnerId        = a.AssignedTo.Id,
        OwnerFullName  = $"{a.AssignedTo.FirstName} {a.AssignedTo.LastName}",
        Category       = a.Category
    });

    return View(viewModels);
}
@foreach(var vm in Model)
{
    <div>
        @Html.ActionLink("View Details", vm.Controller, 
                         new { id = vm.Id }, new { @class = "btn btn-primary" })
    </div>
}

๐Ÿ”„ MVC Controller Integration

  • Dynamic Controller Name
    The Controller property returns a string like "Cameras", "Lights", etc.:
    public string Controller => $"{Category}s";
    
  • Routing Example
    If Category = AssetCategory.Camera, Controller == "Cameras".
    The link @Html.ActionLink("Go", "Details", "Cameras", new { id = vm.Id }, null) will direct to /Cameras/Details/{id}.

๐Ÿ Conclusion

The OutstandingViewModel is a lightweight yet powerful ViewModel designed to:

  • Standardize how outstanding assets are displayed in the UI
  • Leverage DataAnnotations for cleaner, more maintainable views
  • Dynamically route to the correct MVC controllers via its Controller property

By following the patterns illustrated above, developers can quickly scaffold new assetโ€related pages, ensure consistency across the application, and provide endโ€users with a clear, userโ€friendly interface. ๐Ÿš€


Happy Coding! โœจ