πŸ›‘οΈ SafetyEquipmentCreateViewModel Documentation

Assembly: IrbyImaging.UI
Path: IrbyImaging/Models/SafetyEquipment/SafetyEquipmentCreateViewModel.cs
Author: kvamshi
Created On: 03‑31‑2022
Last Modified: 03‑31‑2022


πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Key Functional Areas
  4. Class Definition & UML Diagram
  5. Properties & Data Annotations
  6. Usage Scenarios & Examples
  7. Error Handling & Validation
  8. Third-Party Integrations
  9. Conclusion

1. Overview & Purpose

The SafetyEquipmentCreateViewModel class is part of the IrbyImaging web application’s UI layer. It serves as a strongly‑typed model for the β€œCreate Safety Equipment” page in an ASP.NET Core MVC application.

  • πŸ–₯️ Role: Capture user input when registering new safety equipment (e.g., fall protection, hard hats, etc.).
  • 🎯 Goal: Provide properties, display metadata, and select‑list data for rendering a user‑friendly form.

2. Dependencies & Technologies

Category Details
Framework ASP.NET Core MVC
Language C# (.NET 6+)
Data Annotations System.ComponentModel.DataAnnotations
Select List Rendering Microsoft.AspNetCore.Mvc.Rendering
Base Model CreateViewModel (common properties)

3. Key Functional Areas

  • Dropdown Population
    Holds an IEnumerable<SelectListItem> for operating systems/sizes.
  • Data Entry Fields
    Captures Tested Date, JDE Asset Number, JDE Unit Number, CPS Number.
  • Display Metadata
    Uses [Display(Name="…")] and [DataType(DataType.Date)] to render labels & date pickers.
  • Extensibility
    Inherits from CreateViewModel, reusing common Id, CreatedBy, CreatedDate, etc.

4. Class Definition & UML Diagram

namespace IrbyImaging.Models
{
    public class SafetyEquipmentCreateViewModel : CreateViewModel
    {
        [Display(Name = "Operating System/Size")]
        public int OperatingSystemId { get; set; }

        public IEnumerable<SelectListItem> OperatingSystemList { get; set; }

        [Display(Name = "Tested Date")]
        [DataType(DataType.Date)]
        public new DateTimeOffset PurchaseDate { get; set; }

        [Display(Name = "JDE Asset Number")]
        public string AssetNumber { get; set; }

        [Display(Name = "JDE Unit Number")]
        public string UnitNumber { get; set; }

        [Display(Name = "CPS Number")]
        public string CpsNumber { get; set; }
    }
}

UML Class Diagram

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚      CreateViewModel      β”‚
│───────────────────────────│
β”‚ + int Id                  β”‚
β”‚ + string CreatedBy        β”‚
β”‚ + DateTimeOffset Created β”‚
β”‚ + …                       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚ inherits
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ SafetyEquipmentCreateViewModel β”‚
│───────────────────────────│
β”‚ + int OperatingSystemId  β”‚
β”‚ + IEnumerable<SelectListItem> β”‚
β”‚     OperatingSystemList  β”‚
β”‚ + DateTimeOffset PurchaseDate β”‚
β”‚ + string AssetNumber     β”‚
β”‚ + string UnitNumber      β”‚
β”‚ + string CpsNumber       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

5. Properties & Data Annotations

Property Type Annotation(s) Description
OperatingSystemId int [Display(Name="Operating System/Size")] Selected OS/size identifier.
OperatingSystemList IEnumerable<SelectListItem> β€” Populates the OS dropdown.
PurchaseDate DateTimeOffset [Display(Name="Tested Date")]<br/>[DataType(Date)] Date the equipment was tested/purchased.
AssetNumber string [Display(Name="JDE Asset Number")] JDE asset tracking number.
UnitNumber string [Display(Name="JDE Unit Number")] JDE unit identifier.
CpsNumber string [Display(Name="CPS Number")] Company‑provided serial number.

Note: Some [Required] annotations are commented out for future needs.


6. Usage Scenarios & Examples

6.1 Controller Integration

public class SafetyEquipmentController : Controller
{
    private readonly IOperatingSystemService _osService;

    public SafetyEquipmentController(IOperatingSystemService osService)
    {
        _osService = osService;
    }

    // GET: /SafetyEquipment/Create
    public IActionResult Create()
    {
        var vm = new SafetyEquipmentCreateViewModel
        {
            OperatingSystemList = _osService.GetAll()
                .Select(os => new SelectListItem
                {
                    Value = os.Id.ToString(),
                    Text  = os.Name
                })
        };
        return View(vm);
    }

    // POST: /SafetyEquipment/Create
    [HttpPost]
    public IActionResult Create(SafetyEquipmentCreateViewModel model)
    {
        if (!ModelState.IsValid)
        {
            // Re-populate dropdown on error
            model.OperatingSystemList = _osService.GetAll()
                .Select(os => new SelectListItem
                {
                    Value = os.Id.ToString(),
                    Text  = os.Name
                });
            return View(model);
        }

        // Map to domain & save
        var entity = Mapper.Map<SafetyEquipment>(model);
        _equipmentService.Add(entity);
        return RedirectToAction("Index");
    }
}

6.2 Razor View Sample

@model IrbyImaging.Models.SafetyEquipmentCreateViewModel

<form asp-action="Create" method="post">
  <div class="form-group">
    <label asp-for="OperatingSystemId"></label>
    <select asp-for="OperatingSystemId" 
            asp-items="Model.OperatingSystemList" 
            class="form-control">
      <option value="">-- Select OS/Size --</option>
    </select>
    <span asp-validation-for="OperatingSystemId" class="text-danger"></span>
  </div>

  <div class="form-group">
    <label asp-for="PurchaseDate"></label>
    <input asp-for="PurchaseDate" class="form-control" type="date" />
    <span asp-validation-for="PurchaseDate" class="text-danger"></span>
  </div>

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

  <!-- Unit Number -->
  <div class="form-group">
    <label asp-for="UnitNumber"></label>
    <input asp-for="UnitNumber" class="form-control" />
  </div>

  <!-- CPS Number -->
  <div class="form-group">
    <label asp-for="CpsNumber"></label>
    <input asp-for="CpsNumber" class="form-control" />
  </div>

  <button type="submit" class="btn btn-primary">Create πŸ› οΈ</button>
</form>

7. Error Handling & Validation

  • Relies on DataAnnotations for client/server validation.
  • Invalid model states return the same view with validation messages.
  • Developer should re-populate dropdown lists on POST failures.

8. Third-Party Integrations

  • AutoMapper (optional) to map between SafetyEquipmentCreateViewModel and domain entity.
  • jQuery Validation & Unobtrusive Validation for client‑side form checks.

9. Conclusion

The SafetyEquipmentCreateViewModel provides a clean, metadata‑rich surface for collecting all necessary fields to register new safety equipment. By leveraging ASP.NET Core’s model binding and validation attributes, it ensures:

  • βœ… Strongly‑typed inputs in controllers & views
  • βœ… Automatic label rendering via [Display]
  • βœ… Dropdown generation through SelectListItem
  • βœ… Date formatting via [DataType(DataType.Date)]

This view model can be extended with additional properties (e.g., Location, Department) and further validation attributes as the requirements evolve.


Happy Coding! πŸš€