/// <summary> /// 文章分页 /// </summary> /// <param name="keyword"></param> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <returns></returns> public PagedList <ArticleDetailView> GetTopicArticleList(ArticleSearchView searchView, int pageIndex = 1, int pageSize = 20) { var expression = GetFilterEnabled(); var orderpr = base.Order(); orderpr = o => o.OrderBy(t => t.CreatorTime); if (!searchView.SpecialTopicId.IsEmpty()) { expression = base.GetFilterEnabled(); expression = expression.And(t => t.SpecialTopicId == searchView.SpecialTopicId); } if (!string.IsNullOrEmpty(searchView.Keyword)) { expression = expression.And(t => t.Title.Contains(searchView.Keyword)); expression = expression.Or(t => t.Description.Contains(searchView.Keyword)); } return(_Respository.GetPagedList( u => new ArticleDetailView { Id = u.Id, Title = u.Title, ReadCount = u.ReadCount, ResourceType = u.ResourceType } , expression, pageIndex, pageSize, orderpr)); }
/// <summary> /// 首页 /// </summary> /// <param name="keyword"></param> /// <returns></returns> public IActionResult Index([FromQuery] ArticleSearchView search, int pageIndex = 1) { if (search == null) { search = new ArticleSearchView(); } var articles = _ArticleService.GetList(search, pageIndex, 1); var articlesView = articles.MapTo <PagedList <ArticleDetailView> >(); return(View(articlesView)); }
/// <summary> /// 文章分页 /// </summary> /// <param name="keyword"></param> /// <param name="pageSize"></param> /// <param name="pageIndex"></param> /// <returns></returns> public PagedList <Article> GetList(ArticleSearchView searchView, int pageIndex = 1, int pageSize = 20) { var expression = ExtLinq.True <Article>(); if (!string.IsNullOrEmpty(searchView.Keyword)) { expression = expression.And(t => t.Title.Contains(searchView.Keyword)); expression = expression.Or(t => t.Content.Contains(searchView.Keyword)); } //expression = expression.And(t => t.CategoryId == 2); return(_Respository.GetPagedList <Article>(expression, pageIndex, pageSize)); }
public ActionResult GetGridJson(ArticleSearchView searchView, int page = 1) { searchView.HasMember = true; var data = _ArticleService.GetBooks(searchView, page, PageSize); data.ForEach(da => { da.Description = RegexRegular.CheckMathLength(RegexRegular.NoHTML(da.Description), 20); }); return(Content(new { rows = data, total = data.PageCount, page = data.PageIndex, records = data.TotalCount }.ToJson())); }
public IActionResult Index([FromServices] IArticleCategoryService articleCategoryService, [FromQuery] ArticleSearchView search, int pageIndex = 1) { if (search == null) { search = new ArticleSearchView(); } search.BookStatus = (int)BookStatus.审核通过; ListItem cateInfo = new ListItem { Text = "全部" }; //所有分类 var allCateList = GetArticleCateList(articleCategoryService, null, null, true); ViewBag.CateList = allCateList; //cid参数 string cid = Request.Query["cid"]; if (!cid.IsEmpty()) { if (allCateList.Any(w => w.Code == cid)) { search.ParentCategoryId = cid; } else { search.CategoryId = cid; } } if (!search.ParentCategoryId.IsEmpty()) { cateInfo = allCateList.FirstOrDefault(w => w.Code == search.ParentCategoryId); } if (!search.CategoryId.IsEmpty()) { allCateList.ForEach(cate => { if (cate.Childs != null && cate.Childs.Any(w => w.Code == search.CategoryId)) { cateInfo = cate.Childs.FirstOrDefault(w => w.Code == search.CategoryId); } }); } //Keyword search.Keyword = Request.Query["q"]; //上架时间范围选择 if (search.OnShelfDays.HasValue) { switch (search.OnShelfDays.Value) { case 3: search.StartDate = DateTime.Now.AddDays(-3); break; case 7: search.StartDate = DateTime.Now.AddDays(-7); break; case 30: search.StartDate = DateTime.Now.AddDays(-30); break; case 365: search.StartDate = DateTime.Now.AddDays(-365); break; } } //key ViewBag.SearchKey = search.Keyword; //版权 ViewBag.CopyrightList = BusinessHelper.GetItemDictionary("Copyright"); //资源类型 ViewBag.ResourceTypeList = BusinessHelper.GetItemDictionary("ResourceType"); //CateBooksStaticModel //string categoryId, string parentCategoryId search.Articles = _ArticleService.GetBooks(search, pageIndex, PageSize); ViewBag.HotArticle = _ArticleService.GetTopArticles(ArticleTopEnum.HotArticle, PageSize); ViewBag.CateInfo = cateInfo; AddPageCrumbs(cateInfo == null?"搜索":cateInfo.Text); return(View(search)); }
public PagedList <ArticleDetailView> GetBooks(ArticleSearchView searchView, int pageIndex, int pageSize) { var expression = GetFilterEnabled(); var includeProperties = "ArticleCategory"; //if (!searchView.SpecialTopicId.IsEmpty()) //{ // includeProperties = ""; // expression = base.GetFilterEnabled(); // expression = expression.And(t => t.SpecialTopicId == searchView.SpecialTopicId); //} var orderpr = base.Order(); orderpr = o => o.OrderBy(t => t.CreatorTime); if (!string.IsNullOrEmpty(searchView.Keyword)) { expression = expression.And(t => t.Title.Contains(searchView.Keyword) || (!t.Description.IsEmpty() && t.Description.Contains(searchView.Keyword)) || (!t.Keyword.IsEmpty() && t.Keyword.Contains(searchView.Keyword))); } if (!searchView.Title.IsEmpty()) { expression = expression.And(t => t.Title.Contains(searchView.Title)); } if (!string.IsNullOrEmpty(searchView.MemberId)) { expression = expression.And(t => t.MemberId == searchView.MemberId); } if (!searchView.CategoryId.IsEmpty()) { expression = expression.And(t => t.CategoryId == searchView.CategoryId); } if (searchView.StartDate.HasValue) { expression = expression.And(t => t.CreatorTime >= searchView.StartDate); } if (searchView.EndDate.HasValue) { expression = expression.And(t => t.CreatorTime <= searchView.EndDate); } if (!searchView.ResourceType.IsEmpty()) { //资源类型多样化查询处理 if (searchView.ResourceType == "pdf" || searchView.ResourceType == "doc" || searchView.ResourceType == "docx" || searchView.ResourceType == "ppt" || searchView.ResourceType == "pptx") { expression = expression.And(t => t.ResourceType == searchView.ResourceType); } else if (searchView.ResourceType == "jpg") { expression = expression.And(t => ConfigManager.UploadAllowImgExtension.Contains(t.ResourceType)); } else if (searchView.ResourceType == "mp4") { expression = expression.And(t => ConfigManager.UploadAllowVideoExtension.Contains(t.ResourceType)); } else if (searchView.ResourceType == "mp3") { expression = expression.And(t => ConfigManager.UploadAllowVoiceExtension.Contains(t.ResourceType)); } else if (searchView.ResourceType == "swf") { expression = expression.And(t => ConfigManager.UploadAllowFlashExtension.Contains(t.ResourceType)); } } if (searchView.StartScore.HasValue) { expression = expression.And(t => t.RequireAmount > searchView.StartScore); } if (searchView.EndScore.HasValue) { expression = expression.And(t => t.RequireAmount <= searchView.EndScore); } if (searchView.StartPage.HasValue) { expression = expression.And(t => t.PageCount >= searchView.StartPage); } if (searchView.EndPage.HasValue) { expression = expression.And(t => t.PageCount <= searchView.EndPage); } //审核状态 if (searchView.BookStatus.HasValue) { expression = expression.And(t => t.BookStatus == searchView.BookStatus); } if (!searchView.SearchStatus.IsEmpty()) { if (searchView.SearchStatus == "0") { orderpr = o => o.OrderByDescending(b => b.CreatorTime); } if (searchView.SearchStatus == "1") { orderpr = o => o.OrderByDescending(b => b.DownloadCount); } if (searchView.SearchStatus == "2") { orderpr = o => o.OrderByDescending(b => b.ReadCount); } } //分类 if (!searchView.ParentCategoryId.IsEmpty()) { if (searchView.CategoryId.IsEmpty()) { expression = expression.And(t => t.ArticleCategory.ParentId == searchView.ParentCategoryId); } } if (!searchView.CategoryId.IsEmpty()) { expression = expression.And(t => t.CategoryId == searchView.CategoryId); } //expression = expression.And(t => t.CategoryId == 2); var data = _Respository.GetPagedList( u => new ArticleDetailView { Id = u.Id, Title = u.Title, CoverUrl = u.CoverUrl, ShortTitle = u.ShortTitle, Description = u.Description, Attachment = u.Attachment, CategoryId = u.CategoryId, Category = (u.ArticleCategory == null ? null : u.ArticleCategory.Title), ReadCount = u.ReadCount, DownloadCount = u.DownloadCount, ResourceUrl = u.ResourceUrl, CreatorTime = u.CreatorTime, ResourceSize = u.ResourceSize, RequireAmount = u.RequireAmount, BookStatus = u.BookStatus, AuditMessage = u.AuditMessage, ResourceType = u.ResourceType, MemberId = u.MemberId } , expression, pageIndex, pageSize, orderpr, includeProperties); if (data.Any() && searchView.HasMember.HasValue && searchView.HasMember == true) { var meberIds = data.Select(u => u.MemberId).Distinct().ToArray(); if (meberIds.Any()) { var memList = _IMemberRespository.GetFeilds(u => new { u.Id, u.UserName }, w => w.EnabledMark == true && meberIds.Contains(w.Id)).ToDictionary(k => k.Id, v => v.UserName); data.ForEach(article => { article.Member = "系统管理员"; if (!article.MemberId.IsEmpty()) { article.Member = memList.TryGetValue(article.MemberId); } }); } } return(data); }