๐ Employee Domain Model (Employee.cs)
Welcome to the comprehensive documentation for the Employee domain class in the IrbyImaging.DomainClasses assembly. This file defines the Employee entity, its properties, EF Core mappings, relationships, computed fields, and usage patterns.
๐ Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- Data Model Structure
4.1 Primary Identifiers
4.2 Personal Information
4.3 Contact & Address
4.4 Employment Details
4.5 Navigation Properties
4.6 Computed & Unmapped Properties
- Entity Relationships
- EF Core & DataAnnotations Mappings
- Helper Methods & Utilities
- Sample Code Blocks & Usage Examples
- UML Class Diagram
- Conclusion & Best Practices
๐ 1. Overview & Purpose
The Employee class represents an individual working within the Irby Imaging system. It is used to:
- Persist employee details in the database (schema
irby, table Employee).
- Capture personal, contact, and employment-related data.
- Link to Assets, Jobs, Departments, Roles, and Crew assignments.
- Provide computed properties (e.g., FullName, NotDisposedAssets) for display and business logic.
๐ ๏ธ 2. Dependencies & Technologies
| Technology / Library |
Purpose |
| Microsoft.EntityFrameworkCore |
ORM mapping (via DataAnnotations) |
| System.ComponentModel.DataAnnotations |
Validation & display metadata |
| System.ComponentModel.DataAnnotations.Schema |
Table/Column mapping |
| IrbyImaging.Utility |
Custom enums (EmployeeStatus), helper utilities |
| Microsoft.AspNetCore.Mvc.Rendering |
(Imported but not directly used in this class) |
๐ 3. Key Functional Areas
- Data Persistence: Mapped to the
irby.Employee table via EF Core.
- Navigation: Establishes relationships to
Job, Asset, Department, Role, and CrewEmployee.
- Computed Fields: Calculates the
FullName and filters assets that are not disposed.
- UI Metadata: Uses
[Display(Name = "...")] for label customization in MVC/Razor views.
- Access Control: Holds a collection of
Permissions and various Role groupings for authorization.
๐๏ธ 4. Data Model Structure
Below is a categorized overview of all properties in Employee.cs.
๐ Primary Identifiers
| Property |
Type |
Description |
EmployeeId |
Guid |
[Key] Primary key for the Employee table |
| Property |
Type |
Display Name |
Notes |
JdeNumber |
string |
JDE Number |
JDE system identifier |
FirstName |
string |
First Name |
|
MiddleName |
string |
Middle Name |
|
LastName |
string |
Last Name |
|
Birthday |
DateTime? |
โ |
Date of birth (optional) |
| Property |
Type |
Display Name |
Notes |
Email, WorkEmail |
string |
Email |
Personal & work email |
PhoneNumberFromActiveDirectory |
string |
Office # |
Not mapped to DB |
PhoneNumberFromAssignedMobile |
string |
Mobile # |
Not mapped to DB |
OfficePhone |
string |
โ |
Direct office extension |
StreetAddress, City, State, County, Zip |
string |
โ |
Postal address |
๐ผ Employment Details
| Property |
Type |
Display Name |
Notes |
Title |
string |
Job Title |
|
BusinessUnit |
string |
Business Unit |
|
JobId |
Guid |
Current Job |
[ForeignKey โ Job] |
Status |
EmployeeStatus |
โ |
Enum from IrbyImaging.Utility |
PayType |
string |
โ |
Salary/Hourly etc. |
EmploymentStartDate |
DateTime? |
โ |
|
TerminatedDate |
DateTime? |
โ |
Nullable termination date |
RehireDate |
DateTime? |
โ |
Nullable rehire date |
LastJob, LastJobDate |
string / DateTime? |
โ |
Details of previous position |
FLSAExemption |
string |
โ |
Dept. of Labor exemption status |
UserName |
string |
โ |
AD or system login name |
AzureUserId |
Guid |
โ |
Link to Azure AD user |
LastFourSSN |
string |
โ |
Stored for verification (last 4 digits) |
PWReset & PWResetDate |
bool / DateTime |
โ |
Password reset flag + date |
UARApprover |
bool |
โ |
User Access Request approver flag |
๐ Navigation Properties
| Property |
Type |
Notes |
Job |
Job |
Current job detail |
Department |
Department |
Department entity (DepartmentId) |
Role |
Role |
Primary role (RoleId) |
Assets |
ICollection<Asset> |
Assets assigned to employee |
CrewEmployees |
ICollection<CrewEmployee> |
Many-to-many with crews |
๐งฎ Computed & Unmapped Properties
| Property |
Type |
Formula / Purpose |
FullName |
string |
"{LastName}, {FirstName} {MiddleName}" (read-only) |
DisplayName |
string |
Duplicate of full name for certain UIs |
NotDisposedAssets |
IEnumerable<Asset> |
Filters Assets where Status != Disposed |
AdditionalRoles, Roles, MainRoles, AllRoles |
collections of Role |
Unmapped groupings for UI & permission management |
Permissions |
HashSet<string> |
Set of permission keys assigned |
EmployeeStatus, JobName, ManagerName |
string |
Cached/display-only fields |
๐ 5. Entity Relationships
classDiagram
direction LR
Employee "1" -- "0..*" Asset : AssignedAssets
Employee "1" --> "1" Job : CurrentJob
Employee "1" --> "0..1" Department : Department
Employee "1" --> "0..1" Role : Role
Employee "1" -- "0..*" CrewEmployee : CrewAssignments
CrewEmployee -- "1" Crew
CrewEmployee -- "1" Employee
- One Employee can have many Assets (1:N).
- One Employee has one current Job (1:1).
- Department and Role are optional (0..1).
- CrewEmployee is a linking entity for employees in crews.
๐ 6. EF Core & DataAnnotations Mappings
| Attribute |
Target |
Purpose |
[Table("Employee", Schema="irby")] |
Class |
Maps to irby.Employee in DB |
[Key] |
EmployeeId |
Primary key |
[Display(Name="...")] |
Various props |
UI-friendly labels for MVC/Razor |
[ForeignKey("...")] |
JobId, DepartmentId, RoleId |
Configures relations |
[NotMapped] |
Computed & UI-only props |
Excluded from DB |
๐งฐ 7. Helper Methods & Utilities
Although Employee is predominantly a POCO, it offers:
- FullName: Combines names for display.
- NotDisposedAssets: LINQ filter to hide disposed assets.
Example:
string full = employee.FullName; // "Doe, John A."
var liveAssets = employee.NotDisposedAssets;
๐ป 8. Sample Code Blocks & Usage Examples
8.1 Fetching Employees with Assets
using (var context = new AppDbContext())
{
var employees = context.Employees
.Include(e => e.Assets)
.Where(e => e.Status == EmployeeStatus.Active)
.ToList();
foreach (var emp in employees)
{
Console.WriteLine($"{emp.FullName} has {emp.NotDisposedAssets.Count()} active assets.");
}
}
8.2 Assigning an Asset to an Employee
var employee = context.Employees.Find(employeeId);
var asset = context.Assets.Find(assetId);
employee.Assets.Add(asset);
context.SaveChanges();
8.3 Displaying in a Razor View
@model Employee
<h2>@Model.FullName</h2>
<ul>
<li>Email: @Model.Email</li>
<li>Title: @Model.Title</li>
<li>Department: @Model.Department?.Name</li>
</ul>
๐ 9. UML Class Diagram
classDiagram
class Employee {
+Guid EmployeeId
+string JdeNumber
+string FirstName
+string MiddleName
+string LastName
+string FullName {get;}
+string PhoneNumberFromActiveDirectory
+string PhoneNumberFromAssignedMobile
+string Title
+Guid JobId
+Job Job
+string DisplayName
+string BusinessUnit
+string Email
+string EmployeeNotes
+bool PWReset
+DateTime PWResetDate
+EmployeeStatus Status
+ICollection<Asset> Assets
+string StreetAddress
+string City
+string State
+string County
+string Zip
+Guid? DepartmentId
+Department Department
+Guid? RoleId
+Role Role
+List<Role> AdditionalRoles
+string PayType
+DateTime? Birthday
+DateTime? EmploymentStartDate
+DateTime? TerminatedDate
+DateTime? RehireDate
+string LastJob
+DateTime? LastJobDate
+string FLSAExemption
+string WorkEmail
+string UserName
+bool UARApprover
+Guid AzureUserId
+string LastFourSSN
+string OfficePhone
+Guid? ManagerId
+Guid? CrewId
+ICollection<Role> Roles
+ICollection<Role> MainRoles
+HashSet<string> Permissions
+ICollection<Role> AllRoles
+ICollection<CrewEmployee> CrewEmployees
+IEnumerable<Asset> NotDisposedAssets
+string EmployeeStatus
+string JobName
+string ManagerName
}
๐ 10. Conclusion & Best Practices
- Use EF Core Migrations to keep the database schema in sync with
Employee.cs.
- Leverage Display Attributes to simplify UI labeling.
- Never persist
[NotMapped] dataโthese are strictly for computation/UI.
- Control access via Roles and Permissions collections.
- Always filter out disposed assets via
NotDisposedAssets to maintain data integrity.
๐ Congratulations! You now have a detailed understanding of the Employee domain class, its structure, relationships, and usage patterns within the Irby Imaging application.