📄 Desk Phones Index View Documentation

File: IrbyImaging/Views/DeskPhones/Index.cshtml
Purpose: Renders a searchable, sortable, and exportable data table of desk phones with CRUD actions.


📑 Table of Contents

  1. Overview & Purpose
  2. Key Functional Areas
  3. Dependencies & Technologies
  4. View Model & Data Model
  5. Layout & ViewData
  6. Page Header & Controls
  7. Search & Filtering
  8. Data Table & Export Buttons
  9. Scripts & Initialization
  10. ASP.NET Core Tag Helpers & Routes
  11. Third-Party Integrations
  12. Sample Usage & Code Snippets
  13. UML Diagram
  14. Conclusion

1. Overview & Purpose 🔎

This Razor View displays a list of desk phones stored in the system. It offers:

  • A count of the total desk phones by status.
  • Search by keyword and filter by asset status.
  • A DataTable with built‑in export buttons (CSV, Excel, Print).
  • CRUD and History actions for each phone.

It is part of the IrbyImaging ASP.NET Core MVC project and uses the shared layout _ATSLayout.cshtml.


2. Key Functional Areas 🔑

Section Responsibilities
View Model Binding Binds DeskPhoneListViewModel to the view.
Header & Add Button Displays page title & “Add New Desk Phone” link.
Search & Filter Form Keyword search + dropdown filter for AssetStatus.
DataTable Rendering Renders desk phone records in a sortable, paginated table.
Export Buttons Enables exporting table data to CSV, Excel or printing.
Action Links CRUD (Details, Update) and History for each desk phone.
Scripts Section Loads DataTables & dependencies & initializes the table.

3. Dependencies & Technologies 🛠️

Technology / Library Purpose
ASP.NET Core MVC Razor Server‑side view engine
Bootstrap 4 Responsive layout & styling
jQuery DOM manipulation
DataTables (1.10.25) Advanced HTML tables with plugins
DataTables Buttons (1.7.1) Export buttons (CSV, Excel, Print)
FontAwesome Icon fonts (search icon)

4. View Model & Data Model 🧩

public class DeskPhoneListViewModel
{
    public AssetStatus Status { get; set; }
    public IEnumerable<DeskPhoneViewModel> DeskPhones { get; set; }
}

public class DeskPhoneViewModel
{
    public int Id { get; set; }
    public string MakeAndModel { get; set; }
    public string SerialNumber { get; set; }
    public string PhoneNumber { get; set; }
    public string MacAddress { get; set; }
    public int? OwnerId { get; set; }
    public string OwnerFullName { get; set; }
    public DateTime PurchaseDate { get; set; }
    public AssetStatus Status { get; set; }
}
  • Status: Current filter (Enum: Active, Retired, etc.).
  • DeskPhones: Collection of desk phone summaries for listing.

5. Layout & ViewData 🎨

@{
    ViewData["Title"] = "Desk Phone List";
    Layout = "~/Views/Shared/_ATSLayout.cshtml";
}
  • ViewData["Title"] sets the browser title / header text.
  • Layout references a shared shell providing navigation, header, footer, etc.

6. Page Header & Controls 🖥️

<h2>
  @Html.DisplayFor(m => m.Status) Desk Phones 
  <span style="color:blue">@Model.DeskPhones.Count()</span>
</h2>

<div class="row">
  <div class="col-lg-2">
    <a asp-action="Create" class="btn btn-success irby-green">Add New Desk Phone</a>
  </div>
</div>
  • Status label (e.g., “Active Desk Phones 12”).
  • Add New button navigates to DeskPhones/Create action.

7. Search & Filtering 🔍

<form asp-action="Index" method="get">
  <div class="input-group">
    <input type="text" name="search" class="form-control" placeholder="Search for..." />
    <div class="col-lg-4" style="float:right;">
      @Html.DropDownListFor(
        model => model.Status,
        Html.GetEnumSelectList<AssetStatus>(),
        new { @class = "form-control dropdown" })
    </div>
    <span class="input-group-addon">
      <button type="submit" class="btn btn-primary irby-blue">
        <i class="fa fa-search"></i> Search
      </button>
    </span>
  </div>
</form>
  • Text box for free‑text search (e.g., by serial or owner).
  • Dropdown populated from AssetStatus enum for filtering.
  • Submits as GET to DeskPhones/Index.

8. Data Table & Export Buttons 🗃️

<table id="deskPhonesDatatable" class="table table-striped table-bordered dt-responsive nowrap">
  <thead>
    <tr>
      <th>Make/Model</th>
      <th>Serial Number</th>
      <th>Phone Number</th>
      <th>MAC Address</th>
      <th>Assigned To</th>
      <th>Purchase Date</th>
      <th>Status</th>
      <th>Actions</th>
    </tr>
  </thead>
  <tbody>
    @foreach (var item in Model.DeskPhones) {
      <tr>
        <td>@item.MakeAndModel</td>
        <td>@item.SerialNumber</td>
        <td>@item.PhoneNumber</td>
        <td>@item.MacAddress</td>
        <td>
          <a asp-controller="Employees" asp-action="Details" asp-route-id="@item.OwnerId">
            @item.OwnerFullName
          </a>
        </td>
        <td>@item.PurchaseDate.ToShortDateString()</td>
        <td>@item.Status</td>
        <td>
          <a asp-action="Details" asp-route-id="@item.Id" class="btn-sm btn-info">Details</a>
          <a asp-action="Edit" asp-route-id="@item.Id" class="btn-sm btn-warning">Update</a>
          <a asp-action="History" asp-route-id="@item.Id" class="btn-sm btn-primary">History</a>
        </td>
      </tr>
    }
  </tbody>
</table>
  • dt-responsive nowrap: Enables responsive behavior.
  • Action links allow users to view details, edit, or inspect history.

9. Scripts & Initialization ⚙️

@section Scripts {
  <!-- jQuery & DataTables -->
  <script src="https://code.jquery.com/jquery-3.5.1.js"></script>
  <script src="https://cdn.datatables.net/1.10.25/js/jquery.dataTables.min.js"></script>
  <script src="https://cdn.datatables.net/buttons/1.7.1/js/dataTables.buttons.min.js"></script>
  <!-- Export dependencies -->
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/pdfmake.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.53/vfs_fonts.js"></script>
  <script src="https://cdn.datatables.net/buttons/1.7.1/js/buttons.html5.min.js"></script>
  <script src="https://cdn.datatables.net/buttons/1.7.1/js/buttons.print.min.js"></script>

  <script type="text/javascript">
    $(document).ready(function () {
      $('#deskPhonesDatatable').DataTable({
        dom: 'Bfrtip',
        buttons: ['csv', 'excel', 'print']
      });
    });
  </script>
}
  • Loads DataTables + Buttons + export engines from CDNs.
  • Initializes the table with CSV, Excel, Print options.

10. ASP.NET Core Tag Helpers & Routes 🛣️

Helper Route / Action
asp-action="Create" DeskPhonesController.Create
asp-action="Index" DeskPhonesController.Index
asp-controller="Employees" Switches to Employees area
asp-action="Details" Details view (Desk Phone / Employee)
asp-action="Edit" Edit form for desk phone
asp-action="History" Change history of device

11. Third-Party Integrations 🔌

  • Datatables.net: Advanced grid functionality — sorting, paging, filtering.
  • jszip & pdfmake: Enables exporting to Excel & generating PDF for print.

12. Sample Usage & Code Snippets 💡

Search by Status = “Active” and Keyword “12345”:

GET /DeskPhones?search=12345&Status=Active

Initialize Razor Page:

public IActionResult Index(string search, AssetStatus status = AssetStatus.Active)
{
    var vm = _service.GetAllDeskPhones(status, search);
    return View(vm);
}

Resulting ViewModel:

{
  "Status": "Active",
  "DeskPhones": [
    {
      "Id": 1,
      "MakeAndModel": "Cisco 8841",
      "SerialNumber": "ABC123456",
      "PhoneNumber": "555-1212",
      "MacAddress": "00-1A-2B-3C-4D-5E",
      "OwnerId": 42,
      "OwnerFullName": "Jane Doe",
      "PurchaseDate": "2021-06-15T00:00:00",
      "Status": "Active"
    },
    …
  ]
}

13. UML Diagram 📊

flowchart LR
  Controller["DeskPhonesController"]
    -->|returns View(vm)| IndexView["Index.cshtml"]
  IndexView -->|binds| VM["DeskPhoneListViewModel"]
  VM -->|contains| Item["DeskPhoneViewModel*"]
  IndexView -->|AJAX/HTML| DataTable["DataTables.js"]
  DataTable -->|export| CSV[CSV/Excel/Print]

14. Conclusion 🎉

The Index.cshtml view for Desk Phones is a feature‑rich, responsive page that allows users to:

  • View, filter, and search through desk phones.
  • Export data in multiple formats.
  • Perform common CRUD operations and inspect device history.

By leveraging ASP.NET Core Razor, Bootstrap, and DataTables, it delivers a smooth, user‑friendly interface for managing desk phone assets.