I've been trying to figure out the best way to model this entity, and I'm getting stuck. Here's the basic use case/story:
We have equipment arriving on site. We won't know what the equipment is until it arrives. Once the equipment arrives on site it must be recorded as having arrived and whether it was idle or active. If it is active the user must make note of the work the equipment performed. When the equipment leaves the site, this must be noted.
I should be able to easily query whether there is any equipment on the site, what equipment was previously on site, etc.
I'm getting stuck on the date aspect. I'm trying to avoid relying on a cron job to run through and mark equipment as idle if it hasn't been marked idle on a paticular date. It feels like there should be a way to do this. Here's what I've come up with:
public class Equipment {
public int Id { get; set; }
public Site Site { get; set; }
public DateTime Arrival { get; set; }
public DateTime Departure { get; set; }
public IList<EquipmentUtilization> EquipmentUtilizations { get; set; }
}
public class EquipmentUtilization {
public int Id { get; set; }
public Equipment Equipment { get; set; }
public DateTime ReportDate { get; set; }
public string WorkPerformed { get; set; }
}
The idea being that I could run a query like Site.Equipment.Where(x=>x.Departure == null)
to see which equipment is still on site. If there's no EquipmentUtilization for a particular date, it is assume do be idle. I could then setup a DateTimeEnumerator:
public class DateTimeEnumerator : System.Collections.IEnumerable
{
private DateTime begin;
private DateTime end;
public DateTimeEnumerator ( DateTime begin , DateTime end )
{
this.begin = begin;
this.end = end;
}
public System.Collections.IEnumerator GetEnumerator()
{
for(DateTime date = begin; date < end; date = date.AddDays(1))
{
yield return date;
}
}
}
Build a list of dates from the arrival date until DateTime.Now or DepatureDate if that is not null. For some reason this seems ugly. Should I put the DateTime enumerator inside by Equipment object? It feels like this should all be together or done in some different manner, though this does work if I run it. Suggestions?