๐Ÿ“„ IrbyImaging/Views/Computers/Details.cshtml Documentation


๐Ÿ“‘ Table of Contents

  1. Overview & Purpose
  2. Key Functional Areas
  3. Dependencies & Technologies
  4. ViewModel & DataModel
  5. Layout Configuration
  6. HTML & Razor Markup Explanation
  7. Helper Methods & Utilities
  8. Error Handling & Return Types
  9. Sample Usage & Code Blocks
  10. UML Diagram
  11. Thirdโ€‘party Integrations
  12. Conclusion

1. Overview & Purpose

File: IrbyImaging/Views/Computers/Details.cshtml
Responsibility: Render a detailed, readโ€only view of a single Computer record in the ATS (Asset Tracking System).
Primary Features:

  • Presents all key properties of a ComputerDetailViewModel
  • Applies dynamic styling (e.g., warranty status)
  • Links to related data (e.g., owning employee)
  • Provides navigation buttons (Index, Edit, History)

This Razor view is part of an ASP.NET MVC flow:

  1. Controller fetches a computer entity from the database
  2. Controller builds a ComputerDetailViewModel
  3. Controller returns View(model) โ†’ Details.cshtml receives the model

2. Key Functional Areas

Section Description
ViewData & Layout config Sets page title and master layout
Header Displays Make & Model + Status
Detail List (<dl>) Shows all properties in a labelโ€‘value format
Owner Link Navigates to Employees/Details/{id}
Notes Renders multiโ€‘line notes in a <pre> block
Action Buttons Index, Update, History links for navigation
Script Includes Loads frontโ€‘end JavaScript libraries for UI

3. Dependencies & Technologies

  • ASP.NET Core MVC / Razor: Serverโ€‘side rendering
  • Bootstrap 5: Styling & buttons
  • MetaIsMenu, SimpleBar, Nodeโ€‘Waves: Interactive sidebar & UI effects
  • Custom CSS Classes: e.g., irby-red, irby-orange, irby-violet
  • _ATSLayout.cshtml: Shared layout with header, footer, navigation

4. ViewModel & DataModel

4.1 ComputerDetailViewModel (C#)

public class ComputerDetailViewModel
{
    public int Id { get; set; }
    public string MakeAndModel { get; set; }
    public string Status { get; set; }
    public string SerialNumber { get; set; }
    public string AssetNumber { get; set; }
    public string UnitNumber { get; set; }
    public string CpsNumber { get; set; }
    public string OperatingSystem { get; set; }
    public DateTime PurchaseDate { get; set; }
    public DateTime EndOfWarranty { get; set; }
    public string WarrantyColorClass { get; set; }  // e.g., "text-success" or "text-danger"
    public bool NeedsReview { get; set; }
    public int OwnerId { get; set; }                // FK to Employee
    public string OwnerFullName { get; set; }
    public string Notes { get; set; }
}

4.2 Database Model (Entity Framework)

Typically mirrored by an Computer entity with relationships:

  • public Employee Owner { get; set; }
  • Mapping to DB columns: SerialNumber, AssetNumber, etc.

5. Layout Configuration

@{
    ViewData["Title"] = "Computer Details";
    Layout = "~/Views/Shared/_ATSLayout.cshtml";
}
  • ViewData["Title"]: Sets the window/tab title
  • Layout: Points to the shared layout, ensuring consistent header/footer & navigation

6. HTML & Razor Markup Explanation

6.1 Page Title & Header

<h2>
  @Html.DisplayFor(m => m.MakeAndModel)
  <span style="color:blue">@Model.Status</span>
</h2>
  • @Html.DisplayFor: Safely encodes and renders the property
  • <span>: Applies inline style to the Status badge

6.2 Details Display (<dl>)

A definition list is used to present labelโ€‘value pairs:

<dl class="dl-horizontal">
  <dt>@Html.DisplayNameFor(m => m.SerialNumber)</dt>
  <dd>@Html.DisplayFor(m => m.SerialNumber)</dd>
  
  <!-- ...other fields... -->

  <dt>@Html.DisplayNameFor(m => m.EndOfWarranty)</dt>
  <dd class="@Model.WarrantyColorClass">
    @Html.DisplayFor(m => m.EndOfWarranty)
  </dd>
  
  <dt>@Html.DisplayNameFor(m => m.OwnerFullName)</dt>
  <dd>
    <a asp-controller="Employees" asp-action="Details" asp-route-id="@Model.OwnerId">
      @Model.OwnerFullName
    </a>
  </dd>
  
  <dt>@Html.DisplayNameFor(m => m.Notes)</dt>
  <dd><pre>@Model.Notes</pre></dd>
</dl>

Highlights:

  • DisplayNameFor: Renders the friendly label (from DataAnnotations)
  • WarrantyColorClass: Dynamically changes text color based on warranty status
  • Owner Link: Uses Tag Helpers (asp-controller, asp-action, asp-route-id)

6.3 Action Buttons

<div>
  <a asp-action="Index" class="btn btn-danger irby-red">Index List</a>
  <a asp-action="Edit" asp-route-id="@Model.Id" class="btn btn-warning irby-orange">Update</a>
  <a asp-action="History" asp-route-id="@Model.Id" class="btn btn-primary irby-violet">History</a>
</div>
  • Index: Returns to the Computers list
  • Edit: Opens the edit form for the current computer
  • History: Shows warranty or service history

7. Helper Methods & Utilities

  • ASP.NET Tag Helpers: asp-action, asp-controller, asp-route-* simplify URL generation
  • Html.DisplayFor / Html.DisplayNameFor: Leverage metadata and formatting
  • CSS Utility Classes (custom): irby-red, irby-orange, irby-violet for brand colors

8. Error Handling & Return Types

  • This is a readโ€‘only view; errors (e.g., โ€œNot Foundโ€) are handled in the Controller
  • Typical pattern in Controllerโ€™s Details(int id):
    var computer = await _context.Computers.FindAsync(id);
    if (computer == null) return NotFound();
    var vm = _mapper.Map<ComputerDetailViewModel>(computer);
    return View(vm);
    
  • Razor view assumes Model is non-null

9. Sample Usage & Code Blocks

9.1 Controller Action

public async Task<IActionResult> Details(int id)
{
    var computer = await _context.Computers
        .Include(c => c.Owner)
        .FirstOrDefaultAsync(c => c.Id == id);
    if (computer == null) return NotFound();

    var vm = new ComputerDetailViewModel
    {
        Id               = computer.Id,
        MakeAndModel     = $"{computer.Make} {computer.Model}",
        Status           = computer.Status,
        SerialNumber     = computer.SerialNumber,
        AssetNumber      = computer.AssetNumber,
        UnitNumber       = computer.UnitNumber,
        CpsNumber        = computer.CpsNumber,
        OperatingSystem  = computer.OperatingSystem,
        PurchaseDate     = computer.PurchaseDate,
        EndOfWarranty    = computer.EndOfWarranty,
        WarrantyColorClass = (computer.EndOfWarranty < DateTime.Today) ? "text-danger" : "text-success",
        NeedsReview      = computer.NeedsReview,
        OwnerId          = computer.Owner.Id,
        OwnerFullName    = computer.Owner.FullName,
        Notes            = computer.Notes
    };
    return View(vm);
}

9.2 Rendering in Browser

<h2>HP EliteBook <span style="color:blue">Active</span></h2>
<h4>Asset ID: 12345</h4>
<dl class="dl-horizontal">
  <dt>Serial Number</dt><dd>SN-33445</dd>
  <!-- โ€ฆ -->
  <dt>End Of Warranty</dt><dd class="text-success">2025-06-30</dd>
  <!-- โ€ฆ -->
  <dt>Owner Full Name</dt>
  <dd><a href="/Employees/Details/7">Jane Doe</a></dd>
  <dt>Notes</dt><dd><pre>Assigned to VIP user.</pre></dd>
</dl>

10. UML Diagram

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ ComputerDetailViewModel    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ - Id: int                  โ”‚
โ”‚ - MakeAndModel: string     โ”‚
โ”‚ - Status: string           โ”‚
โ”‚ - SerialNumber: string     โ”‚
โ”‚ - AssetNumber: string      โ”‚
โ”‚ - UnitNumber: string       โ”‚
โ”‚ - CpsNumber: string        โ”‚
โ”‚ - OperatingSystem: string  โ”‚
โ”‚ - PurchaseDate: DateTime   โ”‚
โ”‚ - EndOfWarranty: DateTime  โ”‚
โ”‚ - WarrantyColorClass: str  โ”‚
โ”‚ - NeedsReview: bool        โ”‚
โ”‚ - OwnerId: int             โ”‚
โ”‚ - OwnerFullName: string    โ”‚
โ”‚ - Notes: string            โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

11. Thirdโ€‘party Integrations

  • Bootstrap (JS & CSS)
  • MetisMenu: Sidebar accordion menus
  • SimpleBar: Custom scrollbars
  • Nodeโ€‘Waves: Ripple animation effects
<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>

12. Conclusion

๐ŸŽฏ Details.cshtml is a focused Razor view designed to present every critical attribute of a computer asset in a clean, userโ€‘friendly format. It leans on ASP.NET Core MVC best practicesโ€”stronglyโ€‘typed ViewModels, Tag Helpers, and shared layoutsโ€”to deliver a maintainable, extensible UI component within the IrbyImaging application.


Happy Coding! ๐Ÿš€