πŸ“„ ViewCrews.cshtml Documentation


Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Model & Data Structures
  4. Layout & Razor Structure
  5. Key Functional Areas
    5.1. Search Section πŸ”
    5.2. Result Grid Section πŸ“Š
    5.3. Create New Crew πŸš€
    5.4. Actions Template βœοΈπŸ—‘οΈ
    5.5. Delete Confirmation Modal ❗
    5.6. Anti-Forgery Token πŸ”’
  6. JavaScript Functionality 🧩
    6.1. Initialization
    6.2. Search & Clear Handlers
    6.3. Create Crew Redirect
    6.4. Edit Crew
    6.5. Delete Crew Workflow
  7. Styling & Responsive Design 🎨
  8. API Endpoints Overview 🌐
  9. Sample Code Blocks
  10. Usage Flow Example
  11. UML Sequence Diagram
  12. Conclusion & Next Steps βœ…

1. Overview & Purpose

ViewCrews.cshtml is an ASP.NET Core Razor View responsible for displaying, searching, and managing Crews within the Field Log module. It provides:

  • A search form to filter crews by name/creator.
  • A Syncfusion EJ2 Grid to display crew records.
  • Actions for creating, editing, and deleting crews.
  • Smooth AJAX-based interactions for real-time updates without full page reloads.

2. Dependencies & Technologies

Category Details
Frontend Framework ASP.NET Core Razor Views
CSS Libraries Syncfusion EJ2 (material.css, fluent.css), Bootstrap 5
JavaScript Library Syncfusion EJ2 (ej2.min.js, ejs.interop.min.js), Fetch API
Server-Side Helpers @Html.AntiForgeryToken(), Json.Serialize(...)
Layout _TimeLayout.cshtml (Shared layout for time entry pages)
Modal Dialogs Bootstrap 5 Modals

3. Model & Data Structures

@model IEnumerable<IrbyImaging.UI.Models.CrewListItemViewModel>

CrewListItemViewModel (example):

Property Type Description
CrewId Guid Unique identifier of the crew
CrewName string Name of the crew
CreatedBy string User who created the crew
CreatedAt DateTime Timestamp when created (optional)

4. Layout & Razor Structure

@{
    ViewData["Title"] = "View Crews";
    Layout = "~/Views/Shared/_TimeLayout.cshtml";
}
<head> ... <!-- Syncfusion & CSS links --> </head>
<div class="container-fluid"> ... </div>
@Html.AntiForgeryToken()
<script> ... </script>
<style> ... </style>
  • ViewData["Title"] sets the page title.
  • Layout points to a shared layout for consistent look-and-feel.
  • Syncfusion CSS/JS loaded via CDN for grid and controls.
  • Inline scripts and styles handle UI logic and responsive design.

5. Key Functional Areas

5.1. Search Section

<div id="searchForm" class="row uniform-row">
  <div class="col-md-4">
    <label>Crew Name</label>
    <ejs-textbox id="crewName" placeholder="Enter Crew Name"></ejs-textbox>
  </div>
  <div class="col-md-4">
    <label>Created By</label>
    <ejs-textbox id="createdBy" placeholder="Enter Creator Name"></ejs-textbox>
  </div>
  <div class="col-md-4 button-group">
    <ejs-button id="searchBtn" content="Search" isPrimary="true"></ejs-button>
    <ejs-button id="clearBtn" content="Clear"></ejs-button>
  </div>
</div>
  • TextBoxes (ejs-textbox) for filtering by Crew Name and Created By.
  • Search and Clear buttons trigger AJAX filtering and reset.

5.2. Result Grid Section

<ejs-grid id="CrewGrid"
  allowPaging="true"
  allowSorting="true"
  allowFiltering="true"
  allowResizing="true"
  allowExcelExport="true"
  gridLines="Both"
  height="450">
  <e-grid-pagesettings pageSize="10"></e-grid-pagesettings>
  <e-grid-filterSettings type="Excel"></e-grid-filterSettings>
  <e-grid-columns>
    <e-grid-column field="CrewName" headerText="Crew Name" width="200"></e-grid-column>
    <e-grid-column field="CreatedBy" headerText="Created By" width="200"></e-grid-column>
    <e-grid-column headerText="Actions" template="#actionTemplate" width="150"></e-grid-column>
  </e-grid-columns>
</ejs-grid>
  • Paging, Sorting, Filtering, Resizing, Excel Export enabled.
  • Three columns: Crew Name, Created By, and Actions.

5.3. Create New Crew

<ejs-button id="createBtn" content="Create New Crew" isPrimary="true"></ejs-button>
  • On click, redirects to /TimeEntry/CreateCrew.

5.4. Actions Template

<script id="actionTemplate" type="text/x-template">
  <div class="action-buttons">
    <a href="#" class="edit-link" data-id="${CrewId}">Edit</a>
    <a href="#" class="delete-link" data-id="${CrewId}" data-name="${CrewName}">Delete</a>
  </div>
</script>
  • Edit: Opens /TimeEntry/EditCrew/{CrewId} in a new tab.
  • Delete: Opens confirmation modal.

5.5. Delete Confirmation Modal

<div class="modal fade" id="deleteConfirmModal" ...>
  <div class="modal-content">
    <div class="modal-header">
      <h5>Confirm Delete</h5>
      <button class="btn-close" data-bs-dismiss="modal"></button>
    </div>
    <div class="modal-body">
      Are you sure you want to delete: <span id="crewToDelete"></span>?
    </div>
    <div class="modal-footer">
      <button data-bs-dismiss="modal">Cancel</button>
      <button id="confirmDeleteBtn" class="btn btn-danger">Delete</button>
    </div>
  </div>
</div>
  • Shows selected <CrewName> and confirms deletion.

5.6. Anti-Forgery Token

@Html.AntiForgeryToken()
  • Protects POST requests against CSRF attacks.
  • Token is read in JavaScript and sent via RequestVerificationToken header.

6. JavaScript Functionality

6.1. Initialization

document.addEventListener('DOMContentLoaded', function() {
  const initialData = @Html.Raw(Json.Serialize(Model));
  const gridInstance = document.getElementById('CrewGrid').ej2_instances[0];
  gridInstance.dataSource = initialData;
  gridInstance.refresh();
  // Wire up buttons and links...
});
  • Parses server-side model into JSON.
  • Sets up grid, search, clear, create, edit, delete handlers.

6.2. Search & Clear Handlers

function performSearch() {
  const params = new URLSearchParams({
    crewName: getComponentValue('crewName'),
    createdBy: getComponentValue('createdBy')
  });
  fetch(`/TimeEntry/ViewCrews?${params}`, { headers: {'X-Requested-With':'XMLHttpRequest'} })
    .then(r => r.json())
    .then(data => { gridInstance.dataSource = data; gridInstance.refresh(); })
    .catch(err => alert('Search error'));
}

function clearForm() {
  ['crewName','createdBy'].forEach(id => getComponentInstance(id).value = null);
  gridInstance.dataSource = initialData;
  gridInstance.refresh();
}
  • performSearch(): GETs filtered data as JSON and reloads grid.
  • clearForm(): Resets inputs & restores initial grid data.

6.3. Create Crew Redirect

createBtnInstance.element.addEventListener('click', () => {
  window.location.href = '/TimeEntry/CreateCrew';
});
  • Redirects user to crew creation page.

6.4. Edit Crew

document.body.addEventListener('click', e => {
  if (e.target.classList.contains('edit-link')) {
    e.preventDefault();
    window.open(`/TimeEntry/EditCrew/${e.target.dataset.id}`, '_blank');
  }
});
  • Opens the Edit Crew form in a new tab/window.

6.5. Delete Crew Workflow

function deleteCrew(id, name) {
  crewIdToDelete = id;
  document.getElementById('crewToDelete').textContent = name;
  new bootstrap.Modal('#deleteConfirmModal').show();
}

confirmDeleteBtn.addEventListener('click', () => {
  fetch('/TimeEntry/DeleteCrew', {
    method: 'POST',
    headers: {
      'Content-Type':'application/json',
      'RequestVerificationToken': token
    },
    body: JSON.stringify({ crewId: crewIdToDelete })
  })
  .then(r => r.json())
  .then(data => {
    if (data.success) {
      // Remove row from grid
      gridInstance.dataSource = gridInstance.dataSource.filter(c => c.CrewId !== crewIdToDelete);
      gridInstance.refresh();
      alert('Crew deleted successfully.');
    } else {
      alert(data.message || 'Delete failed.');
    }
  })
  .catch(() => alert('An error occurred.'))
  .finally(() => crewIdToDelete = null);
});
  • deleteCrew(): Prepares and shows confirmation modal.
  • confirmDeleteBtn: Sends AJAX POST, updates grid on success.

7. Styling & Responsive Design 🎨

  • Custom CSS to match corporate branding (#11467e primary color).
  • Overrides Syncfusion grid styling for precise column widths, ellipses, alternate rows.
  • Media queries ensure usability on tablets and phones (column percentages, padding adjustments).

8. API Endpoints Overview 🌐

Endpoint Method Description Request Response
/TimeEntry/ViewCrews GET Filters crews by query params, returns JSON ?crewName=&createdBy= List<CrewListItem>
/TimeEntry/DeleteCrew POST Deletes a crew by ID, requires CSRF token { crewId: "..." }, header token { success: bool, message?: string }
/TimeEntry/CreateCrew GET/POST Renders or submits new crew form β€” HTML / JSON response
/TimeEntry/EditCrew/{id} GET/POST Renders or updates existing crew form β€” HTML / JSON response

9. Sample Code Blocks

Razor Model Declaration

@model IEnumerable<IrbyImaging.UI.Models.CrewListItemViewModel>

Grid Column Definition

<e-grid-column field="CrewName" headerText="Crew Name" width="200"></e-grid-column>
<e-grid-column field="CreatedBy" headerText="Created By" width="200"></e-grid-column>
<e-grid-column headerText="Actions" template="#actionTemplate" width="150"></e-grid-column>

AJAX Delete Request

fetch('/TimeEntry/DeleteCrew', {
  method: 'POST',
  headers: {
    'Content-Type':'application/json',
    'RequestVerificationToken': token
  },
  body: JSON.stringify({ crewId: crewIdToDelete })
})

10. Usage Flow Example

  1. Load Page: Grid populates with all crews.
  2. Search: Enter criteria β†’ click Search β†’ grid filters results.
  3. Clear: Click Clear β†’ inputs reset β†’ grid restores all data.
  4. Create: Click Create New Crew β†’ navigates to creation form.
  5. Edit: Click Edit on a row β†’ opens edit form in new tab.
  6. Delete: Click Delete β†’ confirm modal β†’ deletion via AJAX β†’ grid refresh.

11. UML Sequence Diagram

sequenceDiagram
  participant U as User
  participant B as Browser/JS
  participant S as Server
  participant G as Syncfusion Grid

  U->>B: Click "Delete" link
  B->>B: Show confirmation modal
  U->>B: Click "Delete" in modal
  B->>S: POST /TimeEntry/DeleteCrew { crewId }
  S-->>B: { success: true }
  B->>G: Remove row & refresh
  B->>U: Alert "Crew deleted successfully."

12. Conclusion & Next Steps βœ…

This documentation covers the ViewCrews.cshtml view in detail. You now understand:

  • How the Razor view is structured.
  • Integration with Syncfusion EJ2 components.
  • AJAX workflows for search, create, edit, and delete.
  • Responsive styling and corporate theming.

Next Steps:

  • Implement server-side methods (ViewCrews, DeleteCrew).
  • Ensure anti-forgery token validation on POST.
  • Expand error handling and user-friendly notifications (toasts).
  • Add unit/integration tests for AJAX endpoints.

πŸš€ You’re now ready to maintain and extend the β€œView Crews” feature!