public JsonResult ArticleList(ArticleListSearchInput input) { CheckPermission(); using (var result = new ResponseResult <List <Article> >()) { result.PageIndex = input.PageIndex; result.PageSize = input.PageSize; long totalCount; var predicate = PredicateBuilder.True <T_ARTICLE>(); //如果指定了删除状态 if (input.IsDeleted.HasValue) { predicate = predicate.And(m => m.IsDeleted == input.IsDeleted.Value); } //如果指定了分类 if (input.CatId > 1) { predicate = predicate.And(m => m.CatId == input.CatId); } //如果指定了关键词 if (!string.IsNullOrEmpty(input.Keywords)) { predicate = predicate.And(m => m.Title.Contains(input.Keywords)); } IEnumerable <T_ARTICLE> list; if (input.OrderBy.IsNullOrEmpty() || input.OrderBy == "-date") { list = _articleService.GetAll(predicate, null, m => m.CreateTime, input.PageIndex, input.PageSize, out totalCount, "T_ARTICLE_CATEGORY"); } else { list = _articleService.GetAll(predicate, null, m => m.Click, input.PageIndex, input.PageSize, out totalCount, "T_ARTICLE_CATEGORY"); } var regexHtmlTag = new Regex(@"<[^>]+?>", RegexOptions.Multiline); var enumerable = list as T_ARTICLE[] ?? list.ToArray(); foreach (var article in enumerable) { article.Content = HttpUtility.HtmlEncode(regexHtmlTag.Replace(article.Content, "")); } result.TotalNums = totalCount; result.Entity = Mapper.Map <List <Article> >(enumerable.ToList()); return(new JsonResultEx(result)); } }
public JsonResult CarouselPictures(CarouselPictureSearchInput input) { var regexImg = new Regex(@"(<img[\s\S]+?src="".+?""){1}"); var regexUrl = new Regex(@"http[\s\S]+?(?="")"); var regexHtmlTag = new Regex(@"[<][\s\S]+?[>]"); using (var result = new ResponseResult <List <CarouselPictureOutput> >()) { long totalCount = 3; List <T_ARTICLE> list = null; if (input.CatId > 1) { list = _article.GetAll(m => !m.IsDeleted && m.CatId == input.CatId && m.IsPutOnCarousel, input.OrderBy, 1, 3, true, out totalCount); } else { list = _article.GetAll(m => !m.IsDeleted && m.IsPutOnCarousel, input.OrderBy, 1, 3, true, out totalCount); } result.Entity = Mapper.Map <List <CarouselPictureOutput> >(list); result.TotalNums = result.Entity.Count; for (int i = 0; i < list.Count; i++) { var item = list[i]; if (!string.IsNullOrEmpty(item.Content)) { var img = regexImg.Match(item.Content).Value; result.Entity[i].PictureUrl = regexUrl.Match(img).Value; } } return(new JsonResultEx(result)); } }
public async Task <IEnumerable <ArticleViewModel> > GetAll() => _mapper.Map <IEnumerable <ArticleViewModel> >(await _article.GetAll());