private void CreateGroupList() { List <BloodGroupModel> finalList = new List <BloodGroupModel>(); try { var nestedGroups = from p in MemberList.OrderByDescending(x => x.memBG) group p by p.memBG into yg select new { Year = yg.Key, BloodGroups = from o in yg group o by o.memBG into mg select new { bloodGroup = mg.Key, Items = mg.Select(x => x) } }; foreach (var groupedYear in nestedGroups) { var listMonth = groupedYear.BloodGroups.ToList(); for (int i = 0; i < listMonth.Count; i++) { var datesList = new List <DatesModel>(); string _group = listMonth[i].bloodGroup; //finalList[i] = new ItemModel{Text=month}; var listDates = listMonth[i].Items.ToList(); for (int j = 0; j < listDates.Count; j++) { string name = listDates[j].memName.ToString(); string mobile = listDates[j].memMobile.ToString(); //finalList[i].Dates[j] = new DatesModel {Text= name.ToString()}; datesList.Add(new DatesModel { memName = name, memMobile = mobile }); datesList = datesList.OrderBy(d => d.memName) .Select(x => x).ToList(); } finalList.Add(new BloodGroupModel { BloodGroup = _group, groupList = datesList, ListHeight = datesList.Count * 60 }); } } if (!ReferenceEquals(finalList, null)) { var sorted = finalList.OrderBy(d => d.BloodGroup) .Select(x => x).ToList(); foreach (var item in sorted) { //item.merrageAnyver = DateTime.Parse(item.merrageAnyver).ToString("M"); GroupList.Add(item); } } } catch (Exception ex) { } }
private void CreateGroupList() { List <AnniversaryModel> finalList = new List <AnniversaryModel>(); try { var nestedGroups = from p in MemberList.OrderByDescending(x => DateTime.Parse(x.merrageAnyver)) group p by DateTime.Parse(p.merrageAnyver).Month into yg select new { Year = yg.Key, Months = from o in yg group o by DateTime.Parse(o.merrageAnyver).Month into mg select new { Month = mg.Key, Items = mg.Select(x => x) } }; foreach (var groupedYear in nestedGroups) { var listMonth = groupedYear.Months.ToList(); for (int i = 0; i < listMonth.Count; i++) { var datesList = new List <DatesModel>(); string month = CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(listMonth[i].Month); int _date = listMonth[i].Month; //finalList[i] = new ItemModel{Text=month}; var listDates = listMonth[i].Items.ToList(); for (int j = 0; j < listDates.Count; j++) { string date = listDates[j].merrageAnyver.ToString(); string name = listDates[j].memName.ToString(); string mobile = listDates[j].memMobile.ToString(); //finalList[i].Dates[j] = new DatesModel {Text= name.ToString()}; datesList.Add(new DatesModel { merrageAnyver = DateTime.Parse(date).ToString("M"), memName = name, memMobile = mobile }); datesList = datesList.OrderBy(d => DateTime.Parse(d.merrageAnyver).Date) .Select(x => x).ToList(); } finalList.Add(new AnniversaryModel { month = month, date = _date, Dates = datesList, ListHeight = datesList.Count * 60 }); } } if (!ReferenceEquals(finalList, null)) { var sorted = finalList.OrderBy(d => d.date) .Select(x => x).ToList(); foreach (var item in sorted) { //item.merrageAnyver = DateTime.Parse(item.merrageAnyver).ToString("M"); GroupList.Add(item); } } } catch (Exception ex) { } }