public ActionResult GetGridJson(ArticleCateSearchView searchView, int page = 1) { var data = _ArticleCategoryService.GetCateList(searchView, page, PageSize); //取出分类 var parentIds = data.Where(w => w.ParentId != null).Select(u => u.ParentId).Distinct().ToArray(); Dictionary <string, string> cateDictory = new Dictionary <string, string>(); if (parentIds.Any()) { cateDictory = _ArticleCategoryService.GetCates(parentIds, true).ToDictionary(k => k.Code, v => v.Text); } if (data.Any()) { data.ForEach(cate => { if (cateDictory.Any() && !cate.ParentId.IsEmpty()) { cate.Category = cateDictory.TryGetValue(cate.ParentId); } }); } return(Content(new { rows = data, total = data.PageCount, page = data.PageIndex, records = data.TotalCount }.ToJson())); }
/// <summary> /// 获取文章分类 /// </summary> /// <param name="parentId"></param> /// <returns></returns> public List <ListItem> GetArticleCateList(IArticleCategoryService articleCategoryService, string currentId, string parentId, bool containsChild = false) { if (articleCategoryService == null) { articleCategoryService = CoreContextProvider.GetService <IArticleCategoryService>(); } return(articleCategoryService.GetCateList(currentId, parentId, containsChild)); }
public IActionResult Index([FromServices] IArticleTopicService topicService, [FromServices] IArticleCategoryService articleCategoryService) { AddPageCrumbs("资源分类"); var cateList = articleCategoryService.GetCateList(null, null, true); //var topicService = SkyCore.GlobalProvider.CoreContextProvider.GetService<IArticleTopicService>(); ViewBag.TopicCates = topicService.GetTopicCateList(null, null); ViewBag.HotTopics = topicService.GetTopicInfoList(new ArticleTopicSearchView { HotTopic = true, TopicStatus = TopicStatus.Audited, IgnoreCate = true }, 1, 3); return(View(cateList)); }
//首页 public IActionResult Index([FromServices] IArticleTopicService articleTopicService, [FromServices] IHelpService helpService, [FromServices] INewsService newsService , [FromServices] ILinkService linkService, [FromServices] IArticleCategoryService articleCategoryService) { ViewBag.TodayArticles = _ArticleService.GetTopArticles(ArticleTopEnum.HotArticle, 10); ViewBag.NewArticles = _ArticleService.GetTopArticles(ArticleTopEnum.NewArticle, 10); ViewBag.HotTopics = articleTopicService.GetHotTopics(8); ViewBag.BestCates = articleCategoryService.GetCateList(new ArticleCateSearchView { IsRemmand = true }, 1, 6); var tradeScores = _IMemberScoreService.GetList(true, 5); ViewBag.TradeScores = tradeScores; //PPT ViewBag.HotPPT = _ArticleService.GetTopArticles(ArticleTopEnum.HotPPT, 18, null); ViewBag.NewPPT = _ArticleService.GetTopArticles(ArticleTopEnum.NewPPT, 18, null); //轮播图 ViewBag.HomeCarousels = helpService.GetHelps(new HelpSearchView() { HelpCode = HelpCode.HomeCarousel }, 1, 10).ToList(); //公告 ViewBag.Announcements = newsService .GetTopNewss(NewsTopEnum.Announcement, 5).ToList(); //资源总数量 var totalData = _ArticleService.GetTotalBooks(); ViewBag.TotalBooks = totalData; //友情链接 ViewBag.FriendLinks = linkService.GetList(); return(View()); }
/// <summary> /// 分类下文库统计 /// </summary> /// <param name="userId"></param> /// <returns></returns> public List <ListItem> GetBookStatics(string userId) { //所有分类 var list = _IArticleCategoryService.GetCateList(null, null, false); //用户相关文库 var expression = GetFilterEnabled(); expression = expression.And(w => w.MemberId == userId); var articleCateStatics = _Respository.GetFeilds(u => new { Category = u.ArticleCategory.Title, ArticleId = u.Id, u.ArticleCategory.ParentId }, expression, o => o.OrderBy(b => b.CreatorTime), "ArticleCategory").Select(u => new ListItem { Text = u.Category, ParentId = u.ParentId, Code = u.ArticleId }).ToList(); var parentIds = articleCateStatics.Where(u => u.ParentId != null).Select(u => u.ParentId).ToArray(); if (parentIds.Any())//取出父级类别名 { var dics = _IArticleCategoryService.GetCates(parentIds).ToDictionary(k => k.Code, v => v.Text); articleCateStatics.ForEach(cate => { if (!cate.ParentId.IsEmpty()) { cate.Text = dics.TryGetValue(cate.ParentId); } }); } var staticsTictionary = articleCateStatics.Where(w => !w.Text.IsEmpty()).GroupBy(g => g.Text).Select(u => new { u.Key, Count = u.Count() }).ToDictionary(k => k.Key, v => v.Count); list.ForEach(data => { data.Code = "0"; if (staticsTictionary.Any(w => w.Key == data.Text)) { data.Code = staticsTictionary.TryGetValue(data.Text) + ""; } }); return(list); }