🕒 TimeSheetEntry.cs Documentation
📑 Table of Contents
- Overview & Purpose
- 🔑 Key Functional Areas
- 🧩 Dependencies & Technologies
- 📊 Data Model & Mappings
4.1 EF Core Attributes
4.2 Properties & Relationships - 🗺 UML Class Diagram
- ⚙️ Sample Usage & Code Snippets
- 🧰 Helper Methods & Utilities
- 🚧 Error Handling & Validation
- 🎉 Conclusion
📋 1. Overview & Purpose
The TimeSheetEntry class represents a single time tracking record in the Irby Imaging domain. It captures who worked, what type of entry was recorded (e.g., regular hours, overtime), when it occurred, and how many hours were logged. This domain entity is persisted in the database under schema irby.TimeSheetEntry and is used in payroll calculations, reporting, and auditing.
Key goals:
- Store daily working hours per employee.
- Track the type of hours worked (regular, overtime, vacation, etc.).
- Keep an audit trail with creation/modification metadata.
- Support soft-deletion for historical reporting.
🔑 2. Key Functional Areas
- Entity Mapping: Maps to a database table via Entity Framework Core attributes.
- Relationships:
Employee(many-to-one)TimeEntryType(many-to-one)
- Audit Fields: Tracks who created/modified records and when.
- Soft Deletion:
IsDeletedflag to omit entries without hard-deleting. - Domain Properties: Encapsulates time entry data (
DateWorked,HoursWorked,Notes, etc.).
🧩 3. Dependencies & Technologies
| Technology | Purpose |
|---|---|
| .NET Core / .NET 5+ | Runtime & Base Class Libraries |
| Entity Framework | ORM for mapping classes to database tables |
| System.ComponentModel.DataAnnotations | Data validation & mapping attributes |
| System.ComponentModel.DataAnnotations.Schema | Schema/table configuration |
📊 4. Data Model & Mappings
namespace IrbyImaging.DomainClasses
{
[Table("TimeSheetEntry", Schema = "irby")]
public class TimeSheetEntry
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public Guid TimeSheetEntryId { get; set; }
public Guid EmployeeId { get; set; }
[ForeignKey("EmployeeId")]
public Employee Employee { get; set; }
public Guid TimeEntryTypeId { get; set; }
[ForeignKey("TimeEntryTypeId")]
public TimeEntryType TimeEntryType { get; set; }
[Column(TypeName = "Date")]
public DateTime DateWorked { get; set; }
public Decimal HoursWorked { get; set; }
public bool IsDeleted { get; set; }
public string Notes { get; set; }
public string AddedBy { get; set; }
public DateTime AddedDate { get; set; }
public string ModifiedBy { get; set; }
public DateTime ModifiedDate { get; set; }
}
}
4.1 EF Core Attributes
[Table(...)]
Specifies table name (TimeSheetEntry) and schema (irby).[Key]
MarksTimeSheetEntryIdas primary key.[DatabaseGenerated(DatabaseGeneratedOption.None)]
Indicates the GUID is supplied by the application, not generated by the database.[ForeignKey("...")]
Establishes navigation properties forEmployeeandTimeEntryType.[Column(TypeName = "Date")]
PersistsDateWorkedas SQLDate(without time).
4.2 Properties & Relationships
| Property | Type | Description |
|---|---|---|
| TimeSheetEntryId | Guid |
PK, uniquely identifies the time sheet entry. |
| EmployeeId | Guid |
FK to Employee record. |
| Employee | Employee |
Navigation to employee who logged the time. |
| TimeEntryTypeId | Guid |
FK to TimeEntryType (e.g., Regular, Overtime). |
| TimeEntryType | TimeEntryType |
Navigation to the type of entry. |
| DateWorked | DateTime |
Date on which hours were worked. |
| HoursWorked | Decimal |
Number of hours worked (e.g., 8.0, 7.5). |
| IsDeleted | bool |
Soft-delete flag. |
| Notes | string |
Optional notes or comments. |
| AddedBy | string |
Username/ID of creator. |
| AddedDate | DateTime |
Timestamp of creation. |
| ModifiedBy | string |
Username/ID of last modifier. |
| ModifiedDate | DateTime |
Timestamp of last update. |
🗺 5. UML Class Diagram
classDiagram
class TimeSheetEntry {
+Guid TimeSheetEntryId
+Guid EmployeeId
+DateTime DateWorked
+Decimal HoursWorked
+bool IsDeleted
+string Notes
+string AddedBy
+DateTime AddedDate
+string ModifiedBy
+DateTime ModifiedDate
}
class Employee
class TimeEntryType
TimeSheetEntry "1" --> "1" Employee : EmployeeId
TimeSheetEntry "1" --> "1" TimeEntryType : TimeEntryTypeId
⚙️ 6. Sample Usage & Code Snippets
Creating a New TimeSheetEntry
var entry = new TimeSheetEntry
{
TimeSheetEntryId = Guid.NewGuid(),
EmployeeId = someEmployeeId,
TimeEntryTypeId = regularHoursTypeId,
DateWorked = DateTime.UtcNow.Date,
HoursWorked = 8.0m,
Notes = "Completed imaging setup",
AddedBy = currentUser,
AddedDate = DateTime.UtcNow,
ModifiedBy = currentUser,
ModifiedDate = DateTime.UtcNow,
IsDeleted = false
};
dbContext.TimeSheetEntries.Add(entry);
await dbContext.SaveChangesAsync();
Querying Entries for a Date Range
var startDate = new DateTime(2024, 1, 1);
var endDate = new DateTime(2024, 1, 31);
var januaryEntries = dbContext.TimeSheetEntries
.Where(e => !e.IsDeleted
&& e.DateWorked >= startDate
&& e.DateWorked <= endDate)
.Include(e => e.Employee)
.Include(e => e.TimeEntryType)
.ToList();
🧰 7. Helper Methods & Utilities
While TimeSheetEntry is a plain domain model, common helpers in the application might include:
- Extensions for rounding hours or computing totals.
- Repository Pattern wrapping
DbContextoperations (Add, Update, Soft-Delete). - Audit Interceptors to auto-populate
AddedBy/ModifiedByfields before saving.
🚧 8. Error Handling & Validation
- Data Annotations can be extended for validation (e.g.,
[Range(0, 24)]onHoursWorked). - Service Layer should ensure:
EmployeeIdandTimeEntryTypeIdexist.DateWorkedis within permissible range.- Prevent duplicate entries for the same date/employee/type.
🎉 9. Conclusion
The TimeSheetEntry class is a core domain entity for the Irby Imaging application, enabling robust time tracking and auditing. Through EF Core mappings, soft-delete support, and clear relationships, it integrates seamlessly into reporting and payroll services. By following the sample usage patterns and extending with validation or repository abstractions, developers can reliably create and manage time entries.
Happy coding! 🚀