using System.Collections.Generic; using System.Linq; using JXCMS.CMS.Movie.Entity; using JXCMS.Core.Extensions; namespace JXCMS.CMS.Movie.Utils { public static class Classify { public static List FindAllChildren(List classifyEntities, int baseId, bool includeSelf = true) { var returnValue = new List(); if (includeSelf) { returnValue.AddRange(classifyEntities.Where(x => x.Id == baseId)); } var classifyEntityList = classifyEntities.Where(x => x.ParentId == baseId).ToList(); returnValue.AddRange(classifyEntityList); foreach (var classifyEntity in classifyEntityList) { returnValue.AddRange(FindAllChildren(classifyEntities, classifyEntity.Id, false)); } return returnValue; } public static List FindAllNotChildren(List classifyEntities, int baseId) { var children = FindAllChildren(classifyEntities, baseId, true); return classifyEntities.Where(x => !children.Contains(x)).ToList(); } public static List Structured(List classifyEntities, int baseId = 0, int hierarchy = 0) { var returnValue = new List(); var classifyEntityList = classifyEntities.Where(x => x.ParentId == baseId).ToList(); foreach (var classifyEntity in classifyEntityList) { classifyEntity.Name = classifyEntity.Name.InsertMultipleString("-", hierarchy * 2); returnValue.Add(classifyEntity); returnValue.AddRange(Structured(classifyEntities, classifyEntity.Id, hierarchy + 1)); } return returnValue; } } }