📖 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Class Diagram (UML)
  4. Key Functional Areas
  5. Properties Reference
  6. Sample Code Blocks
  7. Usage Example
  8. Error Handling & Validation
  9. Third-Party Integrations
  10. Conclusion

🧐 Overview & Purpose

The SafetyEquipmentEditViewModel class is a specialized ViewModel used in the IrbyImaging.UI application to facilitate the creation and editing of Safety Equipment records. It inherits from a base EditViewModel and extends it with properties specific to safety equipment:

  • Selecting the Operating System/Size
  • Picking a Tested Date
  • Capturing various identification numbers (Asset, Unit, CPS)

This ViewModel is passed from an ASP.NET Core Controller to a Razor View, enabling strongly‑typed form rendering and model binding.


🛠️ Dependencies & Technologies

Dependency Purpose
Microsoft.AspNetCore.Mvc.Rendering SelectListItem for dropdown lists
System.ComponentModel.DataAnnotations Display attributes & data validation
IrbyImaging.Models.EditViewModel Base class for common edit features
ASP.NET Core MVC Web framework for controllers/views

📊 Class Diagram (UML)

@startuml
skinparam classAttributeIconSize 0

class EditViewModel {
  <<abstract>>
  +int Id
  +string Name
  +DateTimeOffset EffectiveDate
  +DateTimeOffset? ExpiryDate
}

class SafetyEquipmentEditViewModel {
  +int OperatingSystemId
  +IEnumerable<SelectListItem> OperatingSystemList
  +DateTimeOffset PurchaseDate
  +string AssetNumber
  +string UnitNumber
  +string CpsNumber
}

SafetyEquipmentEditViewModel --|> EditViewModel
@enduml

🔑 Key Functional Areas

  1. Inheritance
    • Inherits common fields from EditViewModel (e.g., Id, Name, dates).
  2. Operating System Selection
    • OperatingSystemId & OperatingSystemList enable dropdown selection.
  3. Date Handling
    • PurchaseDate (displayed as “Tested Date”) for safety checks.
  4. Asset Identification
    • AssetNumber, UnitNumber, CpsNumber capture JDE and CPS references.

📋 Properties Reference

Property Type Attributes Description
OperatingSystemId int [Display("Operating System/Size")] Selected OS/size ID from the dropdown.
OperatingSystemList IEnumerable – Collection of OS/Size options for dropdown.
PurchaseDate DateTimeOffset [Display("Tested Date")], [DataType(Date)] Date when equipment was tested.
AssetNumber string [Display("JDE Asset Number")] JDE asset tracking number.
UnitNumber string [Display("JDE Unit Number")] JDE unit tracking number.
CpsNumber string [Display("CPS Number")] CPS-specific equipment number.

Note: Some [Required] attributes are commented out for future reference—this model currently does not enforce required validation for safety equipment.


💻 Sample Code Blocks

Controller Usage

using IrbyImaging.Models;
using Microsoft.AspNetCore.Mvc;

public class SafetyEquipmentController : Controller
{
    public IActionResult Edit(int id)
    {
        // Fetch existing record or new instance
        var viewModel = new SafetyEquipmentEditViewModel
        {
            Id = id,
            Name = "Safety Vest",
            PurchaseDate = DateTimeOffset.Now,
            AssetNumber = "AS12345",
            UnitNumber = "UN67890",
            CpsNumber = "CPS0001"
        };

        // Populate the OperatingSystemList for dropdown
        viewModel.OperatingSystemList = GetOperatingSystems();
        return View(viewModel);
    }

    private IEnumerable<SelectListItem> GetOperatingSystems()
    {
        // This could come from a database or enum
        return new List<SelectListItem>
        {
            new SelectListItem("Small", "1"),
            new SelectListItem("Medium", "2"),
            new SelectListItem("Large", "3")
        };
    }
}

Razor View Usage

@model IrbyImaging.Models.SafetyEquipmentEditViewModel

<form asp-action="Edit">
  <div class="form-group">
    <label asp-for="OperatingSystemId"></label>
    <select asp-for="OperatingSystemId" asp-items="Model.OperatingSystemList" class="form-control">
      <option value="">-- Select Size --</option>
    </select>
  </div>

  <div class="form-group">
    <label asp-for="PurchaseDate"></label>
    <input asp-for="PurchaseDate" class="form-control" />
  </div>

  <div class="form-group">
    <label asp-for="AssetNumber"></label>
    <input asp-for="AssetNumber" class="form-control" />
  </div>

  <!-- UnitNumber & CpsNumber fields omitted for brevity -->
  <button type="submit" class="btn btn-primary">Save</button>
</form>

🏗️ Usage Example

  1. GET /SafetyEquipment/Edit/1
    • Controller initializes SafetyEquipmentEditViewModel with existing data.
  2. POST /SafetyEquipment/Edit/1
    • Model binder populates the ViewModel from form values.
    • Validate and persist changes in the database.

⚠️ Error Handling & Validation

  • Relies on DataAnnotations for basic UI hints.
  • Custom validation (e.g., required fields, business rules) should be implemented in the Controller or via [IValidatableObject].
  • No built‑in error handling: ensure to wrap database calls in try/catch and return ModelState errors to the view.

🔌 Third-Party Integrations

  • Microsoft.AspNetCore.Mvc.Rendering: Provides SelectListItem for dropdown lists.
  • DataAnnotations: Standard .NET library for metadata & validation.

🎯 Conclusion

The SafetyEquipmentEditViewModel is a streamlined, focused ViewModel that bridges your safety equipment domain data with the UI layer. By leveraging ASP.NET Core’s model binding and validation, it enables a clean, maintainable way to render form fields, capture user input, and apply simple validations. Implementing this pattern enhances testability and separates UI concerns from business logic.


Happy coding! 🛡️