📄 EmployeeDirectory.cshtml Documentation
Welcome to the comprehensive documentation for IrbyImaging/Views/FieldOffices/EmployeeDirectory.cshtml. This Razor view renders an interactive “Employee Master List” table using ASP.NET Core MVC and DataTables. Below you’ll find an in-depth breakdown of its structure, dependencies, rendering logic, and usage examples.
📑 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Data Model & ViewModel 📋
- Rendering Logic & Key Functional Areas ⚙️
4.1 Page Header & Title
4.2 Table Layout & Columns
4.3 Primary/Secondary Phone Extraction
4.4 Action Links & Navigation
4.5 Scripts & Initialization 📜 - DataTables Integration 📊
- UML Class Diagram 🛠️
- Usage Example & Integration 🚀
- Conclusion 🎯
1. Overview & Purpose
This view displays a master directory of employees for Field Offices. It:
- Lists each employee’s key details (JDE number, name, title, department, supervisor, job, phones, and email).
- Leverages the DataTables plugin to provide search, sort, pagination, and export (CSV/Excel/Print).
- Injects an EF Core context to fetch mobile devices for primary/secondary phone numbers on the fly.
Use this view when you need a centralized, interactive directory in your ASP.NET Core MVC portal.
2. Dependencies & Technologies
| Technology/Library | Purpose |
|---|---|
| ASP.NET Core MVC Razor | Server-side view rendering |
| Entity Framework Core (IrbyContext) | Data access (employees, mobile devices) |
| jQuery | DOM manipulation & DataTables dependency |
| DataTables & Buttons Extension | Interactive table with export options |
| Bootstrap 4 | Responsive styling |
| MetisMenu, Simplebar, node-waves | Admin template utilities |
<!-- Example CSS Includes -->
<link href="~/lib/datatables/css/dataTables.bootstrap4.min.css" rel="stylesheet" />
<link href="https://cdn.datatables.net/1.10.25/css/jquery.dataTables.min.css" rel="stylesheet" />
<link href="https://cdn.datatables.net/buttons/1.7.1/css/buttons.dataTables.min.css" rel="stylesheet" />
3. Data Model & ViewModel 📋
Model passed to the view:
@model IEnumerable<IrbyImaging.DomainClasses.Employee>
@inject IrbyContext _context
Employee (DomainClasses.Employee)
| Property | Type | Description |
|---|---|---|
int JdeNumber |
int |
Unique employee number |
string FullName |
string |
Concatenated first & last name |
string Title |
string |
Job title |
Department |
Department (Entity) |
Navigation to Dept (with Name) |
int ManagerId |
int |
Supervisor’s employee ID |
string ManagerName |
string |
Supervisor’s display name |
int JobId |
int |
FK to Jobs |
Job |
Job (Entity) |
Navigation to Job (with Name) |
string OfficePhone |
string |
Landline phone |
string WorkEmail |
string |
Corporate email address |
ICollection<Asset> |
Asset list | List of assigned assets (e.g., phones) |
Note: The view uses
_context.MobileDevicesto resolve phone numbers by matchingAsset.Id→MobileDevice.Id.
4. Rendering Logic & Key Functional Areas ⚙️
4.1 Page Header & Title
@{
ViewData["Title"] = "Employee Master List";
Layout = "~/Views/Shared/_ATSLayout.cshtml";
}
<h2>
Employee Master List
<span class="badge irby-blue">@Model.Count()</span>
</h2>
<br />
- ViewData["Title"] sets the browser title & layout’s header.
- Badge shows the total count of employees.
4.2 Table Layout & Columns
<table id="empMasterDatatable" class="table table-striped table-bordered ...">
<thead>
<tr>
<th>Emp#</th>
<th>Name</th>
<th>Title</th>
<th>Department</th>
<th>Supervisor</th>
<th>Job</th>
<th>Primary Cell</th>
<th>Secondary Cell</th>
<th>Office Phone</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<!-- Rendered in foreach loop -->
</tbody>
</table>
- Bootstrap classes for styling (
table-striped,table-bordered). - dt-responsive and nowrap for proper responsiveness.
4.3 Primary/Secondary Phone Extraction
Inside the @foreach(var item in Model) loop:
var assets = item.Assets
.Where(a => a.Category == AssetCategory.MobileDevice)
.ToList();
if (assets.Count > 0) {
// Primary phone
var p = assets.First();
primary = _context.MobileDevices.Find(p.Id)?.PhoneNumber;
// Secondary phone (if exists)
if (assets.Count > 1) {
var s = assets.Skip(1).First();
Secondary = _context.MobileDevices.Find(s.Id)?.PhoneNumber;
}
}
- Filters the employee’s assets for
MobileDevicecategory. - Fetches actual phone numbers by querying
_context.MobileDevices.
⚠️ Ideally, move this logic to a ViewModel or service layer to avoid DB calls from the view.
4.4 Action Links & Navigation
<td>
<a asp-controller="Employees"
asp-action="Details"
asp-route-id="@item.ManagerId">
@item.ManagerName
</a>
</td>
<td>
<a asp-controller="Jobs"
asp-action="Details"
asp-route-id="@item.JobId">
@item.Job.Name
</a>
</td>
asp-route-idensures proper routing to Details pages.- Tag Helpers simplify link generation.
4.5 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>
<!-- Buttons Extension -->
<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>
<!-- Initialize DataTable -->
<script>
$(document).ready(function () {
$('#empMasterDatatable').DataTable({
dom: 'Bfrtip',
buttons: ['csv', 'excel', 'print']
});
});
</script>
}
dom: 'Bfrtip'places Buttons (B) at the top.- Exports: CSV, Excel, Print.
5. DataTables Integration 📊
The view leverages the DataTables plugin for:
- Client-side search & sort
- Responsive pagination
- Export features via the Buttons extension.
To customize:
$('#empMasterDatatable').DataTable({
paging: true,
searching: true,
ordering: true,
buttons: [
{ extend: 'excel', title: 'Employees' },
'print'
]
});
6. UML Class Diagram 🛠️
classDiagram
class Employee {
+int JdeNumber
+string FullName
+string Title
+Department Department
+int ManagerId
+string ManagerName
+int JobId
+Job Job
+string OfficePhone
+string WorkEmail
+ICollection<Asset> Assets
}
class Asset {
+int Id
+AssetCategory Category
}
class MobileDevice {
+int Id
+string PhoneNumber
}
Employee --> "1..*" Asset
Asset --|> MobileDevice : maps to
Employee --> Department
Employee --> Job
7. Usage Example & Integration 🚀
-
Controller Action (FieldOfficesController):
public IActionResult EmployeeDirectory() { var employees = _context.Employees .Include(e => e.Department) .Include(e => e.Job) .Include(e => e.Assets) .ToList(); return View(employees); } -
Route:
GET /FieldOffices/EmployeeDirectory -
Render:
- The view will auto‑inject
_contextto fetch phone details. - Users can search, sort, and export the table.
- The view will auto‑inject
8. Conclusion 🎯
EmployeeDirectory.cshtml provides a rich, interactive employee listing page within the IrbyImaging portal. By combining ASP.NET Core MVC with DataTables, it delivers both performance and user-friendly features—search, pagination, and exports. While the current view does direct DB calls for phone retrieval, you may refactor that logic into a ViewModel or Service for better separation of concerns.
Enjoy building great experiences! 🚀