private RecordHierarchy GetHierarchyRecords( IList<IDictionary<string, object>> records, EntityHierarchy hierarchy) { var baseRecord = records.FirstOrDefault(); var prefix = hierarchy.Alias.Undecorate() + "_"; var rowData = new DataRow(baseRecord, hierarchy.Entity, prefix); var recordHierarchy = new RecordHierarchy { Entity = hierarchy.Entity, KeyValue = rowData.KeyValue, DisplayName = rowData.ToString(hierarchy.Entity), SubRecordsHierarchies = new List<RecordHierarchy>() }; GetHierarchyRecords(recordHierarchy, records, hierarchy.SubHierarchies); return recordHierarchy; }
private void GetHierarchyRecords( RecordHierarchy parentHierarchy, IList<IDictionary<string, object>> records, IEnumerable<EntityHierarchy> subHierarchies, IList<string> foreignKey = null, IList<string> foreignKeyValue = null) { foreach (var hierarchy in subHierarchies) { var prefix = hierarchy.Alias.Undecorate() + "_"; foreach (var record in records) { var rowData = new DataRow(record, hierarchy.Entity, prefix); if (!rowData.KeyValue.IsNullOrEmpty()) { var subRecord = new RecordHierarchy { Entity = hierarchy.Entity, KeyValue = rowData.KeyValue, DisplayName = rowData.ToString(hierarchy.Entity), SubRecordsHierarchies = new List<RecordHierarchy>() }; if (parentHierarchy.SubRecordsHierarchies.FirstOrDefault(x => x.JoinedKeyValue == subRecord.JoinedKeyValue) == null && Matching(record, foreignKey, foreignKeyValue)) { parentHierarchy.SubRecordsHierarchies.Add(subRecord); GetHierarchyRecords( subRecord, records, hierarchy.SubHierarchies, hierarchy.Entity.Key.Select(x => prefix + x.Column.Undecorate()).ToList(), rowData.KeyValue); } } } } }