public GroupDTOList ToViewModel(List <GroupDTO> groups = null) { GroupDTOList gdtolist = new GroupDTOList(); if (groups == null) { groups = this; return(ToViewModel(groups)); } else { groups = groups.OrderByDescending(g => g.Index).ToList(); groups.ForEach(g => { GroupDTO dto = new GroupDTO(); dto.CreateDate = g.CreateDate; dto.Creator = g.Creator; dto.Description = g.Description; dto.EditDate = g.EditDate; dto.ID = g.ID.ToString(); dto.Name = g.Name; dto.ParentID = g.ParentID; dto.ParentName = g.ParentName; dto.Status = (Wings.DataObjects.Status)g.Status; dto.Index = g.Index; if (g.ChildGroup != null && g.ChildGroup.Count > 0) { dto.ChildGroup = this.ToViewModel(g.ChildGroup); } gdtolist.Add(dto); }); } return(gdtolist); }
/// <summary> /// 转换为友好显示树形结构 /// </summary> /// <param name="groupdtolist"></param> /// <returns></returns> public List <Tree> ToTree(GroupDTOList groupdtolist = null) { List <Tree> trees = new List <Tree>(); if (groupdtolist == null) { groupdtolist = this; } if (groupdtolist.Count == 0) { return(null); } groupdtolist.OrderByDescending(g => g.Index).ToList().ForEach(g => { Tree tree = new Tree(); tree.id = g.ID.ToString(); tree.text = g.Name; if (g.ChildGroup != null && g.ChildGroup.Count > 0) { tree.children = ToTree((GroupDTOList)g.ChildGroup); } trees.Add(tree); }); return(trees); }