/// <summary>
        /// 搜索文章新闻
        /// </summary>
        /// <returns></returns>
        public ActionResult GetArticelInfo()
        {
            int pageIndex = Request["page"] != null?int.Parse(Request["page"]) : 1; //当前页码。

            int pageSize = Request["rows"] != null?int.Parse(Request["rows"]) : 5;  //每页显示记录数。

            string        fromDateTime     = Request["formDatepicker"];
            string        toDatepicker     = Request["toDatepicker"];
            string        articelClassId   = Request["articelClassId"];
            string        txtArticeTitle   = Request["txtArticeTitle"];
            string        txtArticelAuthor = Request["txtArticelAuthor"];
            int           totalCount       = 0;
            ArticelSearch articelSearch    = new ArticelSearch()
            {
                ArticelAuthor  = txtArticelAuthor,
                ArticelClassId = articelClassId,
                FormDatepicker = fromDateTime,
                ToDatepicker   = toDatepicker,
                ArticelTitle   = txtArticeTitle,
                PageIndex      = pageIndex,
                PageSize       = pageSize,
                TotalCount     = totalCount
            };
            var articelList = ArticelService.LoadSearchEntities(articelSearch);
            var temp        = from a in articelList
                              select new { ID = a.ID, Title = a.Title, Author = a.Author, AddDate = a.AddDate, Origin = a.Origin, ClassName = from c in a.ArticelClass select c.ClassName };

            return(Json(new { rows = temp, total = articelSearch.TotalCount }, JsonRequestBehavior.AllowGet));
        }
Example #2
0
        /// <summary>
        /// 多条件查询
        /// </summary>
        /// <param name="articelSearch"></param>
        /// <returns></returns>
        public IQueryable <Articel> LoadSearchEntities(ArticelSearch articelSearch)
        {
            var articelInfoList = this.DbSession.ArticelDal.LoadEntities(a => a.DelFlag == 0);

            if (!string.IsNullOrEmpty(articelSearch.ArticelClassId))
            {
                int cid = Convert.ToInt32(articelSearch.ArticelClassId);
                articelInfoList = from a in articelInfoList
                                  from b in a.ArticelClass
                                  where b.ID == cid
                                  select a;
            }
            if (!string.IsNullOrEmpty(articelSearch.ArticelTitle))
            {
                articelInfoList = articelInfoList.Where <Articel>(a => a.Title.Contains(articelSearch.ArticelTitle));
            }
            if (!string.IsNullOrEmpty(articelSearch.ArticelAuthor))
            {
                articelInfoList = articelInfoList.Where <Articel>(a => a.Author.Contains(articelSearch.ArticelAuthor));
            }
            //开始时间与结束时间,必须都要完整
            if (!string.IsNullOrEmpty(articelSearch.FormDatepicker) && !string.IsNullOrEmpty(articelSearch.ToDatepicker))
            {
                DateTime startDateTime = Convert.ToDateTime(articelSearch.FormDatepicker);
                DateTime endDateTime   = Convert.ToDateTime(articelSearch.ToDatepicker);
                articelInfoList = articelInfoList.Where <Articel>(a => a.AddDate >= startDateTime && a.AddDate <= endDateTime);
            }
            articelSearch.TotalCount = articelInfoList.Count();
            return(articelInfoList.OrderBy <Articel, int>(a => a.ID).Skip <Articel>((articelSearch.PageIndex - 1) * articelSearch.PageSize).Take <Articel>(articelSearch.PageSize));
        }