đŸ“± IrbyImaging – Mobile Devices Index View Documentation


File: IrbyImaging/Views/MobileDevices/Index.cshtml
Purpose: Renders an interactive list of mobile devices (phones, tablets, hotspots) with create, search, filter, export and CRUD‑like operations.


📑 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. View Models & Data Models
  4. Key Functional Areas
  5. Third‑Party Integrations
  6. API Endpoints Overview
  7. Error Handling & Return Types
  8. Helper Methods & Utilities
  9. UML Class Diagram
  10. Usage Examples
  11. Conclusion

1. Overview & Purpose

This Razor view is the landing page for the Mobile Devices module of the IrbyImaging application. It:

  • 🎯 Displays a filtered list of mobile devices.
  • ➕ Provides buttons to add new devices by type (Phone, Tablet, Hotspot).
  • 🔍 Offers search and status‑filter capabilities.
  • 📊 Integrates DataTables for sorting, paging & exporting (CSV/Excel/Print).
  • 🔗 Links to Details, Update, and History actions.

2. Dependencies & Technologies

Technology / Library Purpose
ASP.NET Core MVC + Razor Server‑side view rendering
Bootstrap 4 Responsive UI & styling
jQuery DOM manipulations
DataTables (with Buttons extension) Interactive tables & exporting
MetisMenu, SimpleBar, Node‑Waves Layout & UI enhancements
@Html.*, @Url.Action, Tag Helpers Razor & MVC integration
@model MobileDeviceListViewModel
@{
  ViewData["Title"] = "Mobile Device List";
  Layout = "~/Views/Shared/_ATSLayout.cshtml";
}

3. View Models & Data Models

MobileDeviceListViewModel

Property Type Description
IEnumerable<MobileDevice> MobileDevices List of devices The devices to render in the table
AssetStatus Status Enum Current status filter
int NumberApproachingEndOfWarranty int Count of warranties nearing expiry
int NumberOutOfWarranty int Count of expired warranties

MobileDevice

Property Type Description
string MakeAndModel string Brand & model (e.g., “iPhone X”)
string Imei string IMEI number
string Carrier string Carrier network (e.g., “Verizon”)
string PhoneNumber string Assigned phone number
string OwnerFullName string Employee owner’s name
DateTime PurchaseDate DateTime Date of purchase
DateTime EndOfWarranty DateTime Warranty expiry date
AssetStatus Status Enum Current asset status
bool NeedsReview bool Flag for manual review
bool IsTelogis bool Telematics integration flag
string WarrantyColorClass string CSS class based on warranty status

Enums

  • DeviceType { Phone, Tablet, Hotspot }
  • AssetStatus { Active, Inactive, Maintenance, 
 }

4. Key Functional Areas

Title & Layout

@{
  ViewData["Title"] = "Mobile Device List";
  Layout = "~/Views/Shared/_ATSLayout.cshtml";
}
<h2>
  @Html.DisplayFor(m => m.Status) Mobile Devices
  <span style="color:blue">@Model.MobileDevices.Count()</span>
</h2>
  • ViewData["Title"] sets the browser title.
  • Layout references the shared _ATSLayout.cshtml.
  • The header shows the current status filter and the total count.

Add‑New Buttons

<div class="col-lg-5">
  <a asp-action="Create" asp-route-deviceType="@DeviceType.Phone" class="btn-sm btn-success irby-green">
    ➕ Add New Cell Phone
  </a>
  <a asp-action="Create" asp-route-deviceType="@DeviceType.Tablet" class="btn-sm btn-success irby-green">
    ➕ Add New Tablet
  </a>
  <a asp-action="Create" asp-route-deviceType="@DeviceType.Hotspot" class="btn-sm btn-success irby-green">
    ➕ Add New Hotspot
  </a>
</div>
  • Generates three buttons that route to MobileDevices/Create?deviceType={Phone|Tablet|Hotspot}.

Search & Filter Form

<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(
        m => m.Status,
        Html.GetEnumSelectList<AssetStatus>(),
        new { @class = "form-control dropdown" }
      )
    </div>
    <span class="input-group-addon">
      <button type="submit" class="btn btn-primary irby-blue">Search</button>
    </span>
  </div>
</form>
  • Keyword search via name="search".
  • Status filter populated from AssetStatus enum.
  • On submit, Index(search, status) is called on the controller.

Data Table Markup

<table
  id="mobileDevicesDatatable"
  class="table table-striped table-bordered dt-responsive nowrap"
  width="100%"
>
  <thead>
    <tr>
      <th>@Html.DisplayNameFor(m => m.MobileDevices.First().MakeAndModel)</th>
      <!-- ... other columns ... -->
      <th>
        Warranty
        <span class="badge irby-orange">@Model.NumberApproachingEndOfWarranty</span>
        <span class="badge irby-red">@Model.NumberOutOfWarranty</span>
      </th>
      <th>Details</th>
      <th>Update</th>
      <th>History</th>
    </tr>
  </thead>
  <tbody>
    @foreach (var item in Model.MobileDevices) {
      <tr class="@item.WarrantyColorClass">
        <td>@item.MakeAndModel</td>
        <!-- ... other fields ... -->
        <td>
          <a href="@Url.Action("Details", "MobileDevices", new { id = item.Id })"
             class="btn-sm btn-info">
            Details <img src="~/details.png" style="width:20px;" />
          </a>
        </td>
        <td>
          <a href="@Url.Action("Edit", "MobileDevices", new { id = item.Id })"
             class="btn-sm btn-warning">
            Update <img src="~/update.png" style="width:23px;" />
          </a>
        </td>
        <td>
          <a href="@Url.Action("History", "MobileDevices", new { id = item.Id })"
             class="btn-sm btn-primary">
            History <img src="~/history.png" style="width:23px;" />
          </a>
        </td>
      </tr>
    }
  </tbody>
</table>
  • Dynamically builds each row from Model.MobileDevices.
  • Uses @item.WarrantyColorClass to highlight warranty status (e.g., red for expired).

Scripts & DataTables Initialization

@section Scripts {
  <!-- jQuery & DataTables core -->
  <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>

  <!-- Buttons extension + dependencies -->
  <script src="https://cdn.datatables.net/buttons/1.7.1/js/dataTables.buttons.min.js"></script>
  <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>

  <!-- Init DataTable -->
  <script>
    $(document).ready(function () {
      $('#mobileDevicesDatatable').DataTable({
        dom: 'Bfrtip',
        buttons: ['csv', 'excel', 'print']
      });
    });
  </script>
}
  • DataTables is initialized with export buttons: CSV, Excel, Print.
  • Loaded via CDN for simplicity.

5. Third‑Party Integrations

Library Usage
DataTables (+ Buttons) Sorting, paging, live export
jQuery CDN DOM ready & DataTables dependency
Bootstrap 4 CSS/JS Grid system, form controls, button styling
MetisMenu, SimpleBar, Node‑Waves (bundled) Global layout & effects (via _ATSLayout)

6. API Endpoints Overview

Although this is purely a view, it ties into the following controller actions in MobileDevicesController:

Action HTTP Method Route Notes
Index GET /MobileDevices?search=&status= Renders this view
Create GET/POST /MobileDevices/Create?deviceType= Add new device
Details GET /MobileDevices/Details/{id} Show device details
Edit GET/POST /MobileDevices/Edit/{id} Update device info
History GET /MobileDevices/History/{id} View device change history

7. Error Handling & Return Types

  • Model Validation: Standard ASP.NET Core validation for Create/Edit POST actions.
  • NotFound(): If an ID is invalid in Details/Edit/History, the controller returns NotFound().
  • RedirectToAction("Index"): On success for Create/Edit to refresh the list.

8. Helper Methods & Utilities

  • @Html.DisplayFor(...)
  • @Html.DisplayNameFor(...)
  • @Html.DropDownListFor(model ⇒ ..., Html.GetEnumSelectList<AssetStatus>())
  • @Url.Action("Action", "Controller", new { ... })
  • Html.GetEnumSelectList<TEnum>() – extension to build <select> from an enum.

9. UML Class Diagram

@startuml
class MobileDeviceListViewModel {
  - IEnumerable<MobileDevice> MobileDevices
  - AssetStatus Status
  - int NumberApproachingEndOfWarranty
  - int NumberOutOfWarranty
}
class MobileDevice {
  - string MakeAndModel
  - string Imei
  - string Carrier
  - string PhoneNumber
  - string OwnerFullName
  - DateTime PurchaseDate
  - DateTime EndOfWarranty
  - AssetStatus Status
  - bool NeedsReview
  - bool IsTelogis
  - string WarrantyColorClass
}
enum AssetStatus { Active; Inactive; Maintenance; /* 
 */ }
MobileDeviceListViewModel --> "0..*" MobileDevice
MobileDeviceListViewModel --> AssetStatus
@enduml

10. Usage Examples

Controller

public IActionResult Index(AssetStatus? status, string search) {
  var devices = _mobileDeviceService.GetAll(status, search);
  var model = new MobileDeviceListViewModel {
    Status = status ?? AssetStatus.Active,
    MobileDevices = devices,
    NumberApproachingEndOfWarranty = devices.Count(d => d.EndOfWarranty < DateTime.Today.AddMonths(1)),
    NumberOutOfWarranty = devices.Count(d => d.EndOfWarranty < DateTime.Today)
  };
  return View(model);
}
<a asp-controller="Employees"
   asp-action="Details"
   asp-route-id="@item.OwnerId">
  @item.OwnerFullName
</a>

11. Conclusion

The Index.cshtml view in the MobileDevices folder is a feature‑rich, data‑driven page that:

  • Presents a dynamic, exportable table of corporate mobile assets.
  • Empowers users to create, filter, view, update, and audit history of devices.
  • Leverages industry‑standard libraries (DataTables, Bootstrap) for a polished UX.

By understanding each section above—models, markup, scripts, and integration points—developers can confidently extend, customize, or reuse this view for new scenarios in the IrbyImaging platform.

Enjoy building with ❀ IrbyImaging!