public ViewCategory GetCategoriesByGroupID(string GroupId) { DaoAsset daoAsset = new DaoAsset(context); ViewCategory result = new ViewCategory(); result.lsSubCategory = context.Category.AsNoTracking().Where(p => p.Active == true && p.ParentId.Equals("0") && p.CategoryType.Equals(GroupId)) .Include(p => p.EavAttributeValue).ThenInclude(x => x.Eav).AsEnumerable().ToList(); result.lsSubCategory.ForEach(e => { e.CountAsset = context.EavAttributeValue.Where(p => p.EavId.Equals(e.CategoryId) && p.Active == true).Count(); e.CountSubCategory = context.Category.Where(p => p.ParentId.Equals(e.CategoryId) && p.Active == true).Count(); }); result.countSubCategory = result.lsSubCategory.Count(); return(result); }
public ViewCategory GetCategoriesByID(string CategoryId) { DaoAsset daoAsset = new DaoAsset(context); ViewCategory result = new ViewCategory(); result.Category = context.Category.AsNoTracking().Where(p => p.Active == true && p.CategoryId.Equals(CategoryId)).AsEnumerable().FirstOrDefault(); result.lsSubCategory = context.Category.AsNoTracking().Where(p => p.Active == true && p.ParentId.Equals(CategoryId)).OrderBy(p => p.No) //.Include(p => p.EavAttributeValue) //.ThenInclude(x => x.Eav).AsEnumerable() .ToList(); result.lsSubCategory.ForEach(e => { e.CountAsset = context.EavAttributeValue.Where(p => p.EavId.Equals(e.CategoryId) && p.Active == true).Count(); e.CountSubCategory = context.Category.Where(p => p.ParentId.Equals(e.CategoryId) && p.Active == true).Count(); }); result.lsAsset = daoAsset.GetAssetByCategoryId(CategoryId); result.countAsset = result.lsAsset.Count() + result.lsSubCategory.Sum(p => p.CountAsset); result.countSubCategory = result.lsSubCategory.Count(); return(result); }