public List <ArticleCategoryMostUsed> GetListCategoryMostUsedSort(int parent, string search = "") { var result = _dBtsics.ArticleCategory .Where(p => p.Parent == parent && p.Status == 1 && p.Name.Contains(search)); List <ArticleCategoryMostUsed> FinalResult = new List <ArticleCategoryMostUsed>(); foreach (var item in result) { ArticleCategoryMostUsed articlecategory = new ArticleCategoryMostUsed { ArticleCategoryId = item.ArticleCategoryId, Name = item.Name, CreatedAt = item.CreatedAt, Parent = item.Parent, Icon = item.Icon, Status = item.Status, CountUsed = _dBtsics.Article.Where(c => c.Category1Id.Equals(item.ArticleCategoryId) || c.Category2Id.Equals(item.ArticleCategoryId) || c.Category3Id.Equals(item.ArticleCategoryId) || c.Category4Id.Equals(item.ArticleCategoryId) || c.Category5Id.Equals(item.ArticleCategoryId) || c.Category6Id.Equals(item.ArticleCategoryId) || c.Category7Id.Equals(item.ArticleCategoryId)).Count(), Subcategory = _dBtsics.ArticleCategory.Where(p => p.Parent == item.ArticleCategoryId && p.Status == 1).Count(), Position = item.Position }; FinalResult.Add(articlecategory); } FinalResult = FinalResult.OrderBy(c => c.Position).ToList(); return(FinalResult); }
public List <ArticleCategoryMostUsed> GetListCategoryMostUsedLiterature(int parent) { var result = _dBtsics.ArticleCategory .Where(p => p.Parent == parent && p.Status == 1); List <ArticleCategoryMostUsed> FinalResult = new List <ArticleCategoryMostUsed>(); foreach (var item in result) { ArticleCategoryMostUsed articlecategory = new ArticleCategoryMostUsed { ArticleCategoryId = item.ArticleCategoryId, Name = item.Name, CreatedAt = item.CreatedAt, Parent = item.Parent, Icon = item.Icon, Status = item.Status, Position = item.Position, CountUsed = _dBtsics.Article.Where(s => s.Type.Equals(1) && (s.Category1Id.Equals(item.ArticleCategoryId) && s.Category2Id == 0 && s.Category3Id == 0 && s.Category4Id == 0 && s.Category5Id == 0 && s.Category6Id == 0 && s.Category7Id == 0 || s.Category2Id.Equals(item.ArticleCategoryId) && s.Category3Id == 0 && s.Category4Id == 0 && s.Category5Id == 0 && s.Category6Id == 0 && s.Category7Id == 0 || s.Category3Id.Equals(item.ArticleCategoryId) && s.Category4Id == 0 && s.Category5Id == 0 && s.Category6Id == 0 && s.Category7Id == 0 || s.Category4Id.Equals(item.ArticleCategoryId) && s.Category5Id == 0 && s.Category6Id == 0 && s.Category7Id == 0 || s.Category5Id.Equals(item.ArticleCategoryId) && s.Category6Id == 0 && s.Category7Id == 0 || s.Category6Id.Equals(item.ArticleCategoryId) && s.Category7Id == 0 || s.Category7Id.Equals(item.ArticleCategoryId))).Where(s => s.Status == 1).Count() }; FinalResult.Add(articlecategory); } FinalResult = FinalResult.OrderBy(c => c.Position).ToList(); return(FinalResult); }