πŸ“„ Documentation: CostCodeUpload.cshtml


πŸ“‘ Table of Contents

  1. 🎯 Overview & Purpose
  2. πŸ”‘ Key Functional Areas
  3. πŸ”§ Dependencies & Technologies
  4. πŸ“¦ Models & ViewModels
  5. πŸ–Ό UI Layout & Structure
  6. πŸ“ Forms & Data Binding
  7. πŸ’» Client-Side Logic & Helpers
  8. 🚨 Error Handling & Validation
  9. πŸ”— Third-Party Integrations
  10. πŸ’‘ Sample Usage & Code Snippets
  11. πŸ“ˆ UML Sequence Diagram
  12. βœ… Conclusion

🎯 Overview & Purpose

CostCodeUpload.cshtml is an ASP.NET Core Razor View that enables users to upload and submit new cost codes associated with mechanic timesheets. It provides:

  • A form to enter Cost Code and Cost Code Name
  • A Syncfusion ComboBox to select a Current Job from a dynamic list
  • A Bootstrap Modal for Preview & Confirmation before final submission

This page is part of the TimeEntry workflow in the IrbyImaging application, specifically under FringeBenefits.


πŸ”‘ Key Functional Areas

Section Description
Header & Layout Sets the page title and uses the _TimeLayout.cshtml master layout.
Styles & Scripts Includes CSS/JS for Syncfusion, Bootstrap, DataTables, jQuery, etc.
Cost Code Form Inputs for Cost Code, Cost Code Name, and Job selection.
Confirmation Modal Preview of entered data with Ok / Cancel controls.
Client-Side Validation Ensures all fields are filled before showing the modal.
Form Submission Posts data to TimeEntryController.CostCodeUpload via HTTP POST after confirmation.

πŸ”§ Dependencies & Technologies

Category Library / Framework Purpose
ASP.NET Core MVC Razor Views (.cshtml) Server-side rendering & binding
Styling Bootstrap 4 Layout, grid, modal
UI Components Syncfusion EJ2 (ComboBox) Rich dropdown with filtering
DataTables DataTables.net (JS + CSS) (Not used directly here but available)
JavaScript Library jQuery 3.6 DOM manipulation & event handling
Modal Bootstrap Modal Preview & confirmation UI
JSON Serialization Newtonsoft.Json (Available for server-side needs)

πŸ“¦ Models & ViewModels

@model IrbyImaging.DomainClasses.MechanicTimesheet
  • Model: MechanicTimesheetβ€”the domain class backing the view; though only cost code fields are used here
  • ViewBag: ViewBag.Jobsβ€”a list of { Text, Value } pairs used as the data source for the Syncfusion ComboBox

πŸ–Ό UI Layout & Structure

@{ 
    ViewData["Title"] = "Cost Code Upload";  
    Layout = "~/Views/Shared/_TimeLayout.cshtml"; 
}
<h2>Cost Code Upload</h2>
  • Layout: Sections of header, sidebar, footer are inherited from _TimeLayout.cshtml
  • Title: Dynamically set to β€œCost Code Upload”

Grid Structure

<div class="card">
  <div class="card-body">
    <div class="row">
      <!-- Left Column: Cost Code -->
      <div class="col-lg-2"> … </div>
      <!-- Right Column: Cost Code Name -->
      <div class="col-lg-2"> … </div>
    </div>
    <div class="row mt-2">
      <!-- Job ComboBox -->
      <div class="col-lg-4"> … </div>
    </div>
    <div class="row mt-2">
      <!-- Submit Button -->
      <div class="col"> … </div>
    </div>
  </div>
</div>
  • Uses Bootstrap grid for responsive two-column input layout and full-width button

πŸ“ Forms & Data Binding

<form asp-action="CostCodeUpload" asp-controller="TimeEntry" method="post">
  @Html.AntiForgeryToken()

  <!-- Cost Code Field -->
  <input type="number" id="costCode" name="costCode" required />

  <!-- Cost Code Name Field -->
  <input type="text" id="costCodeName" name="costCodeName" required />

  <!-- Syncfusion ComboBox for Job Selection -->
  <ejs-combobox
    id="jobCombo"
    dataSource="@(ViewBag.Jobs)"
    placeholder="Select a job"
    popupHeight="330px"
    allowFiltering="true"
    filterType="Contains"
    change="valueChange">
    <e-combobox-fields text="Text" value="Value"></e-combobox-fields>
  </ejs-combobox>
  <input type="hidden" id="jobId" name="jobId" required />

  <!-- Preview Button (manual click triggers modal) -->
  <button type="button" id="previewButton" class="btn btn-primary">
    Submit
  </button>
</form>
  • Anti-forgery token for CSRF protection
  • Hidden jobId field updated via Syncfusion change event

πŸ’» Client-Side Logic & Helpers

$(document).ready(function () {
  // 1️⃣ Preview Button Click
  $('#previewButton').click(function() {
    if (!validateForm()) {
      alert('Please fill in all required fields…');
      return;
    }
    // Populate Modal
    $('#modalCostCode').text($('#costCode').val());
    $('#modalCostCodeName').text($('#costCodeName').val());
    var combo = document.getElementById('jobCombo').ej2_instances[0];
    $('#modalJob').text(combo.text);
    // Show Bootstrap Modal
    new bootstrap.Modal($('#confirmationModal')).show();
  });

  // 2️⃣ Confirm & Submit
  $('#confirmSubmit').click(function() {
    $('form').submit();
  });

  // Validation Helper
  function validateForm() {
    return $('#costCode').val() && $('#costCodeName').val() && $('#jobId').val();
  }
});

// Syncfusion ComboBox Change Event
function valueChange() {
  var combo = document.getElementById('jobCombo').ej2_instances[0];
  document.getElementById('jobId').value = combo.value;
}
  • validateForm(): Ensures Cost Code, Name, and Job are selected
  • valueChange(): Binds ComboBox selection to the hidden jobId input

🚨 Error Handling & Validation

  1. HTML required attributes on inputs
  2. JavaScript validateForm(): alerts if any field is empty
  3. Anti-forgery token to prevent CSRF
  4. Server-side (controller) should re-validate fields before persisting

πŸ”— Third-Party Integrations

  • Syncfusion EJ2
    • ComboBox: rich dropdown with built-in filtering, templating
  • Bootstrap
    • Modal, grid system, buttons
  • DataTables & Dropzone
    • Included but not actively used in this view (future extension)

πŸ’‘ Sample Usage & Code Snippets

1. Posting from Controller

[HttpPost]
[ValidateAntiForgeryToken]
public IActionResult CostCodeUpload(int costCode, string costCodeName, int jobId) {
    // 1. Validate inputs
    if (jobId <= 0) { ModelState.AddModelError("", "JobId is required."); }

    if (!ModelState.IsValid) {
        // Reload ViewBag.Jobs & return view
    }

    // 2. Save to database (e.g. MechanicTimesheet)
    _db.MechanicTimesheets.Add(new MechanicTimesheet { 
        CostCode = costCode, 
        CostCodeName = costCodeName, 
        JobId = jobId 
    });
    _db.SaveChanges();

    // 3. Redirect or display success
    return RedirectToAction("Index");
}

2. Populating ViewBag.Jobs

var jobs = _db.Jobs
  .Select(j => new { Text = j.Name, Value = j.Id })
  .ToList();
ViewBag.Jobs = jobs;
return View();

πŸ“ˆ UML Sequence Diagram

sequenceDiagram
  participant U as User
  participant V as CostCodeUpload View
  participant C as TimeEntryController

  U->>V: Fill Cost Code & Name
  U->>V: Select Job (Syncfusion ComboBox)
  U->>V: Click "Submit"
  V->>V: validateForm()
  V->>V: Show Confirmation Modal
  U->>V: Click "Ok"
  V->>C: HTTP POST /TimeEntry/CostCodeUpload
  C-->>V: Return Redirect or View

βœ… Conclusion

The CostCodeUpload.cshtml view provides a user-friendly, interactive interface for adding cost codes to mechanic timesheets. Leveraging Syncfusion for rich UI controls and Bootstrap for responsive layout, it guides users through:

  1. Entering cost code details
  2. Previewing their entries
  3. Confirming before submission

This pattern enhances data accuracy and reduces input errors. By following the documented patterns, you can extend or maintain this pageβ€”adding further validation, custom styling, or new fieldsβ€”while keeping consistency across the IrbyImaging application.