Exemplo n.º 1
0
        public IActionResult GetBlogListByPaging(int PageIndex, int PageSize, string Title, string startdate, string enddate, string CategoryType)
        {
            string where = " 1 = 1 and state = 0 ";
            //var BlogList = _BlogDAL.GetList();
            if (!string.IsNullOrEmpty(Title))
            {
                //BlogList = BlogList.Where(o => o.Title.Contains(Title));
                where += $" and Title like '%{Title}%' or Content like '%{Title}%'";
            }
            if (!string.IsNullOrEmpty(startdate))
            {
                where += $" and createdate >= {startdate}";
                //BlogList = BlogList.Where(o => o.CreateDate >= DateTime.Parse(startdate));
            }
            if (!string.IsNullOrEmpty(enddate))
            {
                where += $" and createdate <= {enddate}";
                //BlogList = BlogList.Where(o => o.CreateDate <= DateTime.Parse(enddate));
            }
            if (!string.IsNullOrEmpty(CategoryType) && CategoryType != "0")
            {
                where += $" and CategoryTypeId = {CategoryType}";
                //BlogList = BlogList.Where(o => o.CategoryTypeId.Equals(CategoryType));
            }
            var list = _BlogDAL.GetBlogListByPaging("id ", PageSize, PageIndex, where);
            //var list = BlogList.Skip(PageSize * PageIndex).Take(PageSize).ToList();
            int Count     = _BlogDAL.GetCount(where);
            var PageCount = Count % PageSize == 0 ? Count / PageSize : Count / PageSize + 1;

            return(Json(new { data = list, PageCount = PageCount, total = Count }));
        }