๐Ÿ“„ Documentation: IrbyImaging/Views/FieldOffices/Index.cshtml

Purpose: Renders a dynamic, filterable, and exportable table of Field Offices within the IrbyImaging application.


๐Ÿ“‘ Table of Contents

  1. Overview & Purpose
  2. Key Functional Areas
  3. Dependencies & Technologies
  4. View Model & Data Model
  5. Markup Structure
  6. Data Display & Iteration
  7. Actions & Routing
  8. Thirdโ€‘party Integrations
  9. Scripts & Initialization
  10. Sample Usage Example
  11. UML Component Diagram
  12. Conclusion

๐Ÿ” Overview & Purpose

The Index.cshtml view is responsible for displaying a comprehensive list of Field Offices in a tabular format. It:

  • ๐ŸŽจ Utilizes DataTables to provide sorting, paging, filtering, and export functionality.
  • ๐Ÿš€ Shows key details for each office (JDE number, contact, managers, address).
  • ๐Ÿ”— Offers quick navigation to Create, Details, and Update actions.

๐Ÿงฉ Key Functional Areas

Functional Area Description
Page Metadata Sets the Title and Layout via ViewData and _ATSLayout.cshtml.
Toolbar โ€œAdd New Field Officeโ€ button for creating new entries.
Data Table Table headers, rows populate from the IEnumerable<FieldOffice> model.
Action Links โ€œDetailsโ€ and โ€œUpdateโ€ buttons with icons.
DataTables Integration CSS/JS imports + initialization for export buttons (csv, excel, print).
Responsive Design Uses Bootstrap 4 grid classes (row, col-lg-2).

โš™๏ธ Dependencies & Technologies

  • ASP.NET Core MVC
  • Razor View Engine
  • jQuery 3.5.1
  • DataTables (+ Buttons extension)
  • Bootstrap 4
  • MetisMenu, SimpleBar, Waves (interface libs)

๐Ÿ’พ View Model & Data Model

Model Declaration

@model IEnumerable<IrbyImaging.DomainClasses.FieldOffice>

FieldOffice Domain Class (simplified)

Property Type Description
int Id int Primary key
string JdeNumber string Unique JDE office identifier
string Name string Field Office name
Employee Manager Employee Office Manager
Employee Lead Employee Office Lead
string OfficePhone string Contact phone number
string FaxNumber string Fax number
string MailingAddress string Postal address
... โ€ฆ Other related properties

๐Ÿ— Markup Structure

@{ 
  ViewData["Title"] = "Field Office List"; 
  Layout = "~/Views/Shared/_ATSLayout.cshtml"; 
}

<h2>
  Field Offices <span class="badge irby-blue">@Model.Count()</span>
</h2>

<div class="row">
  <div class="col-lg-2">
    <a asp-action="Create" class="btn btn-success irby-green">
      Add New Field Office
    </a>
  </div>
</div>

<table id="fieldOfficesDatatable" class="table table-striped table-bordered">
  <thead>โ€ฆ</thead>
  <tbody>
    @foreach (var item in Model) {
      <tr>
        <td>@item.JdeNumber</td>
        <td>@item.Name</td>
        โ€ฆ action links โ€ฆ
      </tr>
    }
  </tbody>
</table>
  • Layout & Title: Defined at the top.
  • Badge: Shows real-time count: @Model.Count().
  • Commented Code: A search form and local script references are commented out (@* ... *@).

๐Ÿ”„ Data Display & Iteration

  • Headers: Uses @Html.DisplayNameFor(model => model.Property) for localization/friendly names.
  • Rows: Loops @foreach (var item in Model) to render each Field Office.
  • Nested Links: Manager, Superintendent, ProjectManager, and Lead link to their respective details in EmployeesController.

๐Ÿ”— Actions & Routing

Action Razor Tag Helpers Generates URL
Create <a asp-action="Create"> /FieldOffices/Create
Details <a href="@Url.Action("Details","FieldOffices",new{id=item.Id})"> /FieldOffices/Details/{id}
Update/Edit <a href="@Url.Action("Edit","FieldOffices",new{id=item.Id})"> /FieldOffices/Edit/{id}
Employee Info <a asp-controller="Employees" asp-action="Details" asp-route-id="@item.ManagerId"> /Employees/Details/{employeeId}

๐ŸŒ Thirdโ€‘party Integrations

  1. DataTables.net
    • CSS:
      <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" />
      
    • JS:
      <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>
      <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>
      
  2. Bootstrap 4
  3. MetisMenu, SimpleBar, Waves (for sidebar & effects)

๐Ÿ“œ Scripts & Initialization

<script type="text/javascript">
  $(document).ready(function () {
    $('#fieldOfficesDatatable').DataTable({
      dom: 'Bfrtip',
      buttons: ['csv', 'excel', 'print']
    });
  });
</script>
  • Initializes DataTable on page load.
  • Enables CSV, Excel, and Print export buttons.

๐Ÿš€ Sample Usage Example

Controller Action (FieldOfficesController.cs)

public async Task<IActionResult> Index()
{
    var offices = await _context.FieldOffices
        .Include(f => f.Manager)
        .Include(f => f.Superintendent)
        .Include(f => f.ProjectManager)
        .Include(f => f.Lead)
        .ToListAsync();

    return View(offices);
}

Result: The Index view receives a list of FieldOffice objects and renders them in the DataTable.


๐Ÿงญ UML Component Diagram

flowchart LR
  A[Index.cshtml] -->|model binding| B[FieldOffice Domain Model]
  A -->|links to| C[FieldOfficesController]
  A -->|links to| D[EmployeesController]
  A -->|includes| E[jQuery & DataTables]
  A -->|styles| F[Bootstrap 4]

โœ… Conclusion

  • Index.cshtml offers a robust, interactive list of Field Offices.
  • It leverages Razor, ASP.NET Core MVC, and DataTables for a seamless user experience.
  • Extensible to include search filters, additional export formats, or inline editing with minimal changes.

Happy coding! ๐ŸŽ‰