🏷️ WorkOrder.cs Documentation

Welcome to the detailed documentation for WorkOrder.cs, a core domain class in the IrbyImaging.DomainClasses namespace. This file defines the WorkOrder entity used by Entity Framework to map work order data to the database.


πŸ“‘ Table of Contents

  1. Overview & Purpose
  2. Dependencies & Technologies
  3. Key Functional Areas
  4. Schema & Table Mapping
  5. Properties & Data Fields
  6. Relationships & Navigation Properties
  7. Usage & Code Examples
  8. UML Class Diagram
  9. Conclusion

πŸ“Œ Overview & Purpose

The WorkOrder class represents a work order record in the system. It encapsulates:

  • Identification: Unique GUID identifier.
  • Organization Context: Business Unit, Division, and referencing details.
  • Status & Scheduling: Estimated hours/costs and actual dates (assigned, start, complete).
  • Relationships: Links to Job, Equipment, and Employee (Project Manager) entities.

This POCO is decorated with Entity Framework data annotations for seamless code-first database mapping.


πŸ› οΈ Dependencies & Technologies

  • C# / .NET (Core or Framework)
  • Entity Framework – Data Annotations (System.ComponentModel.DataAnnotations, System.ComponentModel.DataAnnotations.Schema)
  • LINQ, Collections, System namespaces

πŸš€ Key Functional Areas

  • Data Modeling: Defines the schema for work orders.
  • ORM Mapping: Maps class ↔ database table (irby.WorkOrder).
  • Relationship Management: Navigation properties to related entities.
  • Validation & Formatting: (Future scope via DataAnnotations for required fields, ranges, etc.)

πŸ“‹ Schema & Table Mapping

[Table("WorkOrder", Schema = "irby")]
public class WorkOrder
{ 
    // ... properties ...
}
  • Schema: irby
  • Table Name: WorkOrder
Annotation Applies To Description
[Table] Class level Defines target DB table and schema.
[Key] WorkOrderId property Marks primary key.
[ForeignKey(...)] Navigation props Defines FK relationship to another entity.
[NotMapped] Equipment, DocumentName Excludes property from DB mapping.

πŸ”’ Properties & Data Fields

Property Type Attributes Description
WorkOrderId Guid [Key] Primary key. Unique identifier for each work order.
Org_Bu string β€” Organization Business Unit code.
Org_IntDivision string β€” Internal division within the organization.
Name string β€” Name of the work order.
DisplayName string β€” Human-friendly display name.
WorkOrderNumber string β€” Unique work order number (e.g., β€œWO-12345”).
DocType string β€” Document type code (e.g., β€œINVOICE”, β€œRM”).
WorkOrderType string β€” Type/category of work order (e.g., β€œMaintenance”, β€œInstallation”).
Status string β€” Current status (e.g., β€œOpen”, β€œInProgress”, β€œClosed”).
Reference string β€” External reference or PO number.
EstimatedHours decimal β€” Estimated labor hours.
EstimatedAmount decimal β€” Estimated cost/amount.
DateAssigned DateTime? β€” When the work order was assigned.
DateStart DateTime? β€” Actual start date.
DateComplete DateTime? β€” Actual completion date.
StatusComment string β€” Additional comments on status.
JobId Guid [ForeignKey("JobId")] ID of the related Job entity.
EquipmentId Guid? β€” Optional ID of associated Equipment.
ProjectManagerId Guid? [ForeignKey("ProjectManagerId")] ID of the Employee acting as PM.
DocumentId string β€” External document identifier (e.g., sharepoint file ID).
DocumentName string [NotMapped] Friendly name of the document (not stored in DB).
WorkOrderTypeCode string β€” Coded value for work order type.

πŸ”— Relationships & Navigation Properties

[ForeignKey("JobId")]
public Job Job { get; set; }

[NotMapped]
public Equipment Equipment { get; set; }

[ForeignKey("ProjectManagerId")]
public Employee Employee { get; set; }
  • Job
    • β˜… Type: Job (another domain entity)
    • β˜… FK: JobId
  • Equipment
    • β˜… Type: Equipment
    • β˜… NotMapped: This is a transient property, not persisted.
  • Employee
    • β˜… Type: Employee (for Project Manager)
    • β˜… FK: ProjectManagerId

πŸ’» Usage & Code Examples

1. Creating a New WorkOrder

var workOrder = new WorkOrder
{
    WorkOrderId        = Guid.NewGuid(),
    Org_Bu             = "BU01",
    Org_IntDivision    = "DIV-A",
    Name               = "Install Laser Printer",
    DisplayName        = "Laser Printer Installation",
    WorkOrderNumber    = "WO-2023-1001",
    DocType            = "INSTALL",
    WorkOrderType      = "Installation",
    Status             = "Open",
    EstimatedHours     = 4.5m,
    EstimatedAmount    = 250.00m,
    DateAssigned       = DateTime.UtcNow,
    JobId              = existingJob.Id,
    ProjectManagerId   = pmEmployee.Id,
    DocumentId         = "DOC-789"
};

2. Saving via Entity Framework

using (var context = new IrbyImagingContext())
{
    context.WorkOrders.Add(workOrder);
    context.SaveChanges();
}

3. Querying Work Orders

// All open work orders
var openWOs = context.WorkOrders
    .Where(wo => wo.Status == "Open")
    .OrderBy(wo => wo.DateAssigned)
    .ToList();

πŸ“ UML Class Diagram

@startuml
class WorkOrder {
  - 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 DocumentId
  - string DocumentName
  - string WorkOrderTypeCode
}
class Job
class Equipment
class Employee

WorkOrder "1" --> "1" Job
WorkOrder "1" --> "0..1" Equipment : NotMapped
WorkOrder "1" --> "0..1" Employee
@enduml

Tip: Paste the above snippet into PlantUML to visualize the relationships!


🏁 Conclusion

The WorkOrder class is a foundational domain model in the Irby Imaging application, designed to:

  • Represent and persist work order data
  • Maintain strong relationships with jobs, equipment, and personnel
  • Facilitate CRUD operations in a code-first Entity Framework environment

By following this documentation, developers can confidently extend, query, and integrate WorkOrder entities within the broader system. Happy coding! πŸŽ‰