コード例 #1
0
        /// <summary>
        /// 2.0 jquery.datatable()插件 Ajax Get设置列表
        /// </summary>
        /// <returns>datatable-JSON</returns>
        public JsonResult GetSettingsJson(jqDataTableParameter tableParam)
        {
            List <WebSetting> DataSource = settingService.GetDataListBy(a => true, a => a.Id);

            string echo      = tableParam.sEcho;
            int    dataStart = tableParam.iDisplayStart;
            int    pageSize  = tableParam.iDisplayLength == -1 ? DataSource.Count : tableParam.iDisplayLength;

            var data = DataSource.Skip <WebSetting>(dataStart)
                       .Take(pageSize)
                       .Select(s => new
            {
                Id          = s.Id,
                ConfigKey   = s.ConfigKey,
                ConfigValue = s.ConfigValue,
                Description = s.Description,
                BuildTime   = s.BuildTime.ToString()
            }).ToList();

            return(Json(new
            {
                sEcho = echo,
                iTotalRecords = DataSource.Count(),
                iTotalDisplayRecords = DataSource.Count(),
                aaData = data
            }, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        /// <summary>
        /// 2.0 jquery.datatable()插件 Ajax Get头像列表
        /// </summary>
        /// <returns>datatable-JSON</returns>
        public JsonResult GetHeadiconsJson(jqDataTableParameter tableParam)
        {
            //0.0 全部数据
            List <HeadIcon> DataSource = iconService.GetDataListBy(h => true, h => h.UploadTime);

            //1.0 首先获取datatable提交过来的参数
            string echo      = tableParam.sEcho;                                                               //用于客户端自己的校验
            int    dataStart = tableParam.iDisplayStart;                                                       //要请求的该页第一条数据的序号
            int    pageSize  = tableParam.iDisplayLength == -1 ? DataSource.Count : tableParam.iDisplayLength; //每页容量(=-1表示取全部数据)

            //2.0 根据参数(起始序号、每页容量)查询数据
            var data = DataSource.Skip <HeadIcon>(dataStart)
                       .Take(pageSize)
                       .Select(h => new
            {
                Id         = h.Id,
                HeadImg    = h.IconURL,
                RawName    = h.IconRawName,
                NowName    = h.IconName,
                HeadImgUrl = h.IconURL,
                UploadTime = h.UploadTime.ToString(),
                Status     = h.Status
            }).ToList();

            //3.0 构造datatable所需要的数据json对象...aaData里面应是一个二维数组:即里面是一个数组[["","",""],[],[],[]]
            return(Json(new
            {
                sEcho = echo,
                iTotalRecords = DataSource.Count(),
                iTotalDisplayRecords = DataSource.Count(),
                aaData = data
            }, JsonRequestBehavior.AllowGet));
        }
コード例 #3
0
        /// <summary>
        /// 2.0 jquery.datatable()插件 Ajax Get评论列表
        ///     按文章编号来排序吧
        /// </summary>
        /// <returns>datatable-JSON</returns>
        public JsonResult GetLvMsgsJson(jqDataTableParameter tableParam)
        {
            //0.0 全部数据 按什么排序呢?
            List <LeaveMsg> DataSource = lvmService.GetDataListBy(c => true);

            //1.0 首先获取datatable提交过来的参数
            string echo      = tableParam.sEcho;         //用于客户端自己的校验
            int    dataStart = tableParam.iDisplayStart; //要请求的该页第一条数据的序号
            int    pageSize  = tableParam.iDisplayLength == -1 ? DataSource.Count : tableParam.iDisplayLength;

            //2.0 根据参数(起始序号、每页容量、查询参数)查询数据
            var data = DataSource.Skip <LeaveMsg>(dataStart)
                       .Take(pageSize)
                       .Select(c => new
            {
                Id         = c.Id,
                LvmText    = c.LMessage,
                LvmerName  = c.Visitor.VisitorName,
                LvmerEmail = c.Visitor.VisitorEmail,
                SubTime    = c.SubTime.ToString(),
                Status     = c.Status
            }).ToList();

            //3.0 构造datatable所需要的数据json对象...aaData里面应是一个二维数组:即里面是一个数组[["","",""],[],[],[]]
            return(Json(new
            {
                sEcho = echo,
                iTotalRecords = DataSource.Count(),
                iTotalDisplayRecords = DataSource.Count(),
                aaData = data
            }, JsonRequestBehavior.AllowGet));
        }
コード例 #4
0
        public ActionResult GetTeachers(jqDataTableParameter tableParam)
        {
            var whereExp = PredicateBuilder.True <Users>();

            whereExp = whereExp.And(p => !p.IsDeleted && (p.RoleId == (int)UserRole.教师 || p.RoleId == (int)UserRole.管理员));

            //1.0 首先获取datatable提交过来的参数
            string echo         = tableParam.sEcho;          //用于客户端自己的校验
            int    displayStart = tableParam.iDisplayStart;  //要请求的该页第一条数据的序号
            int    pageSize     = tableParam.iDisplayLength; //每页容量(=-1表示取全部数据)

            var total    = _usersService.GetDataListBy(whereExp).Count();
            var teachers = _usersService.GetPagedList <DateTime>(displayStart, pageSize, whereExp, p => p.CreationTime, false);
            var data     = (from s in teachers
                            select new TeacherOutput
            {
                Id = s.Id,
                UserName = s.UserName,
                RealName = s.RealName,
                Email = s.Email,
                Phone = s.Phone,
                RoleId = s.RoleId,
                CreationTime = s.CreationTime,
                IsActive = s.IsActive
            }).ToList();

            return(Json(new
            {
                sEcho = echo,
                iTotalRecords = total,
                iTotalDisplayRecords = total,
                aaData = data
            }));
        }
コード例 #5
0
        /// <summary>
        /// 2.0 jquery.datatable()插件 Ajax Get游客列表
        /// </summary>
        /// <returns>datatable-JSON</returns>
        public JsonResult GetVisitorsJson(jqDataTableParameter tableParam)
        {
            //0.0 全部数据
            List <Visitor> DataSource = visitorService.GetDataListBy(v => true, v => v.SubTime);

            //1.0 首先获取datatable提交过来的参数
            string echo      = tableParam.sEcho;                                                               //用于客户端自己的校验
            int    dataStart = tableParam.iDisplayStart;                                                       //要请求的该页第一条数据的序号
            int    pageSize  = tableParam.iDisplayLength == -1 ? DataSource.Count : tableParam.iDisplayLength; //每页容量(=-1表示取全部数据)

            //2.0 根据参数(起始序号、每页容量、查询参数)查询数据
            string defaultIconPath = ConfigurationManager.AppSettings["DefaultHeadIcon"];
            var    data            = DataSource.Skip <Visitor>(dataStart)
                                     .Take(pageSize)
                                     .Select(v => new
            {
                Id      = v.Id,
                HeadImg = v.HeadIcon == null ? defaultIconPath : v.HeadIcon.IconURL,
                Name    = v.VisitorName,
                Email   = v.VisitorEmail,
                QQ      = v.VisitorQQ,
                SubTime = v.SubTime.ToString(),
                Status  = v.Status
            }).ToList();

            //3.0 构造datatable所需要的数据json对象...aaData里面应是一个二维数组:即里面是一个数组[["","",""],[],[],[]]
            return(Json(new
            {
                sEcho = echo,
                iTotalRecords = DataSource.Count(),
                iTotalDisplayRecords = DataSource.Count(),
                aaData = data
            }, JsonRequestBehavior.AllowGet));
        }
コード例 #6
0
        /// <summary>
        /// 2.0 jquery.datatable()插件 Ajax Get类别列表
        /// </summary>
        /// <returns>datatable-JSON</returns>
        public JsonResult GetCategoriesJson(jqDataTableParameter tableParam)
        {
            //0.0 全部数据
            List <Category> DataSource = categoryService.GetDataListBy(a => true, a => a.SubTime);

            //1.0 首先获取datatable提交过来的参数
            string echo      = tableParam.sEcho;                                                               //用于客户端自己的校验
            int    dataStart = tableParam.iDisplayStart;                                                       //要请求的该页第一条数据的序号
            int    pageSize  = tableParam.iDisplayLength == -1 ? DataSource.Count : tableParam.iDisplayLength; //每页容量(=-1表示取全部数据)
            string search    = tableParam.sSearch;

            //2.0 根据参数(起始序号、每页容量、查询参数)查询数据
            if (!String.IsNullOrEmpty(search))
            {
                var data = DataSource.Where(c => c.Name.Contains(search) ||
                                            c.Descn.Contains(search))
                           .Skip <Category>(dataStart)
                           .Take(pageSize)
                           .Select(c => new
                {
                    Id       = c.Id,
                    Name     = c.Name,
                    Descript = c.Descn,
                    SubTime  = c.SubTime.ToString(),
                    Status   = c.Status
                }).ToList();

                //3.0 构造datatable所需要的数据json对象...aaData里面应是一个二维数组:即里面是一个数组[["","",""],[],[],[]]
                return(Json(new
                {
                    sEcho = echo,
                    iTotalRecords = DataSource.Count(),
                    iTotalDisplayRecords = DataSource.Count(),
                    aaData = data
                }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var data = DataSource.Skip <Category>(dataStart)
                           .Take(pageSize)
                           .Select(c => new
                {
                    Id       = c.Id,
                    Name     = c.Name,
                    Descript = c.Descn,
                    SubTime  = c.SubTime.ToString(),
                    Status   = c.Status
                }).ToList();

                //3.0 构造datatable所需要的数据json对象...aaData里面应是一个二维数组:即里面是一个数组[["","",""],[],[],[]]
                return(Json(new
                {
                    sEcho = echo,
                    iTotalRecords = DataSource.Count(),
                    iTotalDisplayRecords = DataSource.Count(),
                    aaData = data
                }, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #7
0
        /// <summary>
        /// 2.0 jquery.datatable()插件 Ajax Get评论列表
        ///     按文章编号来排序吧
        /// </summary>
        /// <returns>datatable-JSON</returns>
        public JsonResult GetCommentsJson(jqDataTableParameter tableParam)
        {
            //0.0 全部数据   先按文章编号排序,再按时间排序
            List <Comment> DataSource = commentService.GetDataListBy(c => true, c => c.CmtArtId);
            //DataSource = DataSource.OrderBy(c => c.SubTime).ToList();


            //1.0 首先获取datatable提交过来的参数
            string echo      = tableParam.sEcho;                                                               //用于客户端自己的校验
            int    dataStart = tableParam.iDisplayStart;                                                       //要请求的该页第一条数据的序号
            int    pageSize  = tableParam.iDisplayLength == -1 ? DataSource.Count : tableParam.iDisplayLength; //每页容量(=-1表示取全部数据)
            string search    = tableParam.sSearch;

            //2.0 根据参数(起始序号、每页容量、查询参数)查询数据
            if (!String.IsNullOrEmpty(search))
            {
                var data = DataSource.Where(c => c.CmtText.Contains(search))
                           .Skip <Comment>(dataStart)
                           .Take(pageSize)
                           .Select(c => new
                {
                    Id         = c.Id,
                    ArticleId  = c.CmtArtId,
                    CmtText    = c.CmtText,
                    CmterName  = c.Visitor.VisitorName,
                    CmterEmail = c.Visitor.VisitorEmail,
                    SubTime    = c.SubTime.ToString(),
                    Status     = c.Status
                }).ToList();

                //3.0 构造datatable所需要的数据json对象...aaData里面应是一个二维数组:即里面是一个数组[["","",""],[],[],[]]
                return(Json(new
                {
                    sEcho = echo,
                    iTotalRecords = DataSource.Count(),
                    iTotalDisplayRecords = DataSource.Count(),
                    aaData = data
                }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var data = DataSource.Skip <Comment>(dataStart)
                           .Take(pageSize)
                           .Select(c => new
                {
                    Id         = c.Id,
                    ArticleId  = c.CmtArtId,
                    CmtText    = c.CmtText,
                    CmterName  = c.Visitor.VisitorName,
                    CmterEmail = c.Visitor.VisitorEmail,
                    SubTime    = c.SubTime.ToString(),
                    Status     = c.Status
                }).ToList();

                //3.0 构造datatable所需要的数据json对象...aaData里面应是一个二维数组:即里面是一个数组[["","",""],[],[],[]]
                return(Json(new
                {
                    sEcho = echo,
                    iTotalRecords = DataSource.Count(),
                    iTotalDisplayRecords = DataSource.Count(),
                    aaData = data
                }, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #8
0
        /// <summary>
        /// 2.0 jquery.datatable()插件 Ajax Get文章列表
        /// </summary>
        /// <returns>datatable-JSON</returns>
        public JsonResult GetArchivesJson(jqDataTableParameter tableParam)
        {
            #region 1.0 场景一:服务端一次性取出所有数据,完全由客户端来处理这些数据.此时"bServerSide": false,
            ////1. 获取所有文章
            //List<Article> DataSource = articleService.GetDataListBy(a => true, a => a.Id);
            ////2. 构造aaData
            //var data = DataSource.Select(a => new object[]{
            //  a.Id,
            //  a.Title+ "  ("+a.SubTime.ToString()+")",
            //  (categoryService.GetDataListBy(c=>c.Id==a.CategoryId)[0]).Name,
            //  a.ViewCount,
            //  commentService.GetDataListBy(c=>c.CmtArtId==a.Id).Count,
            //  a.Digg,
            //  a.Status==1?"正常":"删除"

            //});
            ////3. 返回json,aaData是一个数组,数组里面还是字符串数组
            //return Json(new
            //{
            //    sEcho = 1,
            //    iTotalRecords = DataSource.Count,
            //    iTotalDisplayRecords = data.Count(),
            //    aaData = data
            //}, JsonRequestBehavior.AllowGet);
            #endregion

            #region 2.0 场景二:服务端处理分页后数据,客户端呈现,此时为true
            //客户端需要"bServerSide": true, 用mDataProp绑定字段,obj.aData.Id获取字段(.属性)

            //0.0 全部数据
            List <Article> DataSource = articleService.GetDataListBy(a => true);
            //DataSource = DataSource.OrderByDescending(a => a.SubTime).ToList();

            //1.0 首先获取datatable提交过来的参数
            string echo      = tableParam.sEcho;                                                               //用于客户端自己的校验
            int    dataStart = tableParam.iDisplayStart;                                                       //要请求的该页第一条数据的序号
            int    pageSize  = tableParam.iDisplayLength == -1 ? DataSource.Count : tableParam.iDisplayLength; //每页容量(=-1表示取全部数据)
            string search    = tableParam.sSearch;

            //2.0 根据参数(起始序号、每页容量、参训参数)查询数据
            if (!String.IsNullOrEmpty(search))
            {
                var data = DataSource.Where(a => a.Title.Contains(search) ||
                                            a.Keywords.Contains(search) ||
                                            a.Contents.Contains(search))
                           .Skip <Article>(dataStart)
                           .Take(pageSize)
                           .Select(a => new
                {
                    Id           = a.Id,
                    Title        = a.Title + "  (" + a.SubTime.ToString() + ")",
                    CategoryName = a.Category.Name,
                    ViewCount    = a.ViewCount,
                    CommentCount = commentService.GetDataListBy(c => c.CmtArtId == a.Id).Count,
                    Digg         = a.Digg,
                    Status       = a.Status
                }).ToList();

                //3.0 构造datatable所需要的数据json对象...aaData里面应是一个二维数组:即里面是一个数组[["","",""],[],[],[]]
                return(Json(new
                {
                    sEcho = echo,
                    iTotalRecords = DataSource.Count(),
                    iTotalDisplayRecords = DataSource.Count(),
                    aaData = data
                }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var data = DataSource.Skip <Article>(dataStart)
                           .Take(pageSize)
                           .Select(a => new
                {
                    Id           = a.Id,
                    Title        = a.Title + "  (" + a.SubTime.ToString() + ")",
                    CategoryName = a.Category.Name,
                    ViewCount    = a.ViewCount,
                    CommentCount = commentService.GetDataListBy(c => c.CmtArtId == a.Id).Count,
                    Digg         = a.Digg,
                    Status       = a.Status
                }).ToList();

                //3.0 构造datatable所需要的数据json对象...aaData里面应是一个二维数组:即里面是一个数组[["","",""],[],[],[]]
                return(Json(new
                {
                    sEcho = echo,
                    iTotalRecords = DataSource.Count(),
                    iTotalDisplayRecords = DataSource.Count(),
                    aaData = data
                }, JsonRequestBehavior.AllowGet));
            }
            #endregion
        }