protected void PrepareCategories(Dictionary <int, CategoryCached> categories) { foreach (var category in categories.Values) { category.Init1ParentAndSub(categories); } _rootCategory = categories[1]; var categoriesList = _rootCategory.Init2AllSub(); categoriesList.Insert(0, _rootCategory); foreach (var category in categoriesList) { category.Init3ISectionType(_allSectionTypes); } _rootCategory.Init4InitSectionsRoots(); _rootCategory.Init5PreparePaths(); foreach (var category in categoriesList) { category.Init6SetListsAndBlockEditable(); } _allCategories = categoriesList.ToImmutableDictionary(x => x.NameNormalized); }
protected void PrepareCategories(Dictionary <int, CategoryCached> categories) { foreach (var category in categories.Values) { category.Init1ParentAndSub(categories); } _rootCategory = categories.Values.FirstOrDefault(x => x.Name == Category.RootName); if (_rootCategory == null) { throw new Exception($"Can not find category '{Category.RootName}' in data base."); } var categoriesList = _rootCategory.Init2AllSub(); categoriesList.Insert(0, _rootCategory); _rootCategory.Init3InitSectionsRoots(); foreach (var category in categoriesList) { category.Init4SetListsAndBlockEditable(); } _allCategoriesByName = categoriesList.ToImmutableDictionary(x => x.NameNormalized, StringComparer.OrdinalIgnoreCase); _allCategoriesById = _allCategoriesByName.ToImmutableDictionary(x => x.Value.Id, x => x.Value); }
public void Initialize() { using var db = dataBaseFactory.CreateDb(); var categories = db.Categories.Where(x => x.DeletedDate == null).Select(x => new CategoryCached(x)) .ToDictionary(x => x.Id); foreach (var category in categories.Values) { category.Init1ParentAndSub(categories); } RootCategory = categories.Values.FirstOrDefault(x => x.Name == Category.RootName); if (RootCategory == null) { throw new Exception($"Can not find category '{Category.RootName}' in data base."); } var categoriesList = RootCategory.Init2AllSub(); categoriesList.Insert(0, RootCategory); RootCategory.Init3InitSectionsRoots(); foreach (var category in categoriesList) { category.Init4SetListsAndBlockEditable(); } AllCategoriesByName = categoriesList.ToImmutableDictionary(x => x.NameNormalized, StringComparer.OrdinalIgnoreCase); AllCategoriesById = AllCategoriesByName.ToImmutableDictionary(x => x.Value.Id, x => x.Value); }