Beispiel #1
0
        public async Task <CategoryAdminView> GetAllCategoriesAsync()
        {
            var categories = await db.Categories.Where(x => x.DeletedDate == null)
                             .OrderBy(x => x.SortNumber).Select(x => new CategoryAdminView
            {
                Id    = x.Id,
                Name  = x.Name,
                Token = x.Token,
                AppendTokenToSubCatsPath = x.AppendTokenToSubCatsPath,
                ShowInBreadcrumbs        = x.ShowInBreadcrumbs,
                Title                       = x.Title,
                SubTitle                    = x.SubTitle,
                Icon                        = x.Icon,
                IsMaterialsContainer        = x.IsMaterialsContainer,
                Header                      = x.Header,
                LayoutName                  = x.LayoutName,
                IsMaterialsNameEditable     = x.IsMaterialsNameEditable,
                IsMaterialsSubTitleEditable = x.IsMaterialsSubTitleEditable,
                ParentId                    = x.ParentId,
                SortNumber                  = x.SortNumber,
                MaterialsCount              = x.Materials.Count,
                IsHidden                    = x.IsHidden,
                IsCacheContent              = x.IsCacheContent,
                DeletedDate                 = x.DeletedDate,
                SettingsJson                = x.SettingsJson
            }).ToDictionaryAsync(x => x.Id);

            CategoryAdminView root = null;

            foreach (var category in categories.Values)
            {
                if (!category.ParentId.HasValue)
                {
                    root = category;
                    continue;
                }

                if (!categories.ContainsKey(category.ParentId.Value))
                {
                    continue;
                }

                var parent = categories[category.ParentId.Value];

                if (parent.SubCategories == null)
                {
                    parent.SubCategories = new List <CategoryAdminView>();
                }

                parent.SubCategories.Add(category);
            }

            return(root);
        }
Beispiel #2
0
        public async Task <CategoryAdminView> GetAllCategoriesAsync()
        {
            var categories = await db.Categories.Where(x => !x.IsDeleted)
                             .OrderBy(x => x.SortNumber).Select(x => new CategoryAdminView
            {
                Id                            = x.Id,
                Name                          = x.Name,
                Title                         = x.Title,
                SubTitle                      = x.SubTitle,
                Icon                          = x.Icon,
                IsMaterialsContainer          = x.IsMaterialsContainer,
                Header                        = x.Header,
                LayoutName                    = x.LayoutName,
                MaterialsPreviewGeneratorName = x.MaterialsPreviewGeneratorName,
                IsMaterialsNameEditable       = x.IsMaterialsNameEditable,
                MaterialsSubTitleInputType    = x.MaterialsSubTitleInputType,
                ParentId                      = x.ParentId,
                SortNumber                    = x.SortNumber,
                MaterialsCount                = x.Materials.Count,
                IsHidden                      = x.IsHidden,
                IsDeleted                     = x.IsDeleted,
                IsCacheContent                = x.IsCacheContent
            }).ToDictionaryAsync(x => x.Id);

            CategoryAdminView root = null;

            foreach (var category in categories.Values)
            {
                if (!category.ParentId.HasValue)
                {
                    root = category;
                    continue;
                }

                if (!categories.ContainsKey(category.ParentId.Value))
                {
                    continue;
                }

                var parent = categories[category.ParentId.Value];

                if (parent.SubCategories == null)
                {
                    parent.SubCategories = new List <CategoryAdminView>();
                }

                parent.SubCategories.Add(category);
            }

            return(root);
        }
        public async Task <CategoryAdminView> GetAllCategoriesAsync()
        {
            var categories = await db.Categories.LoadWith(x => x.SectionType).Where(x => !x.IsDeleted)
                             .OrderBy(x => x.SortNumber).Select(x => new CategoryAdminView
            {
                Id    = x.Id,
                Name  = x.Name,
                Title = x.Title,
                IsMaterialsContainer = x.IsMaterialsContainer,
                Description          = x.Description,
                Header          = x.Header,
                SectionTypeName = x.SectionType != null ? x.SectionType.Name : null,
                SectionType     = x.SectionType,
                AppendUrlToken  = x.AppendUrlToken,
                ParentId        = x.ParentId,
                SortNumber      = x.SortNumber,
                MaterialsCount  = x.Materials.Count,
                IsHidden        = x.IsHidden,
                IsDeleted       = x.IsDeleted,
                IsCacheContent  = x.IsCacheContent
            }).ToDictionaryAsync(x => x.Id);

            CategoryAdminView root = null;

            foreach (var category in categories.Values)
            {
                if (!category.ParentId.HasValue)
                {
                    root = category;
                    continue;
                }

                var parent = categories[category.ParentId.Value];
                if (parent.SubCategories == null)
                {
                    parent.SubCategories = new List <CategoryAdminView>();
                }

                parent.SubCategories.Add(category);
            }

            return(root);
        }