📚 Documentation for IrbyImaging/Models/WorkOrders.cs


📑 Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Key Functional Areas
  4. Data Model: WorkOrders Class
    1. UML Class Diagram
    2. Properties Reference
  5. Sample Code Blocks
  6. Usage Examples
  7. Potential Extensions & Best Practices
  8. Conclusion

1. Overview & Purpose

The WorkOrders class represents the core data model for handling work order information in the Irby Imaging UI. It is intended to:

  • 🗂️ Store metadata about each work order (IDs, status, dates, amounts, etc.).
  • 🔄 Facilitate data binding between the UI layer and business logic (e.g., with Entity Framework Core or any other ORM).
  • 📊 Enable easy serialization/deserialization when interacting with APIs, services, or front-end views.

2. Dependencies & Technologies

This model relies on:

  • .NET 6+ / .NET Core (C#)
  • System Namespace (for built‑in types like Guid, DateTime, Decimal)
  • System.ComponentModel.DataAnnotations.Schema (imported, for potential ORM mapping)
using System;
using System.ComponentModel.DataAnnotations.Schema;
namespace IrbyImaging.UI.Models
{
    public class WorkOrders { … }
}

🔑 Tip: You can decorate this class with attributes such as [Table("WorkOrders")] or configure mappings via Fluent API when using Entity Framework.


3. Key Functional Areas

  • Identity & Organization
    • WorkOrderId (GUID) – Unique identifier
    • Org_Bu, Org_IntDivision – Organizational grouping
  • Descriptive Fields
    • Name, DisplayName, WorkOrderNumber, DocType, WorkOrderType, Reference
  • Status & Tracking
    • Status, StatusComment
    • Dates: DateAssigned, DateStart, DateComplete
  • Financial & Time Estimates
    • EstimatedHours (decimal)
    • EstimatedAmount (decimal)
  • Relationships
    • JobId (GUID) – Links to the parent job
    • EquipmentId, ProjectManagerId – Optional GUIDs for related entities
    • JobNumber – Readable job reference

4. Data Model: WorkOrders Class

4.1 UML Class Diagram

classDiagram
    class WorkOrders {
        + Guid WorkOrderId
        + string Org_Bu
        + string Org_IntDivision
        + string Name
        + string DisplayName
        + string WorkOrderNumber
        + string DocType
        + string WorkOrderType
        + string Status
        + string Reference
        + decimal EstimatedHours
        + decimal EstimatedAmount
        + DateTime? DateAssigned
        + DateTime? DateStart
        + DateTime? DateComplete
        + string StatusComment
        + Guid JobId
        + Guid? EquipmentId
        + Guid? ProjectManagerId
        + string JobNumber
    }

4.2 Properties Reference

Property Type Description
WorkOrderId Guid Primary key for the work order.
Org_Bu string Business Unit identifier.
Org_IntDivision string Internal division within the organization.
Name string Internal name for the work order.
DisplayName string User‑friendly display name.
WorkOrderNumber string External or sequential work order identifier.
DocType string Document type (e.g., “Invoice”, “Ticket”).
WorkOrderType string Classification (e.g., “Installation”, “Repair”).
Status string Current state (e.g., “Open”, “In Progress”, “Completed”).
Reference string Arbitrary reference string for cross‑referencing.
EstimatedHours decimal Planned labor hours.
EstimatedAmount decimal Planned cost or budget amount.
DateAssigned DateTime? UTC date when assigned (nullable).
DateStart DateTime? UTC date work started (nullable).
DateComplete DateTime? UTC date work completed (nullable).
StatusComment string Notes or comments about the current status.
JobId Guid Foreign key to the parent job entity.
EquipmentId Guid? Optional foreign key to equipment.
ProjectManagerId Guid? Optional foreign key to the project manager (user).
JobNumber string Human‑readable job number.

5. Sample Code Blocks

5.1 Instantiation & Assignment

var wo = new WorkOrders
{
    WorkOrderId      = Guid.NewGuid(),
    Org_Bu           = "BU-1001",
    Org_IntDivision  = "DIV-A",
    Name             = "Upgrade Server Rack",
    DisplayName      = "Server Rack Upgrade – Site 12",
    WorkOrderNumber  = "WO-2024-0007",
    DocType          = "Installation",
    WorkOrderType    = "Hardware",
    Status           = "Open",
    Reference        = "PO-XYZ-12345",
    EstimatedHours   = 8.5m,
    EstimatedAmount  = 1250.00m,
    DateAssigned     = DateTime.UtcNow,
    JobId            = Guid.Parse("3f29cfea-5d66-4e4f-990a-1a2b3c4d5e6f"),
    JobNumber        = "JOB-2024-0062"
};

5.2 EF Core Fluent API Configuration

modelBuilder.Entity<WorkOrders>(entity =>
{
    entity.ToTable("WorkOrders");

    entity.HasKey(e => e.WorkOrderId);

    entity.Property(e => e.WorkOrderNumber)
          .HasMaxLength(50)
          .IsRequired();

    entity.Property(e => e.EstimatedAmount)
          .HasColumnType("decimal(18,2)");
    
    // Relationships
    entity.HasOne<Job>()
          .WithMany(j => j.WorkOrders)
          .HasForeignKey(e => e.JobId);
});

6. Usage Examples

  1. Displaying in a Razor View
    @model IEnumerable<IrbyImaging.UI.Models.WorkOrders>
    <table>
      <thead><tr><th>WO #</th><th>Name</th><th>Status</th><th>ETA</th></tr></thead>
      <tbody>
        @foreach(var wo in Model) {
          <tr>
            <td>@wo.WorkOrderNumber</td>
            <td>@wo.DisplayName</td>
            <td>@wo.Status</td>
            <td>@wo.DateStart?.ToShortDateString()</td>
          </tr>
        }
      </tbody>
    </table>
    
  2. Serializing to JSON
    string json = JsonSerializer.Serialize(wo, new JsonSerializerOptions 
    { 
      PropertyNamingPolicy = JsonNamingPolicy.CamelCase 
    });
    Console.WriteLine(json);
    

7. Potential Extensions & Best Practices

  • 🔧 Data Annotations: Add [Required], [MaxLength(100)] to enforce validation.
  • 🔄 Mapping DTOs: Use AutoMapper profiles to map between this model and API contracts or view‑specific DTOs.
  • 📅 Timezone Handling: Consider storing/returning all dates in UTC and converting in the UI.
  • 🛡️ Error Handling: Wrap date parsing and GUID conversions in try/catch when accepting user input.
  • 📈 Tracking Audits: Extend with CreatedBy, CreatedOn, ModifiedBy, ModifiedOn properties for audit logging.

8. Conclusion

The WorkOrders model is a versatile and extensible container for capturing all relevant details of a work order in the Irby Imaging system. It serves as the backbone for data transfer between the database, business logic, and UI layers. By enriching it with data annotations, Fluent API mappings, and DTOs, you can:

  • Ensure data integrity
  • Simplify serialization for APIs
  • Facilitate clean separation of concerns in your application

🚀 Ready to ramp up your work‑order management? Start by integrating this model into your DbContext, scaffold your controllers, and build intuitive UI pages!