📄 IrbyImaging.DomainClasses – CostCode.cs Documentation
📑 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Domain Model & Data Model
- Class Diagram (Mermaid UML)
- Sample Usage & Code Snippets
- Integration with EF Core
- Error Handling & Validation
- Conclusion
🔍 Overview & Purpose
The CostCode class represents a billing or cost‐tracking code within the Irby Imaging domain.
It is used to classify costs into categories (e.g., employee hours vs. equipment usage) and to link those cost codes back to a particular Job.
- Namespace:
IrbyImaging.DomainClasses - Schema/Table:
irby.CostCode - Primary Purpose: Provide a strongly‐typed, EF Core‐friendly model for persisting and querying cost codes.
🛠️ Dependencies & Technologies
| Technology/Package | Purpose |
|---|---|
.NET Core / .NET Framework |
Base framework |
System.ComponentModel.DataAnnotations |
Attributes for validation & display metadata |
System.ComponentModel.DataAnnotations.Schema |
Attributes for table & foreign key mapping |
Entity Framework Core |
ORM for database access and mapping |
🚀 Key Functional Areas
- Persistence
- Table mapping via
[Table],[Key],[ForeignKey].
- Table mapping via
- Navigation & Relationships
- One‐to‐many relationship: Job → CostCode.
- Categorization
CostCodeTypeenum to distinguish Employee vs. Equipment.
- Metadata & Validation
[Display(Name = "Current Job")]for UI hints.
🏗️ Domain Model & Data Model
CostCode Entity
| Property | Type | Attributes | Description |
|---|---|---|---|
CostCodeId |
Guid |
[Key] |
Primary key. |
CostCodeNumber |
string |
Unique code or identifier (e.g., “CC-1001”). | |
Name |
string |
Human‐readable name (e.g., “Generator Rental”). | |
JobId |
Guid |
[Display(Name = "Current Job")][ForeignKey("JobId")] |
FK to the associated Job. |
Job |
Job |
Navigation property | Related Job entity (one‐to‐one). |
CostCodeType |
CostCodeType |
Enum to indicate cost category. |
CostCodeType Enumeration
| Name | Value | Description |
|---|---|---|
Employee |
1 | Cost associated with labor |
Equipment |
2 | Cost associated with machinery |
public enum CostCodeType {
Employee = 1,
Equipment = 2
}
📐 Class Diagram (Mermaid UML)
classDiagram
direction LR
class CostCode {
+Guid CostCodeId
+string CostCodeNumber
+string Name
+Guid JobId
+CostCodeType CostCodeType
}
class Job {
+Guid JobId
+string Title
-- // other properties...
}
CostCode --> Job : JobId
enum CostCodeType {
Employee
Equipment
}
💡 Sample Usage & Code Snippets
1. Creating a New CostCode
using IrbyImaging.DomainClasses;
using System;
var newCostCode = new CostCode {
CostCodeId = Guid.NewGuid(),
CostCodeNumber = "CC-2023",
Name = "Site Inspection",
JobId = existingJobId, // from context
CostCodeType = CostCodeType.Employee
};
2. Adding to EF Core DbContext
using (var context = new MyDbContext()) {
context.CostCodes.Add(newCostCode);
await context.SaveChangesAsync();
}
3. Querying CostCodes by Type
var equipmentCodes = await context.CostCodes
.Where(cc => cc.CostCodeType == CostCodeType.Equipment)
.ToListAsync();
4. Eager‐Loading the Related Job
var costWithJob = await context.CostCodes
.Include(cc => cc.Job)
.FirstOrDefaultAsync(cc => cc.CostCodeNumber == "CC-2023");
Console.WriteLine($"CostCode '{costWithJob.Name}' belongs to Job '{costWithJob.Job.Title}'.");
🔗 Integration with EF Core
-
Model Registration
In yourDbContext:public class MyDbContext : DbContext { public DbSet<CostCode> CostCodes { get; set; } // ... protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity<CostCode>() .ToTable("CostCode", "irby"); // Additional fluent‐API overrides if needed } } -
Migrations
dotnet ef migrations add AddCostCodeEntity dotnet ef database update
⚠️ Error Handling & Validation
-
DataAnnotations provide UI‐level hints (e.g.,
[Display]), but no[Required]or[StringLength]are applied.-
Consider adding additional validation attributes as needed:
[Required] [StringLength(50)] public string CostCodeNumber { get; set; }
-
-
Foreign Key Integrity is enforced by EF Core via
[ForeignKey("JobId")].
🏁 Conclusion
The CostCode entity is a lightweight, EF Core‐friendly domain class designed to manage cost‐tracking codes within the Irby Imaging ecosystem.
With a simple enumeration for categorization and a clear relationship to Job, it integrates seamlessly into your DbContext for CRUD operations, reporting, and business logic.
Feel free to extend with additional data annotations, business‐layer services, or UI‐level view models to suit your application’s needs!
🔧 Further files and domain classes will follow similar documentation patterns for consistency and ease of use.