I am basically creating a flat View Model for a Timesheet page (ASP.NET MVC) that has a grid for the days of the week. The WorkTime properties should either be an existing WorkTime from the database or null if there is no existing one.
There will only ever be 1 week displayed (Saturday to Friday). and I have the individual properties there so that the syntax in my view should be simpler.
+------+-----+-----+-----+-----+-----+-----+-----+
| Desc | Sat | Sun | Mon | Tue | Wed | Thu | Fri |
+------+-----+-----+-----+-----+-----+-----+-----+
|______|_____|_____|_____|_____|_____|_____|_____|
|______|_____|_____|_____|_____|_____|_____|_____|
|______|_____|_____|_____|_____|_____|_____|_____|
|______|_____|_____|_____|_____|_____|_____|_____|
All of the dates that come from and are persisted to the database have no Time element (all midnight hour) and the Saturday to Friday DateTime properties are all set already.
The properties I am setting
public WorkTime SaturdayWorkTime { get; private set; }
public WorkTime SundayWorkTime { get; private set; }
public WorkTime MondayWorkTime { get; private set; }
public WorkTime TuesdayWorkTime { get; private set; }
public WorkTime WednesdayWorkTime { get; private set; }
public WorkTime ThursdayWorkTime { get; private set; }
public WorkTime FridayWorkTime { get; private set; }
Current iteration...
public DateTime Saturday { get; private set; }
public DateTime Sunday { get; private set; }
public DateTime Monday { get; private set; }
public DateTime Tuesday { get; private set; }
public DateTime Wednesday { get; private set; }
public DateTime Thursday { get; private set; }
public DateTime Friday { get; private set; }
_workTimes = _workTimeRepository.GetByWorkAssignmentID(WorkAssignment.ID, Saturday, Friday);
SaturdayWorkTime = GetWorkTimeForDay(DayOfWeek.Saturday);
SundayWorkTime = GetWorkTimeForDay(DayOfWeek.Sunday);
MondayWorkTime = GetWorkTimeForDay(DayOfWeek.Monday);
TuesdayWorkTime = GetWorkTimeForDay(DayOfWeek.Tuesday);
WednesdayWorkTime = GetWorkTimeForDay(DayOfWeek.Wednesday);
ThursdayWorkTime = GetWorkTimeForDay(DayOfWeek.Thursday);
FridayWorkTime = GetWorkTimeForDay(DayOfWeek.Friday);
with this helper method...
private WorkTime GetWorkTimeForDay(DayOfWeek dow)
{
return _workTimes.FirstOrDefault(x => x.Date.DayOfWeek == dow);
}