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 ActionResult ArticleList(ArticleListSearchInput input)
        {
            CheckPermission(GetLoginInfo().User.Id, CurrentUrl);
            var result    = PostStandardWithSameControllerAction <List <Article> >(this, ModelHelper.GetPropertyDictionary <ArticleListSearchInput>(input));
            var viewModel = new ListViewModel <Article>(result.IsSuccess, result.PageIndex, result.PageSize, (int)result.TotalNums, result.Entity);

            if (viewModel.Success)
            {
                foreach (var article in result.Entity)
                {
                    article.Content = PageValidate.RemoveHtmlTagAndSepecialChar(article.Content);
                }
            }
            return(View(viewModel));
        }
Example #3
0
        public JsonResult ArticleList(ArticleListSearchInput input)
        {
            var responseResult = RestSharpHelper.PostWithStandard <ResponseResult <List <ArticleListSearchOutput> > >(GetCurrentUrl(this), GetPostParameters(), GetCertificationFilePath(), GetCertificationPwd());

            if (responseResult.IsSuccess && responseResult.Entity != null)
            {
                var articleBaseHost = ConfigHelper.GetAppSetting(DataKey.ArticleStaticPageBasePath);
                foreach (var article in responseResult.Entity)
                {
                    article.Url = articleBaseHost + article.Url;
                    if (!(article.PictureUrl.IndexOf(Request.Url.Authority) > -1))
                    {
                        article.PictureUrl = "";
                    }
                }
            }
            return(new JsonResultEx(responseResult));
        }
Example #4
0
        public JsonResult ArticleList(ArticleListSearchInput input)
        {
            using (var result = new ResponseResult <List <ArticleListSearchOutput> >())
            {
                List <T_ARTICLE> list         = null;
                List <T_ARTICLE> carouselList = null;
                long             totalCount;

                if (input.CatId > 1)
                {
                    long carouselTotalCount = 0;
                    carouselList = _article.GetAll(m => !m.IsDeleted && m.CatId == input.CatId && m.IsPutOnCarousel, input.OrderBy, 1, 3, false, out carouselTotalCount);
                    if (carouselTotalCount > 0)
                    {
                        var carouselArticleIdList = carouselList.Select(m => m.Id).ToArray();
                        list = _article.GetAll(m => !m.IsDeleted && m.CatId == input.CatId && !carouselArticleIdList.Contains(m.Id), input.OrderBy, input.PageIndex, input.PageSize, false, out totalCount);
                    }
                    else
                    {
                        list = _article.GetAll(m => !m.IsDeleted && m.CatId == input.CatId, input.OrderBy, input.PageIndex, input.PageSize, false, out totalCount);
                    }
                }
                else
                {
                    long carouselTotalCount = 0;
                    carouselList = _article.GetAll(m => !m.IsDeleted && m.IsPutOnCarousel, input.OrderBy, 1, 3, false, out carouselTotalCount);
                    if (carouselTotalCount > 0)
                    {
                        var carouselArticleIdList = carouselList.Select(m => m.Id).ToArray();
                        list = _article.GetAll(m => !m.IsDeleted && !carouselArticleIdList.Contains(m.Id), input.OrderBy, input.PageIndex, input.PageSize, false, out totalCount);
                    }
                    else
                    {
                        list = _article.GetAll(m => !m.IsDeleted, input.OrderBy, input.PageIndex, input.PageSize, false, out totalCount);
                    }
                }


                result.Entity = Mapper.Map <List <ArticleListSearchOutput> >(list);

                var regexImg = new Regex(@"(<img[\s\S]+?src="".+?""){1}");
                var regexUrl = new Regex(@"http[\s\S]+?(?="")");

                var contentLengthLimit = 28;
                var ellipsisString     = "...";
                foreach (var item in result.Entity)
                {
                    var img = regexImg.Match(item.Content).Value;
                    item.PictureUrl = regexUrl.Match(img).Value;
                    var extension = Path.GetExtension(item.PictureUrl);
                    var index     = item.PictureUrl.LastIndexOf(extension);
                    item.PictureUrl = item.PictureUrl.Insert(index, string.Format("_{0}x{1}", DuPont.Global.Global.LeanGardenThumbnailWidth, DuPont.Global.Global.LearGardenThumbnailHeight));

                    item.Content = PageValidate.RemoveHtmlTagAndSepecialChar(item.Content);
                    item.Content = item.Content.Length > contentLengthLimit
                        ? item.Content.Substring(0, 28) + ellipsisString
                        : item.Content;
                }
                result.TotalNums = totalCount;
                return(new JsonResultEx(result));
            }
        }