private List<Year> getCons(List<Convention> completeConList) { int index; Month month; List<Month> months2015 = new List<Month>(); List<Month> months2016 = new List<Month>(); years = new List<Year>(); foreach (Convention con in completeConList) { switch(con.year) { case "2015": month = new Month(); month.Name = con.month; index = months2015.FindIndex(item => item.Name == month.Name); if(index < 0) { month.Items = setConventions(month, completeConList); months2015.Add(month); } break; case "2016": month = new Month(); month.Name = con.month; index = months2016.FindIndex(item => item.Name == month.Name); if (index < 0) { month.Items = setConventions(month, completeConList); months2016.Add(month); } break; } } Year year2015 = new Year(); year2015.Name = "2015"; year2015.months = months2015; Year year2016 = new Year(); year2016.Name = "2016"; year2016.months = months2016; years.Add(year2015); years.Add(year2016); return years; }
private List<Convention> setConventions(Month month, List<Convention> completeConList) { List<Convention> cons = new List<Convention>(); foreach(Convention con in completeConList) { if(con.month.Equals(month.Name)) { cons.Add(con); } } return cons; }