TimesheetEditViewModel 📋🖋️
Welcome to the comprehensive documentation for the IrbyImaging.UI.Models.TimesheetEditViewModel.cs file. This document will guide you through the purpose, structure, usage, and relationships of all view‐ and data‐models defined in this file.
📑 Table of Contents
- Overview & Purpose
- Dependencies & Technologies
- Key Functional Areas
- View & Data Models
4.1. TimesheetEditViewModel
4.2. EmployeeTimesheetEdit
4.3. WorkEntryEdit
4.4. EquipmentTimesheetEdit
4.5. EquipmentWorkEntryEdit
4.6. CostCodeEdit, JobEdit & ClassEdit - UML Class Diagram
- Sample Usage & Code Snippets
- Conclusion
1. Overview & Purpose 🎯
The TimesheetEditViewModel and its related classes power the timesheet editing UI within the IrbyImaging application. It bundles:
- Metadata about a timesheet (IDs, dates, statuses).
- Collections of employee and equipment entries to edit.
- Dropdown data (crews, jobs, cost codes, etc.) for building select lists in Razor views.
This ViewModel allows controllers to pass a fully prepared model to the frontend, and receive back the user’s edits in one cohesive object.
2. Dependencies & Technologies 🔧
| Namespace | Purpose |
|---|---|
IrbyImaging.DomainClasses |
Enums & domain types (Status, CostCodeType) |
Microsoft.AspNetCore.Mvc.Rendering |
SelectListItem for dropdown population |
System, System.Collections.Generic |
Core .NET classes (e.g., Guid, List<T> ) |
Technologies:
- ASP.NET Core MVC
- C# 8.0+ (.NET Core 3.1 / .NET 5+)
- Razor Views for UI binding
3. Key Functional Areas ⚙️
- Timesheet Metadata
Tracks IDs, timestamps (Created, Submitted, Reviewed, Approved), user signatures, status flags, comments. - Employee Timesheet Editing
NestedEmployeeTimesheetEdit→WorkEntryEditobjects for daily work details. - Equipment Timesheet Editing
NestedEquipmentTimesheetEdit→EquipmentWorkEntryEditfor machine hours & readings. - Dropdown Data
Pre‑populated lists (SelectListItemor simple Text/Value pairs) for:- Crews & Employees
- Jobs, Cost Codes & Classes
- Work Orders, Union & Pay Codes
- Equipment list
4. View & Data Models 📦
4.1 TimesheetEditViewModel
public class TimesheetEditViewModel {
public Guid TimesheetId { get; set; }
public string CrewId { get; set; }
public string ForemanSignature { get; set; }
public DateTime CreatedDate { get; set; } = DateTime.UtcNow;
public string Comments { get; set; }
public string SubmittedBy { get; set; }
public DateTime SubmittedDate { get; set; }
public string ReviewedBy { get; set; }
public DateTime ReviewedDate { get; set; }
public string ApprovedBy { get; set; }
public DateTime ApprovedDate { get; set; }
public bool IsDeleted { get; set; }
public Status Status { get; set; }
// Editable items
public List<EmployeeTimesheetEdit> EmployeeTimesheets { get; set; }
= new List<EmployeeTimesheetEdit>();
public List<EquipmentTimesheetEdit> EquipmentTimesheets { get; set; }
= new List<EquipmentTimesheetEdit>();
// Dropdown data
public List<SelectListItem> AvailableCrews { get; set; }
= new List<SelectListItem>();
public List<SelectListItem> AvailableEmployees { get; set; }
= new List<SelectListItem>();
public List<JobEdit> AvailableJobs { get; set; }
= new List<JobEdit>();
public List<CostCodeEdit> AvailableCostCodes { get; set; }
= new List<CostCodeEdit>();
public List<ClassEdit> AvailableClasses { get; set; }
= new List<ClassEdit>();
public List<SelectListItem> AvailableWorkOrders { get; set; }
= new List<SelectListItem>();
public List<SelectListItem> AvailableUnionCodes { get; set; }
= new List<SelectListItem>();
public List<SelectListItem> AvailablePayCodes { get; set; }
= new List<SelectListItem>();
public List<SelectListItem> AvailableEquipment { get; set; }
= new List<SelectListItem>();
}
Highlights:
- Metadata fields capture the full lifecycle of a timesheet.
EmployeeTimesheetsandEquipmentTimesheetshold the actual editing entries.- Dropdown lists are prepared server‑side for Razor helpers.
4.2 EmployeeTimesheetEdit
public class EmployeeTimesheetEdit {
public Guid EmployeeId { get; set; }
public Guid? EmployeeTimesheetId { get; set; }
public Guid TimesheetId { get; set; }
public string Employee { get; set; }
// One-to-many: multiple work entries per employee
public List<WorkEntryEdit> WorkEntries { get; set; }
= new List<WorkEntryEdit>();
}
- EmployeeId links to the domain employee record.
- EmployeeTimesheetId is null when creating a new entry.
- WorkEntries contains daily details.
4.3 WorkEntryEdit
public class WorkEntryEdit {
public Guid? WorkEntryId { get; set; }
public string JobNo { get; set; }
public string CostCode { get; set; }
public string Class { get; set; }
public string WorkOrder { get; set; }
public string UnionCode { get; set; }
public string PayCode { get; set; }
// Hours & time tracking
public double RegularHours { get; set; }
public double OvertimeHours { get; set; }
public double DoubletimeHours { get; set; }
// Per diem & job transfer
public string PerDiemType { get; set; }
public double PerDiemRate { get; set; }
public string JobTransfer { get; set; }
// Times & breaks
public string StartTime { get; set; }
public string EndTime { get; set; }
public double LunchHour { get; set; }
public DateTime WorkDate { get; set; }
// Meal checkboxes
public bool Breakfast { get; set; }
public bool Lunch { get; set; }
public bool Dinner { get; set; }
public bool Motel { get; set; }
}
- Captures all aspects of a single day’s work for an employee.
4.4 EquipmentTimesheetEdit
public class EquipmentTimesheetEdit {
public Guid EquipmentId { get; set; }
public Guid TimesheetId { get; set; }
public Guid? EquipmentTimesheetId { get; set; }
public string Equipment { get; set; }
// One-to-many: daily equipment usage
public List<EquipmentWorkEntryEdit> EquipmentEntries { get; set; }
= new List<EquipmentWorkEntryEdit>();
}
- Analogous to
EmployeeTimesheetEditbut for machines & vehicles.
4.5 EquipmentWorkEntryEdit
public class EquipmentWorkEntryEdit {
public Guid? EquipmentEntryId { get; set; }
public DateTime WorkDate { get; set; }
public double OdometerReading { get; set; }
public double Meter { get; set; }
public string CostCode { get; set; }
public string JobNo { get; set; }
public double WorkedHours { get; set; }
public double IdleHours { get; set; }
}
- Tracks machine hours, readings, and cost allocation per day.
4.6 CostCodeEdit, JobEdit & ClassEdit
public class CostCodeEdit {
public string Text { get; set; }
public string Value { get; set; }
public string JobId { get; set; }
public CostCodeType CostCodeType { get; set; }
public string CostCodeNumber { get; set; }
}
public class JobEdit {
public string Text { get; set; }
public string Value { get; set; }
public string JobId { get; set; }
}
public class ClassEdit {
public string Text { get; set; }
public string Value { get; set; }
public string JobId { get; set; }
public int CostCodeNumber { get; set; }
}
- Simple DTOs for building job/cost‑code/class dropdown lists in the UI.
5. UML Class Diagram 📐
classDiagram
TimesheetEditViewModel "1" o-- "*" EmployeeTimesheetEdit : contains
TimesheetEditViewModel "1" o-- "*" EquipmentTimesheetEdit : contains
EmployeeTimesheetEdit "1" o-- "*" WorkEntryEdit : contains
EquipmentTimesheetEdit "1" o-- "*" EquipmentWorkEntryEdit : contains
class TimesheetEditViewModel {
+Guid TimesheetId
+string CrewId
+DateTime CreatedDate
+Status Status
+List<SelectListItem> AvailableCrews
+List<EmployeeTimesheetEdit> EmployeeTimesheets
+List<EquipmentTimesheetEdit> EquipmentTimesheets
}
class EmployeeTimesheetEdit {
+Guid EmployeeId
+List<WorkEntryEdit> WorkEntries
}
class WorkEntryEdit {
+DateTime WorkDate
+double RegularHours
+bool Motel
}
class EquipmentTimesheetEdit {
+Guid EquipmentId
+List<EquipmentWorkEntryEdit> EquipmentEntries
}
class EquipmentWorkEntryEdit {
+DateTime WorkDate
+double WorkedHours
}
6. Sample Usage & Code Snippets 🚀
Controller Example
public IActionResult Edit(Guid id) {
// Fetch domain data
var domainSheet = _timesheetService.GetById(id);
// Map to ViewModel
var vm = new TimesheetEditViewModel {
TimesheetId = domainSheet.Id,
CrewId = domainSheet.CrewId,
ForemanSignature = domainSheet.ForemanSignature,
CreatedDate = domainSheet.CreatedDate,
Status = domainSheet.Status,
Comments = domainSheet.Comments,
// Populate dropdowns
AvailableCrews = _crewService.GetAll()
.Select(c => new SelectListItem(c.Name, c.Id)).ToList(),
AvailableJobs = _jobService.GetAllJobs()
.Select(j => new JobEdit { Text = j.Name, Value = j.Id, JobId = j.Id }).ToList(),
// ... other dropdowns
};
// Map EmployeeTimesheets & EquipmentTimesheets similarly...
return View(vm);
}
[HttpPost]
public IActionResult Edit(TimesheetEditViewModel model) {
if (!ModelState.IsValid) {
// repopulate dropdowns
return View(model);
}
// Map back to domain and save
_timesheetService.Update(model);
return RedirectToAction("List");
}
Razor View Snippet
@model TimesheetEditViewModel
<form asp-action="Edit" method="post">
<div>
<label>Crew:</label>
<select asp-for="CrewId" asp-items="Model.AvailableCrews"></select>
</div>
<!-- Render Employee timesheet rows -->
@for (int i = 0; i < Model.EmployeeTimesheets.Count; i++) {
<div class="employee-entry">
<h4>@Model.EmployeeTimesheets[i].Employee</h4>
@for (int j = 0; j < Model.EmployeeTimesheets[i].WorkEntries.Count; j++) {
<input asp-for="EmployeeTimesheets[@i].WorkEntries[@j].WorkDate" type="date" />
<input asp-for="EmployeeTimesheets[@i].WorkEntries[@j].RegularHours" type="number" step="0.25" />
<!-- ... -->
}
</div>
}
<button type="submit">Save</button>
</form>
7. Conclusion ✅
The TimesheetEditViewModel.cs file orchestrates all the data needed to render, edit, and submit timesheets in the IrbyImaging UI. By grouping metadata, nested employee/equipment entries, and dropdown sources in one ViewModel, controllers and views remain clean, strongly typed, and easy to maintain.
Feel free to extend these classes with additional properties (e.g., validation attributes, helper methods) as your business requirements evolve.
Happy coding! 🏗️🕒