예제 #1
0
        //获取分页数据
        public ActionResult GetPageList()
        {
            long     searchId;
            bool     isId = long.TryParse(Request["searchId"], out searchId);
            string   searchName = string.IsNullOrEmpty(Request["searchName"]) ? string.Empty : Request["searchName"];
            DateTime from, to;
            bool     fromIsDate = DateTime.TryParse(Request["from"], out from);
            bool     toIsDate   = DateTime.TryParse(Request["to"], out to);

            int pageIndex = Request["page"] != null?int.Parse(Request["page"]) : 1;

            int pageSize = Request["rows"] != null?int.Parse(Request["rows"]) : 5;

            int totalCount;

            WhereHelper <UserInfo> wh = new WhereHelper <UserInfo>();

            wh.Equal("IsDeleted", (byte)0);
            if (isId)
            {
                wh.Equal("UserId", searchId);
            }
            if (searchName != string.Empty)
            {
                wh.Contains("Username", searchName);
            }
            if (fromIsDate)
            {
                wh.StrGreater("AddTime", from.ToString("yyyy-MM-dd HH:mm:ss"));
            }
            if (toIsDate)
            {
                wh.StrLess("AddTime", to.ToString("yyyy-MM-dd") + " 23:59:59");
            }
            var userList = UserInfoBll.GetPageList <long>(wh.GetExpression(), u => u.UserId, false, pageIndex, pageSize, out totalCount).ToList();
            //var userList = UserInfoBll.GetPageList<int>(u => (u.IsDeleted == 0) && (isId ? u.UserId == searchId : true) && (searchName != string.Empty ? u.Username.Contains(searchName) : true), u => u.UserId, false, pageIndex, pageSize, out totalCount);
            var uList  = UserInfoBll.GetList <int>(us => true);
            var result = from u in userList
                         from uu in uList
                         where u.SubBy == uu.UserId
                         select new UserViewModel
            {
                UserId       = u.UserId,
                Username     = u.Username,
                Remark       = u.Remark,
                AddTime      = u.AddTime,
                ModifiedTime = u.ModifiedTime,
                SubBy        = uu.RealName != null && uu.RealName != "" ? uu.RealName : uu.Username
            };

            return(Json(new { total = totalCount, rows = result }));
        }