Say I have a POCO that stores a date range as follows:
public class DateRange()
{
public DateTime FromDate{get;set;}
public DateTime ToDate{get;set;}
}
I want to be able to save a half day at the beginning and/or end of the range. To do this I’m going to present my data as a jqueryui date picker for a from date and to date as well as a checkbox next to each datepicker to represent a 1/2 day. My viewmodel would look something like this:
public class DateRangeModel()
{
public DateTime FromDate {get; set;}
public DateTime ToDate{get;set;}
public bool IsFromDateHalfDay{get; set;}
public bool IsToDateHalfDay {get; set;}
}
When the 1/2 day checkbox is checked for the FromDate I need to save the FromDate in the entity as the selected day + 12 hours and when the 1/2 day checkbox is selected for the ToDate in the ViewModel I need to save the ToDate in the entity as the selected day + 12 hours.
Is it possible to do this using Automapper? If not could you suggest a better/different approach? I dont want to have the bools representing the half-days in the entity because I want to use the DateTimes alone for calculations.
Some Examples (Still contemplating how i should represent a range of 1 day and 1/2 a day – going to need to test calculating ranges a lot!):
A Date Range of 1/2 Day From 24th May to a full day 27th May:
2011-05-24 12:00:00.000 => 2011-05-28 00:00:00.000
A Date Range of Full Day From 24th May to a 1/2 day 27th May:
2011-05-24 00:00:00.000 => 2011-05-27 12:00:00.000
A Half Day on 24th May:
2011-05-24 12:00:00.000 => 2011-05-25 00:00:00.000
A Full Day on 24th May:
2011-05-24 12:00:00.000 > 2011-05-25 00:00:00.000
Are we to assume the FromDate/ToDate can only be Full Days (12:00 AM) or Half Days (12:00 PM)?
Domain to View (if needed):
View to Domain