private List <CategoryJsonModel> GetArticleCate() { List <CategoryJsonModel> articleCate = new List <CategoryJsonModel>(); #region 文章分类 var categories = _iArticleCategoryService.GetCategories().ToArray(); foreach (var main in categories.Where(s => s.ParentCategoryId == 0)) { var topC = new CategoryJsonModel() { Name = main.Name, Id = main.Id.ToString(), SubCategory = new List <SecondLevelCategory>() }; foreach (var secondItem in categories.Where(s => s.ParentCategoryId == main.Id)) { var secondC = new SecondLevelCategory() { Name = secondItem.Name, Id = secondItem.Id.ToString(), }; topC.SubCategory.Add(secondC); } articleCate.Add(topC); } return(articleCate); #endregion }
public JsonResult List(long?categoryId, string titleKeyWords, int rows, int page, string Sort, bool?isAsc) { var articles = _iArticleService.Find(categoryId, titleKeyWords, rows, page, Sort: Sort, isAsc: isAsc); string host = CurrentUrlHelper.CurrentUrl(); string urltmp = string.Format(@"{0}{1}/", host, Url.Action("Details", "Article", new { Area = "Web" })); ////如果未开启PC端授权,则只保留平台公告分类数据(FG:无平台公告分类) //if (!SiteSettingApplication.SiteSettings.IsOpenPC ) //{ // articles.Models.RemoveAll(p => !p.ArticleCategoryInfo.Name.Contains("平台公告")); //} var categories = _iArticleCategoryService.GetCategories(); var articleModels = articles.Models.Select(item => new { id = item.Id, categoryId = item.CategoryId, categoryName = categories.FirstOrDefault(p => p.Id == item.CategoryId)?.Name ?? string.Empty, isShow = item.IsRelease, title = item.Title, displaySequence = item.DisplaySequence, showurl = urltmp + item.Id.ToString(), addDate = item.AddDate.ToString("yyyy-MM-dd HH:mm:ss") }); var data = new { rows = articleModels, total = articles.Total }; return(Json(data)); }