📄 CrewListItemViewModel Documentation


Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Key Functional Areas
  4. Class Definition & Properties
  5. UML Class Diagram
  6. Sample Code Blocks & Usage Examples
  7. Mapping from Domain Models
  8. Error Handling & Return Types
  9. Third‑Party Integrations
  10. Conclusion

Overview & Purpose

The CrewListItemViewModel class is part of the IrbyImaging.UI.Models namespace. It serves as a simple View Model within the UI layer to represent a single crew item in lists, tables, or dropdowns. Its main role is to transport minimal, strictly UI‑focused data from server-side controllers to Razor/Blazor views or any front-end binding:

  • 🆔 CrewId: Unique identifier for the crew
  • 🏷️ CrewName: Display name of the crew
  • 👤 CreatedBy: Username or identifier of who created the crew
  • 🔗 JobId: Link back to the related job

This helps decouple UI concerns from deeper domain models and optimizes data transfer.


Dependencies & Technologies

Category Details
Language C# (8.0+)
Platform .NET Core / .NET 5+ (any implementation supporting System.Guid)
Namespace IrbyImaging.UI.Models
External Packages None
Build System MSBuild / dotnet CLI

Key Functional Areas

  1. Data Transport
    • Carry read-only or read/write data for UI rendering
  2. Mapping
    • Can be populated manually or via AutoMapper from domain/entity models
  3. Lightweight
    • Contains only the fields necessary for list display

Class Definition & Properties

using System;

namespace IrbyImaging.UI.Models
{
    /// <summary>
    /// ViewModel representing a single crew item in a UI list.
    /// </summary>
    public class CrewListItemViewModel
    {
        /// <summary>
        /// Unique identifier of the crew.
        /// </summary>
        public Guid CrewId { get; set; }

        /// <summary>
        /// Display name of the crew.
        /// </summary>
        public string CrewName { get; set; }

        /// <summary>
        /// Identifier or username of the user who created the crew.
        /// </summary>
        public string CreatedBy { get; set; }

        /// <summary>
        /// Related Job's unique identifier.
        /// </summary>
        public Guid JobId { get; set; }
    }
}

Property Summary

Property Type Description
CrewId Guid Globally unique ID of the crew
CrewName string Name used to display the crew in UI
CreatedBy string User who created the crew entry
JobId Guid ID of the associated job (foreign relationship)

UML Class Diagram

Below is a simple UML representation.

@startuml
class CrewListItemViewModel {
  + Guid CrewId
  + string CrewName
  + string CreatedBy
  + Guid JobId
}
@enduml

UML Diagram


Sample Code Blocks & Usage Examples

Instantiation & Basic Usage

// Create a new view model instance in your controller or service:
var item = new CrewListItemViewModel
{
    CrewId   = Guid.NewGuid(),
    CrewName = "Alpha Team",
    CreatedBy= "jdoe",
    JobId    = new Guid("b891c11f-6f2a-4dda-8a30-2e9e3c034df1")
};

// Pass to a Razor view:
return View("CrewList", model: new List<CrewListItemViewModel> { item });

Razor Example

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

<table class="table">
    <thead>
        <tr>
            <th>Crew Name</th>
            <th>Created By</th>
            <th>Actions</th>
        </tr>
    </thead>
    <tbody>
    @foreach (var crew in Model)
    {
        <tr>
            <td>@crew.CrewName</td>
            <td>@crew.CreatedBy</td>
            <td>
                <a asp-action="Details" asp-route-id="@crew.CrewId">🔍 View</a>
            </td>
        </tr>
    }
    </tbody>
</table>

Mapping from Domain Models

Often, you’ll have a domain entity, e.g., Crew, that you want to project into this view model. You can do this:

// Manual mapping
public CrewListItemViewModel Map(Crew domain) => new CrewListItemViewModel
{
    CrewId    = domain.Id,
    CrewName  = domain.Name,
    CreatedBy = domain.CreatedByUsername,
    JobId     = domain.Job.Id
};

// AutoMapper configuration
CreateMap<Crew, CrewListItemViewModel>()
    .ForMember(dest => dest.CrewName,  opt => opt.MapFrom(src => src.Name))
    .ForMember(dest => dest.CreatedBy, opt => opt.MapFrom(src => src.CreatedByUsername))
    .ForMember(dest => dest.JobId,     opt => opt.MapFrom(src => src.Job.Id));

Error Handling & Return Types

  • This class is a simple data container; it does not implement any validation or error handling.
  • Any null/empty checks should be performed at service or controller layers before populating/consuming instances.

Third‑Party Integrations

  • No direct third‑party dependencies.
  • Commonly paired with:
    • AutoMapper: For object-to-object mapping
    • Swagger / NSwag: If exposed via an API
    • Blazor / Razor Pages: For UI binding

Conclusion

CrewListItemViewModel is a lightweight, focused class intended to streamline the presentation of crew information in list-like UI components. By separating view concerns from domain entities, it enhances maintainability and performance in the IrbyImaging application’s UI layer.

Feel free to extend it as needed—for example, to add display formatting helpers or additional metadata (icons, statuses, etc.) for richer UI experiences! 🎉


End of Documentation for CrewListItemViewModel.cs