private async Task SetCatalogCategoryModel(int catalogTypeId) { //Catalog Categories var allCats = await _context.Categories .Include(x => x.Parent) .Include(x => x.CatalogTypes) .ToListAsync(); var catsId = allCats .Where(x => x.CatalogTypes.Any(ct => ct.CatalogTypeId == catalogTypeId)) .Select(x => x.Id) .ToList(); foreach (var item in allCats.Where(x => x.Parent == null).ToList()) { CatalogCategoryViewModel parent = new CatalogCategoryViewModel { CategoryId = item.Id, Label = item.Name, Childs = new List <CatalogCategoryViewModel>(), Selected = catsId.Contains(item.Id) }; parent.Childs.AddRange(allCats.Where(x => x.ParentId == item.Id).Select(s => new CatalogCategoryViewModel { CategoryId = s.Id, Label = s.Name, Selected = catsId.Contains(s.Id) })); CatalogCategoryModel.Add(parent); } }
private async Task SetCatalogCategoryModel() { //Catalog Categories var allCats = await _context.Categories .Include(x => x.Parent) .AsNoTracking() .ToListAsync(); foreach (var item in allCats.Where(x => x.Parent == null).ToList()) { var catalogCategory = ProductModel.Categories.SingleOrDefault(x => x.CategoryId == item.Id); CatalogCategoryViewModel parent = new CatalogCategoryViewModel { Id = catalogCategory?.Id ?? 0, CategoryId = item.Id, Label = item.Name, Selected = catalogCategory != null ? true : false, Childs = new List <CatalogCategoryViewModel>() }; parent.Childs.AddRange(allCats.Where(x => x.ParentId == item.Id).Select(s => new CatalogCategoryViewModel { Id = ProductModel.Categories.SingleOrDefault(x => x.CategoryId == s.Id)?.Id ?? 0, CategoryId = s.Id, Label = s.Name, Selected = ProductModel.Categories.Any(x => x.CategoryId == s.Id), })); CatalogCategoryModel.Add(parent); } }
internal void setCategoryCatalog(Enums.TYPE categoryType) { if (catalogCategoryVM == null) { catalogCategoryVM = new CatalogCategoryViewModel(categoryType); } else { catalogCategoryVM.OnCatalogChange(categoryType); } }
private async Task SetCatalogCategoryModel() { //Catalog Categories CatalogCategoryModel.Clear(); var allCats = await _context.Categories .Include(x => x.Parent) .ToListAsync(); foreach (var item in allCats.Where(x => x.Parent == null).ToList()) { CatalogCategoryViewModel parent = new CatalogCategoryViewModel { CategoryId = item.Id, Label = item.Name, Childs = new List <CatalogCategoryViewModel>() }; parent.Childs.AddRange(allCats.Where(x => x.ParentId == item.Id).Select(s => new CatalogCategoryViewModel { CategoryId = s.Id, Label = s.Name })); CatalogCategoryModel.Add(parent); } }