Exemple #1
0
        public static List <BlogCategoryView> GetBlogCategoryTree()
        {
            var context = new ApplicationDbContext();
            List <BlogCategoryView> topics = new List <BlogCategoryView>();
            Stack <BlogCategory>    topicQ = new Stack <BlogCategory>();
            var firstLevels = context.BlogCategories.Where(x => x.Level == 0).ToList();

            foreach (BlogCategory top in firstLevels)
            {
                topicQ.Push(top);
            }

            while (topicQ.Count > 0)
            {
                var current = topicQ.Pop();
                topics.Add(ModelConverter.BlogCategoryToView(current));
                foreach (var child in current.Childs)
                {
                    topicQ.Push(child);
                }
            }
            return(topics);
        }
Exemple #2
0
        public static List <BlogCategoryView> GetAllBlogCategories()
        {
            List <BlogCategory> categories = DBHelper.GetAllBlogCategories();

            return(categories.Select(x => ModelConverter.BlogCategoryToView(x)).ToList());
        }