public ActionResult AdminList()
        {
            AdminListModel model = new AdminListModel();

            using (BlogDBContexts db = new BlogDBContexts())
            {
                //Çekilen verileri ToList() metoduyla List'e dönüştürdük.
                model.admins = db.tblAdmins.ToList();
            }
            return(View(model));
        }
Exemplo n.º 2
0
        //账号管理
        public IActionResult AdminList(string id)
        {
            if (id == null || !id.ToUpper().Equals("DATA", StringComparison.OrdinalIgnoreCase))
            {
                // 权限和菜单
                AdminListModel model       = new AdminListModel();
                var            layoutModel = this.GetLayoutModel();
                if (layoutModel != null)
                {
                    layoutModel.ToT(ref model);
                }

                var roles = CMSAdminBO.GetRoles(0);
                if (roles != null)
                {
                    model.Roles = roles.ToList();
                }

                return(View(model));
            }
            else
            {
                //取账号列表
                string userNameFilter = Request.Query["userName"];

                int roleIDFilter = 0;
                int.TryParse(Request.Query["roleID"], out roleIDFilter);

                int pageIndex = 0;
                int.TryParse(Request.Query["page"], out pageIndex);

                int pageLimit = Consts.Page_Limit;
                int totCount  = CMSAdminBO.GetAdminCount(userNameFilter, roleIDFilter);
                int pageCount = (int)Math.Ceiling(totCount / (float)pageLimit);
                var admins    = new List <Admin>();
                if (totCount > 0)
                {
                    IEnumerable <Admin> adminIE = CMSAdminBO.GetAdmins(userNameFilter, roleIDFilter, pageLimit, pageIndex);
                    if (adminIE != null)
                    {
                        admins = adminIE.ToList();
                    }
                }

                dynamic model = new ExpandoObject();

                model.code  = 0;
                model.msg   = "";
                model.count = totCount;
                model.data  = admins.Select(s => new
                {
                    id        = s.ID,
                    userName  = s.UserName,
                    roleTitle = s.RoleTitle,
                    state     = s.State,
                    lockState = s.LockState
                });

                return(new JsonResult(model));
            }
        }