📜 Documentation: IrbyImaging/Views/Computers/History.cshtml


Table of Contents

  1. Overview & Purpose
  2. Key Functional Areas
  3. Dependencies & Technologies
  4. View Models & Data Models
  5. Markup Structure & Tag Helpers
  6. Helper Methods & Utilities
  7. Third‑party Integrations
  8. Sample Code Blocks & Snippets
  9. UML Class Diagram
  10. Usage Example
  11. Error Handling & Edge Cases
  12. Conclusion

1. Overview & Purpose

This Razor view renders a computer asset’s history and activity timeline within the IrbyImaging web application. It is intended for the ComputersController action History(int assetId) and uses the HistoryListViewModel to:

  • Display current asset details (make, model, serial no., warranty, status, etc.)
  • Show a chronological activity feed (timestamp, comments, assigned‐to, status changes)
  • Provide navigation buttons to index, details, or update views of the asset

🖥️ When to use:

  • An administrator or support agent clicks “History” on a computer record and is presented with both static metadata and a dynamic timeline of changes.

2. Key Functional Areas

Section Description Emoji
Page Setup Sets title & master layout 🎨
Asset Header Renders “ASSET HISTORY” heading 🏷️
Details Card Shows read‐only properties: Make/Model, OS, Serial, Purchase Date, Warranty, Notes, Status 📊
Activity Timeline Vertical timeline (.verti-timeline) listing each history entry (timestamp, reason, owner) 🔄
Navigation Buttons Links to Index, Details, and Edit 🔗
Scripts Includes JS bundles: Bootstrap, MetisMenu, SimpleBar, Waves ⚙️

3. Dependencies & Technologies

  • ASP.NET Core MVC
  • Razor View Engine
  • Tag Helpers: asp-controller, asp-action, asp-route-id
  • Bootstrap 5 for layout & styling
  • MetisMenu, SimpleBar, Node‑Waves for sidebar/menu & scrollbars
  • C# expressions inside @{ … } blocks

4. View Models & Data Models

4.1 HistoryListViewModel (ViewModel)

public class HistoryListViewModel
{
    public int AssetId { get; set; }
    public ComputerListViewModel ComputerList { get; set; }
    public IEnumerable<History> Histories { get; set; }
}

4.2 ComputerListViewModel (ViewModel)

public class ComputerListViewModel
{
    public string MakeAndModel { get; set; }
    public string OperatingSystem { get; set; }
    public string CpsNumber { get; set; }
    public DateTime? EndOfWarranty { get; set; }
}

4.3 History (Domain/ViewModel)

public class History
{
    public DateTime Timestamp { get; set; }
    public string Owner { get; set; }
    public int OwnerId { get; set; }
    public string ModifiedBy { get; set; }
    public string Reason { get; set; }
    public string Status { get; set; }
    public object SomeAsset { get; set; }      // Cast to DomainClasses.Computer
}

4.4 DomainClasses.Computer (Data Model)

public class Computer
{
    public string SerialNumber { get; set; }
    public string AssetNumber { get; set; }
    public string UnitNumber { get; set; }
    public DateTime PurchaseDate { get; set; }
    public string Status { get; set; }
    public string Notes { get; set; }
    // other properties...
}

5. Markup Structure & Tag Helpers

@model HistoryListViewModel
@{ 
    ViewData["Title"] = "Computer History"; 
    Layout = "~/Views/Shared/_ATSLayout.cshtml"; 
}

<h2 style="color: #11467e"><u>ASSET HISTORY</u></h2>

@* Grab the first history record to display static details *@
@{ 
    var first = Model.Histories.FirstOrDefault();
    var asset = first?.SomeAsset as DomainClasses.Computer;
}

<div class="card">
  <div class="card-body">
    <h1 class="text-danger">DETAILS</h1>
    <h5><b>Make/Model:</b> <i class="text-primary">@Model.ComputerList.MakeAndModel</i></h5>
    <!-- other fields -->
    <h5><b>Notes:</b>
      <pre><i class="text-primary">@asset?.Notes</i></pre>
    </h5>
  </div>
</div>

<div class="card">
  <div class="card-body">
    <h2 class="text-danger">ACTIVITY</h2>
    <ul class="verti-timeline list-unstyled">
      @foreach(var hi in Model.Histories) {
        <li class="event-list">
          <div class="event-timeline-dot"><i class="bx bx-right-arrow-circle"></i></div>
          <div class="d-flex">
            <div class="flex-shrink-0 me-3">
              <i class="bx bx-time">@hi.Timestamp</i>
            </div>
            <div class="flex-grow-1">
              <div>
                <i class="bx bx-notepad">Comment - @hi.Reason</i>
              </div>
              <div>
                <i class="bx bx-user">Assigned To - 
                  <a asp-controller="Employees" asp-action="Details" asp-route-id="@hi.OwnerId">
                    @hi.Owner
                  </a>
                </i>
              </div>
              <div>
                <i class="bx bx-analyse">Status - @hi.Status</i>
              </div>
            </div>
          </div>
        </li>
      }
    </ul>
  </div>
</div>

<a asp-action="Index" class="btn btn-danger">Index List</a>
<a asp-action="Details" asp-route-id="@Model.AssetId" class="btn btn-success">Details</a>
<a asp-action="Edit" asp-route-id="@Model.AssetId" class="btn btn-warning">Update</a>
  • @model HistoryListViewModel binds the view to its ViewModel
  • asp-controller, asp-action, asp-route-id generate anchor URLs

6. Helper Methods & Utilities

  • Model.Histories.FirstOrDefault() — Retrieves the first history record safely
  • as DomainClasses.Computer — Casts the generic SomeAsset object to a strongly typed Computer
  • Html.DisplayFor(...) — (commented out) standard display templates for model properties

7. Third‑party Integrations

Library Purpose
Bootstrap Layout, card components, buttons
MetisMenu Sidebar navigation (shared layout)
SimpleBar Custom scrollbars
Node‑Waves Ripple effect on clicks

Scripts are loaded at the bottom:

<script src="~/libs/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="~/libs/metismenu/metisMenu.min.js"></script>
<script src="~/libs/simplebar/simplebar.min.js"></script>
<script src="~/libs/node-waves/waves.min.js"></script>

8. Sample Code Blocks & Snippets

8.1 Controller Action

public IActionResult History(int id)
{
    var histories = _historyService.GetByAssetId(id);
    var computerInfo = _computerService.GetSummary(id);
    var vm = new HistoryListViewModel
    {
        AssetId       = id,
        ComputerList  = computerInfo,
        Histories     = histories
    };
    return View(vm);
}
<a asp-controller="Employees"
   asp-action="Details"
   asp-route-id="@hi.OwnerId">
   @hi.Owner
</a>

9. UML Class Diagram

classDiagram
    HistoryListViewModel --> ComputerListViewModel
    HistoryListViewModel --> History
    History o-- "1" DomainClasses.Computer : SomeAsset
    ComputerListViewModel : +string MakeAndModel
    ComputerListViewModel : +string OperatingSystem
    History : +DateTime Timestamp
    History : +string Owner
    History : +string Reason
    DomainClasses.Computer : +string SerialNumber
    DomainClasses.Computer : +DateTime PurchaseDate
    DomainClasses.Computer : +string Notes

10. Usage Example

  1. Navigate to /Computers/History/{assetId}
  2. Controller populates HistoryListViewModel.
  3. View renders:
    • Details card at top
    • Timeline of events in the middle
    • Action buttons at bottom

11. Error Handling & Edge Cases

  • Empty Histories: If Model.Histories is empty, FirstOrDefault() returns null. The view uses the null‐conditional operator (first?) to avoid runtime errors—fields render blank.
  • Null SomeAsset: If the asset cast fails, properties like .Notes are null‐safe but display empty.
  • Missing Layout: If _ATSLayout.cshtml is removed/renamed, the view will throw a layout resolution error.

12. Conclusion

This Razor page provides a comprehensive interface for viewing a computer asset’s static information alongside a dynamic activity feed. By leveraging ASP.NET Core MVC and Bootstrap, it offers a maintainable, responsive, and user‐friendly UI for asset lifecycle management. 🎉


End of Documentation