public static TrialBalanceAsPerDetailViewModel AddNodesRecursively(TrialBalanceAsPerDetailViewModel ListContent, List <TrialBalanceAsPerDetailViewModel> MainList) { var current = MainList.Where(o => o.ParentLedgerAccountGroupId == ListContent.LedgerAccountGroupId && o.LedgerAccountGroupId != ListContent.LedgerAccountGroupId); foreach (var item in current) { var child = new TrialBalanceAsPerDetailViewModel(); child.LedgerAccountGroupId = item.LedgerAccountGroupId; child.LedgerAccountGroupName = item.LedgerAccountGroupName; child.AmtDr = item.AmtDr; child.AmtCr = item.AmtCr; child.Level = item.Level; child.ParentLedgerAccountGroupId = ListContent.LedgerAccountGroupId; child.ReportType = item.ReportType; if (ListContent.ChildTrialBalanceAsPerDetailViewModel == null) { ListContent.ChildTrialBalanceAsPerDetailViewModel = new List <TrialBalanceAsPerDetailViewModel>(); } ListContent.ChildTrialBalanceAsPerDetailViewModel.Add(child); if (item.LedgerAccountGroupId != ListContent.LedgerAccountGroupId) { AddNodesRecursively(child, MainList); } } return(ListContent); }
public static List <TrialBalanceAsPerDetailViewModel> GenerateTreeStructureForList(List <TrialBalanceAsPerDetailViewModel> MainList) { List <TrialBalanceAsPerDetailViewModel> RetLsit = new List <TrialBalanceAsPerDetailViewModel>(); foreach (var ListContent in MainList) { TempVar = ListContent; AddNodesRecursively(TempVar, MainList); if (ListContent.ParentLedgerAccountGroupId == null) { RetLsit.Add(ListContent); } TempVar = null; } return(RetLsit); }