Employee Assignments
Employee assignments are managed through theEmployeeNumber field in the locker model. This field links a locker to a specific employee.
Data Model
The employee number is stored as an optional field in both the frontend and backend:The
EmployeeNumber field is nullable, allowing lockers to exist without an assigned employee.Assigning Employees
Employees are assigned to lockers through the management form:app.component.html:21-24
One Locker Per Employee Rule
The system enforces a strict rule: each employee can only be assigned to one locker at a time. This prevents double-booking and ensures accurate tracking.Validation Logic
During locker creation, the system checks if the employee number already exists:LockersController.cs:45-47
The validation excludes empty employee numbers, so multiple unassigned lockers are allowed.
Rejection of Duplicate Assignments
If an employee is already assigned to another locker, the creation fails:LockersController.cs:53-58
Complete Validation Flow
The complete validation process checks both locker numbers and employee numbers:LockersController.cs:42-76
Tracking Locker Occupancy Status
The system automatically tracks whether a locker is empty or occupied based on employee assignments using theIsEmpty field.
Automatic Status Calculation
TheIsEmpty status is calculated automatically and never set manually:
During Locker Creation:
LockersController.cs:68
LockersController.cs:92
Status Logic
The calculation follows this simple rule:Set IsEmpty to false
If an employee number exists and is not empty, set
IsEmpty = false (locker is occupied)Visual Representation
The occupancy status is visually represented in the dashboard with color coding:app.component.html:33
- Green (#92f08d): Empty locker (
isEmpty = true) - Blue (#8db0f0): Occupied locker (
isEmpty = false)
Display in Dashboard
The employee number is displayed on occupied locker cards:app.component.html:36
Employee Number Validation
The system validates employee numbers to ensure data integrity and enforce business rules.Uniqueness Validation
The primary validation ensures each employee number is unique across all occupied lockers:LockersController.cs:45-47
The query uses two conditions:
- Match the employee number
- Exclude empty strings to allow multiple unassigned lockers
Empty Employee Numbers
Empty employee numbers are explicitly allowed and excluded from uniqueness validation:Update Validation
When updating a locker, the system recalculates the occupancy status:LockersController.cs:82-100
The update logic recalculates
IsEmpty based on the new employee number, ensuring status accuracy after modifications.Business Logic Summary
The employee tracking system implements several key business rules:One-to-One Relationship
Each employee can have maximum one locker assigned
Automatic Status
Occupancy status is calculated automatically from employee assignments
Unique Validation
Employee numbers must be unique across all occupied lockers
Optional Assignment
Lockers can exist without employee assignments
Assignment Flow
Unassigning Employees
To unassign an employee from a locker, simply clear the employee number field when updating:- Click on the locker number to populate the form
- Clear the “Employee No” field (leave it empty)
- Submit the form
- Set
IsEmpty = true - Update the locker’s occupancy status
- Change the visual indicator to green
LockersController.cs:92
Clearing an employee assignment frees up that employee to be assigned to a different locker.