Ejemplo n.º 1
0
        public JsonResult GetAllPushTag()
        {
            var pushTags = new PushManager().GetAllPushTag();

            var tagLevel = new List <TagModel>();

            if (pushTags != null && pushTags.Any())
            {
                var firstLevels = pushTags.Select(x => x.FirstLevel).Distinct();

                foreach (var first in firstLevels)
                {
                    var firstLevelTag = new TagModel();
                    firstLevelTag.name = first;
                    tagLevel.Add(firstLevelTag);
                    var secondLevels = pushTags.Where(x => x.FirstLevel == first).Select(x => x.SecondLevel).Distinct();

                    foreach (var second in secondLevels)
                    {
                        var secondLevelTag = new TagModel();
                        secondLevelTag.name = second;
                        firstLevelTag.children.Add(secondLevelTag);
                        var tags = pushTags.Where(x => x.SecondLevel == second).Select(x => new { x.TagName, x.Description }).Distinct();

                        foreach (var tag in tags)
                        {
                            var thirdLevelTag = new TagModel();
                            thirdLevelTag.name = tag.Description;
                            thirdLevelTag.key  = tag.TagName;
                            secondLevelTag.children.Add(thirdLevelTag);
                        }
                    }
                }
            }

            return(Json(tagLevel));
        }