Ejemplo n.º 1
0
        //角色管理
        public IActionResult RoleList(string id)
        {
            if (id == null || !id.ToUpper().Equals("DATA", StringComparison.OrdinalIgnoreCase))
            {
                // 权限和菜单
                RoleListModel model       = new RoleListModel();
                var           layoutModel = this.GetLayoutModel();
                if (layoutModel != null)
                {
                    layoutModel.ToT(ref model);
                }

                return(View(model));
            }
            else
            {
                //取角色列表
                string titleFilter = Request.Query["title"];

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

                int pageLimit = Consts.Page_Limit;
                int totCount  = CMSAdminBO.GetRoleCount(titleFilter);
                int pageCount = (int)Math.Ceiling(totCount / (float)pageLimit);
                var roles     = new List <Role>();
                if (totCount > 0)
                {
                    IEnumerable <Role> roleIE = CMSAdminBO.GetRoles(titleFilter, pageLimit, pageIndex);
                    if (roleIE != null)
                    {
                        roles = roleIE.ToList();
                    }
                }

                dynamic model = new ExpandoObject();

                model.code  = 0;
                model.msg   = "";
                model.count = totCount;
                model.data  = roles.Select(s => new
                {
                    id    = s.ID,
                    title = s.Title,
                    state = s.State
                });

                return(new JsonResult(model));
            }
        }
Ejemplo 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));
            }
        }
Ejemplo n.º 3
0
        //添加修改账号
        public IActionResult ModifyAdmin()
        {
            //展示页面
            if (!Request.Method.ToUpper().Equals("POST", StringComparison.OrdinalIgnoreCase) || !Request.HasFormContentType)
            {
                // 权限和菜单
                ModifyAdminModel model = new ModifyAdminModel();
                var layoutModel        = this.GetLayoutModel();
                if (layoutModel != null)
                {
                    layoutModel.ToT(ref model);
                }

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

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

                if (id > 0)
                {
                    model.PageTitle = "修改账号";
                    var admin = CMSAdminBO.GetAdminByID(id);
                    if (admin != null && admin.ID > 0)
                    {
                        model.Admin = admin;
                    }
                }
                else
                {
                    model.PageTitle = "添加账号";
                }

                return(View(model));
            }
            else
            {
                var msg = new Message(10, "修改失败!");

                int id = 0;
                int.TryParse(Request.Form["id"], out id);
                string userName   = Request.Form["userName"];
                string password   = Request.Form["password"];
                string rePassword = Request.Form["rePassword"];
                int    roleID     = 0;
                int.TryParse(Request.Form["roleID"], out roleID);
                byte state = 1;
                byte.TryParse(Request.Form["state"], out state);

                var admin = new Admin()
                {
                    ID         = id,
                    UserName   = userName,
                    Password   = password,
                    RePassword = rePassword,
                    RoleID     = roleID,
                    State      = state
                };

                if (admin.ID > 0)
                {
                    msg = CMSAdminBO.UpdateAdminByID(admin);
                }
                else
                {
                    msg = CMSAdminBO.CreateAdmin(admin);
                }

                return(new JsonResult(msg));
            }
        }