π·οΈ 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
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Schema & Table Mapping
- Properties & Data Fields
- Relationships & Navigation Properties
- Usage & Code Examples
- UML Class Diagram
- 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
- β
Type:
- Equipment
- β
Type:
Equipment - β NotMapped: This is a transient property, not persisted.
- β
Type:
- Employee
- β
Type:
Employee(for Project Manager) - β
FK:
ProjectManagerId
- β
Type:
π» 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! π