List myList = new List
{
new Users{ Name="Kumar", Gender="M", Age=75, Parent="All"},
new Users{ Name="Suresh",Gender="M", Age=50, Parent="Kumar"},
new Users{ Name="Bennette", Gender="F",Age=45, Parent="Kumar"},
new Users{ Name="kian", Gender="M",Age=20, Parent="Suresh"},
new Users{ Name="Nathani", Gender="M",Age=15, Parent="Suresh"},
new Users{ Name="Peter", Gender="M",Age=90, Parent="All"},
new Users{ Name="Mica", Age=56, Gender="M",Parent="Peter"},
new Users{ Name="Linderman", Gender="M",Age=51, Parent="Peter"},
new Users{ Name="john", Age=25, Gender="M",Parent="Mica"},
new Users{ Name="tom", Gender="M",Age=21, Parent="Mica"},
new Users{ Name="Ando", Age=64, Gender="M",Parent="All"},
new Users{ Name="Maya", Age=24, Gender="M",Parent="Ando"},
new Users{ Name="Niki Sanders", Gender="F",Age=2, Parent="Maya"},
new Users{ Name="Angela Patrelli", Gender="F",Age=3, Parent="Maya"},
};
now i need to format the data like
here i need to check the parent based on the parent i will be creating objects under the parent objects
now { Name="Kumar", Gender="M", Age=75, Parent="All" } this is the top level as a property Parent ="all" now under parent object kumar
here we again create a new object to store these information under object(kumar who is the parent)
new Users{ Name="Suresh",Gender="M", Age=50, Parent="Kumar"},
new Users{ Name="Bennette", Gender="F",Age=45, Parent="Kumar"},
what i need to do here is i need to check the parent based on the parent create further objects under it
ex: i need to achive like this. looking for the syntax how i can do it.
public class SampleProjectData
{
public static ObservableCollection<Product> GetSampleData()
{
DateTime dtS = DateTime.Now;
ObservableCollection<Product> teams = new ObservableCollection<Product>();
teams.Add(new Product() { PDName = "Product1", OverallStartTime = dtS, OverallEndTime = dtS + TimeSpan.FromDays(3), });
Project emp = new Project() { PName = "Project1", OverallStartTime = dtS + TimeSpan.FromDays(1), OverallEndTime = dtS + TimeSpan.FromDays(6) };
emp.Tasks.Add(new Task() { StartTime = dtS, EndTime = dtS + TimeSpan.FromDays(2), TaskName = "John's Task 3" });
emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(3), EndTime = dtS + TimeSpan.FromDays(4), TaskName = "John's Task 2" });
teams[0].Projects.Add(emp);
emp = new Project() { PName = "Project2", OverallStartTime = dtS + TimeSpan.FromDays(1.5), OverallEndTime = dtS + TimeSpan.FromDays(5.5) };
emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(1), EndTime = dtS + TimeSpan.FromDays(4), TaskName = "Victor's Task" });
teams[0].Projects.Add(emp);
emp = new Project() { PName = "Project3", OverallStartTime = dtS + TimeSpan.FromDays(2), OverallEndTime = dtS + TimeSpan.FromDays(5) };
emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(1), EndTime = dtS + TimeSpan.FromDays(4), TaskName = "Jason's Task 1" });
emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(7), EndTime = dtS + TimeSpan.FromDays(9), TaskName = "Jason's Task 2" });
teams[0].Projects.Add(emp);
teams.Add(new Product() { PDName = "Product2", OverallStartTime = dtS, OverallEndTime = dtS + TimeSpan.FromDays(3) });
emp = new Project() { PName = "Project4", OverallStartTime = dtS + TimeSpan.FromDays(0.5), OverallEndTime = dtS + TimeSpan.FromDays(3.5) };
emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(1.5), EndTime = dtS + TimeSpan.FromDays(4), TaskName = "Vicky's Task" });
teams[1].Projects.Add(emp);
emp = new Project() { PName = "Project5", OverallStartTime = dtS + TimeSpan.FromDays(2), OverallEndTime = dtS + TimeSpan.FromDays(6) };
emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(2.2), EndTime = dtS + TimeSpan.FromDays(3.8), TaskName = "Oleg's Task 1" });
emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(5), EndTime = dtS + TimeSpan.FromDays(6), TaskName = "Oleg's Task 2" });
emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(8), EndTime = dtS + TimeSpan.FromDays(9.6), TaskName = "Oleg's Task 3" });
teams[1].Projects.Add(emp);
emp = new Project() { PName = "Project6", OverallStartTime = dtS + TimeSpan.FromDays(2.5), OverallEndTime = dtS + TimeSpan.FromDays(4.5) };
emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(0.8), EndTime = dtS + TimeSpan.FromDays(2), TaskName = "Kim's Task" });
teams[1].Projects.Add(emp);
teams.Add(new Product() { PDName = "Product3", OverallStartTime = dtS, OverallEndTime = dtS + TimeSpan.FromDays(3) });
emp = new Project() { PName = "Project7", OverallStartTime = dtS + TimeSpan.FromDays(5), OverallEndTime = dtS + TimeSpan.FromDays(7.5) };
emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(1.5), EndTime = dtS + TimeSpan.FromDays(4), TaskName = "Balaji's Task 1" });
emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(5), EndTime = dtS + TimeSpan.FromDays(8), TaskName = "Balaji's Task 2" });
teams[2].Projects.Add(emp);
emp = new Project() { PName = "Project8", OverallStartTime = dtS + TimeSpan.FromDays(3), OverallEndTime = dtS + TimeSpan.FromDays(6.3) };
emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(1.75), EndTime = dtS + TimeSpan.FromDays(2.25), TaskName = "Li's Task" });
teams[2].Projects.Add(emp);
emp = new Project() { PName = "Project9", OverallStartTime = dtS + TimeSpan.FromDays(2), OverallEndTime = dtS + TimeSpan.FromDays(6) };
emp.Tasks.Add(new Task() { StartTime = dtS + TimeSpan.FromDays(2), EndTime = dtS + TimeSpan.FromDays(3), TaskName = "Stacy's Task" });
teams[2].Projects.Add(emp);
return teams;
}
}
above is an sample data where i am grouping them with static data in the same way i need **to for teh data which is cmg from DB and i need to store them list**
all these three data are comig from different services. and i am storing them in a list
now i have three tables data
Product ,
Project,
Task.
all the data are coming from webservies.
i have created three list where i am storing the data in list.
List<Project>objpro= new List<Project>();
List<Product>objproduct= new List<Product>();
LIst<Task>objTask= new List<Task>();
**now what i need to do is i need to do the mapping between these tables.
if you see above. i have object of Product under Product i have added object of Project
and then under project object i have added task object.**
now from the above data which is stored in the list i need to do the same mapping between class.
and group the data.
public class Product : INotifyPropertyChanged
{
public Product()
{
this.Projects = new ObservableCollection<Project>();
}
public string PDName { get; set; }
public ObservableCollection<Project> Projects { get; set; }
private DateTime _st;
public DateTime OverallStartTime
{
get { return _st; }
set
{
if (this._st != value)
{
TimeSpan dur = this._et - this._st;
this._st = value;
this.OnPropertyChanged("OverallStartTime");
this.OverallEndTime = value + dur;
}
}
}
private DateTime _et;
public DateTime OverallEndTime
{
get { return _et; }
set
{
if (this._et != value)
{
this._et = value;
this.OnPropertyChanged("OverallEndTime");
}
}
}
#region INotifyPropertyChanged Members
protected void OnPropertyChanged(string name)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(name));
}
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}
public class Project : INotifyPropertyChanged
{
public Project() { this.Tasks = new ObservableCollection<Task>(); }
public string PName { get; set; }
public ObservableCollection<Task> Tasks { get; set; }
DateTime _st;
public DateTime OverallStartTime
{
get { return _st; }
set
{
if (this._st != value)
{
TimeSpan dur = this._et - this._st;
this._st = value;
this.OnPropertyChanged("OverallStartTime");
this.OverallEndTime = value + dur;
}
}
}
DateTime _et;
public DateTime OverallEndTime
{
get { return _et; }
set
{
if (this._et != value)
{
this._et = value;
this.OnPropertyChanged("OverallEndTime");
}
}
}
#region INotifyPropertyChanged Members
protected void OnPropertyChanged(string name)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(name));
}
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}
public class Task : INotifyPropertyChanged
{
public string TaskName { get; set; }
DateTime _st;
public DateTime StartTime
{
get { return _st; }
set
{
if (this._st != value)
{
TimeSpan dur = this._et - this._st;
this._st = value;
this.OnPropertyChanged("StartTime");
this.EndTime = value + dur;
}
}
}
private DateTime _et;
public DateTime EndTime
{
get { return _et; }
set
{
if (this._et != value)
{
this._et = value;
this.OnPropertyChanged("EndTime");
}
}
}
#region INotifyPropertyChanged Members
protected void OnPropertyChanged(string name)
{
if (this.PropertyChanged != null)
this.PropertyChanged(this, new PropertyChangedEventArgs(name));
}
public event PropertyChangedEventHandler PropertyChanged;
#endregion
}
hope my question is clear