πŸ“„ Documentation: IrbyImaging/Views/CarrierType/Index.cshtml


πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Key Functional Areas
  3. Dependencies & Technologies
  4. View Models & Data Models
  5. UI Composition & Razor Elements
  6. Helper Methods & Utilities
  7. Error Handling & Return Types
  8. API Endpoints Overview
  9. Third-party Integrations
  10. Sample Code Blocks
  11. Usage Examples
  12. UML Sequence Diagram
  13. Conclusion

πŸ” 1. Overview & Purpose

File: IrbyImaging/Views/CarrierType/Index.cshtml
Responsibility:
This Razor View renders the Carrier Type List in a tabular format, complete with DataTables features (sorting, filtering, export). It’s part of the ASP.NET Core MVC presentation layer for managing carrier types (e.g., shipping carriers).

Goal: Display existing carrier types, allow creation of new ones, and provide Update/Delete actions in an interactive table.


πŸ›  2. Key Functional Areas

Section Description
Page Setup & Metadata Sets ViewData["Title"] and specifies the shared layout (_ATSLayout.cshtml).
Header & Badge Displays the title β€œCarriers” with a dynamic badge showing the total count.
Action Buttons β€œAdd New Carrier” button wired to the Create action.
DataTable Markup Renders an HTML <table> with columns: Name, Available?, Update, Delete.
DataTable Initialization Uses JavaScript to convert plain table into a DataTable with export buttons.

πŸ”Œ 3. Dependencies & Technologies

Type Library / Framework Usage
ASP.NET Core MVC Razor Pages / Views Page templating, HTML helpers
jQuery https://code.jquery.com/jquery-3.5.1.js DOM manipulation, plugin bootstrapping
DataTables CSS Bootstrap 4, DataTables CDN Table styling
DataTables JS Buttons, JSZip, PDFMake Export functionalities
CSS dataTables.bootstrap4.min.css, buttons.dataTables.min.css Responsive & Buttons UI

πŸ—‚ 4. View Models & Data Models

// Model bound to this view:
@model IrbyImaging.DomainClasses.CarrierType

// Inside DomainClasses.CarrierType (simplified):
public class CarrierType
{
    public IEnumerable<CarrierTypeDetail> CarriersTypeDetail { get; set; }
}

public class CarrierTypeDetail
{
    public int Id { get; set; }
    public string Carrier { get; set; }
    public bool IsInactive { get; set; } // true = active, false = inactive
}
Property Type Description
CarriersTypeDetail IEnumerable<CarrierTypeDetail> Collection of carrier records to list.
Carrier string Name of the carrier.
IsInactive bool Availability flag (βœ… active, ❌ inactive).

πŸ–Ό 5. UI Composition & Razor Elements

  1. Layout & Title

    @{ 
      ViewData["Title"] = "Carrier Type List"; 
      Layout = "~/Views/Shared/_ATSLayout.cshtml"; 
    }
    
  2. Header & Badge

    <h2>Carriers <span class="badge irby-red">
        @Model.CarriersTypeDetail.Count()
    </span></h2>
    
  3. β€œAdd New Carrier” Button

    <a asp-action="Create" class="btn-sm btn-success irby-green">
      Add New Carrier
    </a>
    
  4. DataTable Markup

    <table id="assetDatatable" class="table table-striped table-bordered ...">
      <thead>
        <tr>
          <th>Name</th>
          <th>Available?</th>
          <th>Update</th>
          <th>Delete</th>
        </tr>
      </thead>
      <tbody>
        @foreach (var item in Model.CarriersTypeDetail) {
          <tr>
            <td>@Html.DisplayFor(m => item.Carrier)</td>
            <td>@(item.IsInactive ? "βœ…" : "❌")</td>
            <td>
              <a href="@Url.Action("Edit","CarrierModels", new { id=item.Id })" class="btn-sm btn-warning">
                Update <img src="~/update.png" alt="Edit" style="width:23px"/>
              </a>
            </td>
            <td>
              <a href="@Url.Action("Edit","CarrierModels", new { id=item.Id })" class="btn-sm btn-danger">
                Delete <img src="~/delete.png" alt="Delete" style="width:23px"/>
              </a>
            </td>
          </tr>
        }
      </tbody>
    </table>
    

πŸ”§ 6. Helper Methods & Utilities

  • Html.DisplayFor
    Renders a model property (e.g., item.Carrier) with the correct HTML encoding.

  • Url.Action
    Generates a URL to the Edit action in CarrierModelsController.

  • asp-action
    Tag helper for linking to the Create action.


⚠️ 7. Error Handling & Return Types

  • This view does not implement explicit error-handling logic.
  • In case Model.CarriersTypeDetail is null, the foreach will throw an exceptionβ€”ensure the controller populates the model.
  • The view returns HTML content to the browser.

πŸš€ 8. API Endpoints Overview

Button / Link Controller Action Route Example
Add New Carrier CarrierType Create /CarrierType/Create
Update (per row) CarrierModels Edit /CarrierModels/Edit/{id}
Delete (per row) CarrierModels Edit /CarrierModels/Edit/{id}

Note: Delete is wired to Editβ€”likely an oversight. A proper Delete action endpoint should be implemented.


πŸ”Œ 9. Third-party Integrations

  • DataTables.net

    • Features: sorting, search, pagination, export buttons (CSV, Excel, Print).
    • CSS & JS loaded via CDN.
  • JSZip & PDFMake

    • Enable on-the-fly generation of zip/excel/pdf when exporting table data.

πŸ“„ 10. Sample Code Blocks

DataTables Initialization

@section Scripts {
  <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>

  <script>
    $(document).ready(function() {
      $('#assetDatatable').DataTable({
        dom: 'Bfrtip',
        buttons: ['csv', 'excel', 'print']
      });
    });
  </script>
}

🎯 11. Usage Examples

  1. Navigate to the Index:
    https://yourapp.com/CarrierType/Index
    
  2. Add a New Carrier:
    • Click Add New Carrier β†’ Fill out the form β†’ Submit.
  3. Edit/Delete a Carrier:
    • Use the Update or Delete buttons in each row.

πŸ“Š 12. UML Sequence Diagram

sequenceDiagram
  participant Browser
  participant Controller as CarrierTypeController
  participant View
  participant DataTables

  Browser->>Controller: GET /CarrierType/Index
  Controller->>View: return View(model)
  View->>Browser: HTML + JS (DataTable)
  Browser->>DataTables: initialize('#assetDatatable')
  DataTables->>Browser: Enhanced table UI

🏁 13. Conclusion

This Index.cshtml view is a central piece for managing carrier types in the IrbyImaging application.

  • It leverages Razor for dynamic server-side rendering.
  • It integrates DataTables for a rich, interactive table with export features.
  • It relies on simple ASP.NET Core helpers (Html.DisplayFor, Url.Action) to wire up CRUD functionality.

By following this documentation, developers can extend, maintain, and troubleshoot the Carrier Type List page with confidence. πŸš€