I have an abstract class with 3 other classes that inherit from this class:-
public abstract class AbstractTask
{
[Key]
public int ID {get; set;}
[DisplayName("Featured Task")]
public bool Featured { get; set; }
// various other properties
}
public class HighLevelTask : AbstractTask
{
[DisplayName("Workstream Description")]
public String Workstream { get; set; }
public virtual ICollection<MidLevelTask> MidLevelTasks { get; set; }
}
public class MediumLevelTask : AbstractTask
{
public int HighLevelTaskID { get; set; }
public virtual ICollection<DetailLevelTask> DetailLevelTasks { get; set; }
}
public class DetailLevelTask : AbstractTask
{
public int MidLevelTaskID { get; set; }
}
So a High Level task can contain any number of Mid Level tasks and a Mid level task can contain any number of Detail tasks. Tasks at any level can be set as 'Featured' by the property inherited from the abstract class.
In a HTML view I want to present a nested list of the 'featured' tasks. So I am thinking in a Controller action something like this to collect all the featured tasks but am at a mental block on the best way to present this.
var qryHighLevelTasks = from t in context.HighLevelTasks
where t.Featured == true
select t;
var rsHighLevelTasks = qryHighLevelTasks.ToList();
foreach(var highLevelTask in rsHighLevelTasks)
{
// get all mid level featured tasks related to this high level task
var qryMidTasks = from midLevelTasks in context.MidLevelTasks
where midLevelTasks.Featured == true
&& midLevelTasks.HighLevelTaskID == highLevelTask.ID
select midLevelTasks;
var rsMidLevelTasks = qryMidTasks.ToList();
foreach (var midLevelTask in rsMidLevelTasks)
{
// get all detail level featured tasks related to this mid level task
var qryDetailTasks = from detailLevelTasks in context.DetailLevelTasks
where detailLevelTasks.Featured == true
&& detailLevelTasks.MidLevelTaskID == midLevelTask.ID
select detailLevelTasks;
var rsDetailLevelTasks = qryDetailTasks.ToList();
}
}
Perhaps I should have a composite model to represent the featured tasks? Or is there a better way? Any recommendations?