Example #1
0
        /// <summary>
        /// 全部文章
        /// </summary>
        /// <returns></returns>


        /// <summary>
        /// 文章列表Json【注意权限问题,普通人员是否可以访问?】
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="input">录入</param>
        /// <param name="category">栏目</param>
        /// <param name="fromDate">日期起</param>
        /// <param name="toDate">日期止</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">每页记录</param>
        /// <returns></returns>
        public ActionResult List(string title, string input, int?category, DateTime?fromDate, DateTime?toDate, string search, int offset, int limit = 20, CommonModelState state = CommonModelState.Normal)
        {
            if (category == null)
            {
                category = 0;
            }
            int _total;
            var _rows = commonModelService.FindPageList(out _total, offset / limit + 1, limit, "Article", title, null, null, Server.UrlDecode(search), (int)category, input, fromDate, toDate, OrderType.Desc, state)
                        .Select(cm => new CommonModelViewModel()
            {
                CategoryID    = cm.CategoryID,
                CategoryName  = cm.Category.Name,
                Title         = cm.Title,
                Hits          = cm.Hits,
                Inputer       = cm.Inputer.UserName,
                Intro         = cm.Article.Intro,
                DefaultPicUrl = cm.DefaultPicUrl,
                // CommentCount = cm.com.ToList().Count,
                Model       = cm.Model,
                ModelID     = cm.ModelID,
                ReleaseDate = cm.ReleaseDate,
                State       = cm.State
            });

            return(Json(new { total = _total, rows = _rows.ToList() }));
        }
Example #2
0
        public IQueryable <CommonModel> FindPageList(out int totalRecord, int?pageIndex, int?pageSize, string model, string title, string subTitle, string tag, string keyword, int categoryID, string inputer, Nullable <DateTime> fromDate, Nullable <DateTime> toDate, OrderType orderType, CommonModelState state = CommonModelState.Normal)
        {
            var whereLandba = PredicateBuilder.True <CommonModel>();

            if (model == null || model != "All")
            {
                whereLandba = whereLandba.And(cm => cm.Model == model);
            }
            if (!string.IsNullOrEmpty(title))
            {
                whereLandba = whereLandba.And(cm => cm.Title.Contains(title));
            }
            if (!string.IsNullOrEmpty(subTitle))
            {
                whereLandba = whereLandba.And(cm => cm.SubTitle.Contains(subTitle));
            }
            if (!string.IsNullOrEmpty(tag))
            {
                whereLandba = whereLandba.And(cm => cm.Tags.Contains(tag));
            }
            if (!string.IsNullOrEmpty(keyword))
            {
                whereLandba = whereLandba.And(cm => cm.Article.Content.Contains(keyword) || cm.Inputer.UserName.Contains(keyword) || cm.Article.Author.Contains(keyword) || cm.Title.Contains(keyword) || cm.SubTitle.Contains(keyword) || cm.Tags.Contains(keyword));
            }
            if (categoryID > 0)
            {
                whereLandba = whereLandba.And(com => com.CategoryID == categoryID || com.Category.ParentPath.Contains("|" + categoryID + "|"));
            }
            if (!string.IsNullOrEmpty(inputer))
            {
                whereLandba = whereLandba.And(cm => cm.Inputer.UserName == inputer);
            }
            if (fromDate != null)
            {
                whereLandba = whereLandba.And(cm => cm.ReleaseDate >= fromDate);
            }
            if (toDate != null)
            {
                whereLandba = whereLandba.And(cm => cm.ReleaseDate <= toDate);
            }
            whereLandba = whereLandba.And(cm => cm.State == state || (CommonModelState)(-1 * (int)cm.State) == state);
            int Index = pageIndex == null ? 1 : (int)pageIndex;
            int Size  = pageSize == null ? 1 : (int)pageSize;

            if (pageSize == null)
            {
                Size = 20;
            }
            //获取实体列表
            return(FindPageList(Index, Size, out totalRecord, whereLandba, orderType, cm => cm.ReleaseDate));
        }