Ejemplo n.º 1
0
        public JsonResult List(CustomerListModel model)
        {
            int        rowSize    = 20;
            AjaxResult ajaxResult = null;


            var total     = db.Customers.Count();
            var customers = db.Customers.OrderBy(p => p.Name).Skip(model.page * rowSize).Take(rowSize).Select(p => new
            {
                Id      = p.Id,
                Address = p.Address,
                Name    = p.Name,
                Age     = p.Birthday == null ? -1 : (DateTime.Now.Year - p.Birthday.Value.Year),
                Date    = p.Birthday
            }).ToList();

            ajaxResult = new AjaxResult()
            {
                Success = true,
                Msg     = "加载数据成功",
                Body    = new
                {
                    Total     = total,
                    Customers = customers
                }
            };

            return(new JsonResult()
            {
                ContentEncoding = Encoding.UTF8, Data = CommonJson.camelJson(ajaxResult), JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Ejemplo n.º 2
0
        public JsonResult Remove()
        {
            AjaxResult ajaxResult = null;

            return(new JsonResult()
            {
                ContentEncoding = Encoding.UTF8, Data = CommonJson.camelJson(ajaxResult)
            });
        }
Ejemplo n.º 3
0
        public JsonResult Login(AccountLoginModel model)
        {
            if (!ModelState.IsValid)
            {
            }

            AjaxResult ajaxResult = null;

            var user = db.Users.SingleOrDefault(p => p.Account == model.Account && p.Password == model.Password);

            if (user != null)
            {
                SaveSession(user);
                ajaxResult = new AjaxResult()
                {
                    Success = true,
                    Msg     = "用户登录成功",
                    Body    = new
                    {
                        Id       = user.Id,
                        Account  = user.Account,
                        NickName = user.NickName,
                        Avatar   = user.Avatar,
                    }
                };
            }
            else
            {
                ajaxResult = new AjaxResult()
                {
                    Success = false,
                    Msg     = "用户名或密码错误",
                    Body    = null
                };
            }

            return(new JsonResult()
            {
                ContentEncoding = Encoding.UTF8, Data = CommonJson.camelJson(ajaxResult)
            });
        }
Ejemplo n.º 4
0
        public JsonResult List(UserListModel model)
        {//动态排序属性名要大小全字匹配,eg:"NickName"
            int    page          = model.page;
            int    rowSize       = model.rowSize;
            bool   sortWay_order = model.sortWay_order;
            string sortWay_prop  = model.sortWay_prop.Substring(0, 1).ToUpper() + model.sortWay_prop.Substring(1);

            AjaxResult ajaxResult = null;

            var total = db.Users.Count();
            var users = CommonLinq.Sort(db.Users.Where(p => true), sortWay_prop, sortWay_order)
                        .Skip(page * rowSize).Take(rowSize)
                        .Select(p => new
            {
                Id         = p.Id,
                Account    = p.Account,
                NickName   = p.NickName,
                Password   = p.Password,
                Avatar     = p.Avatar,
                CreateTime = p.CreateTime
            }).ToList();

            ajaxResult = new AjaxResult()
            {
                Success = true,
                Msg     = "加载数据成功",
                Body    = new
                {
                    Total = total,
                    Users = users
                }
            };

            return(new JsonResult()
            {
                ContentEncoding = Encoding.UTF8, Data = CommonJson.camelJson(ajaxResult), JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }