Ejemplo n.º 1
0
        public ActionResult GetRoleValues(string roleId)
        {
            //var result = ResModelFactory.ResDefaultData<SystemRoleValueViewModel>();
            //角色信息
            SystemRoleService service = new SystemRoleService();
            SystemRole        role    = service.GetEntitys(p => p.ID == roleId).FirstOrDefault();

            //角色权限信息
            SystemRoleValueService       rvalservice = new SystemRoleValueService();
            IQueryable <SystemRoleValue> rolevalues  = rvalservice.GetEntitys(p => p.RoleId == roleId);

            //所有系统导航信息
            IQueryable <SystemMenu> navigations = new SystemMenuService().GetEntitys(p => true);

            RoleAndRloeValues model = new RoleAndRloeValues();

            model.Id          = role.ID;
            model.RoleName    = role.RoleName;
            model.Description = role.Description;

            var parentsnav = navigations.Where(p => string.IsNullOrEmpty(p.ParentID)).OrderBy(o => o.Sort);
            List <TreeDataViewModel> tree = new List <TreeDataViewModel>();

            foreach (var p in parentsnav)
            {
                //如果有菜单权限 选中并展开
                TreeDataViewModel roleval = new TreeDataViewModel();
                roleval.id    = p.ID;
                roleval.title = p.MenuName;


                var parents = navigations.Where(n => n.ParentID == p.ID);
                if (parents.Count() > 0)
                {
                    roleval.spread   = true;
                    roleval.children = initRoleValTree(navigations, parents, rolevalues);
                }
                else
                {
                    if (rolevalues.Where(q => q.MenuId == p.ID).Count() > 0)
                    {
                        roleval.@checked = true;
                    }
                    roleval.children = null;
                }
                tree.Add(roleval);
            }
            model.TreeData = tree;
            return(View("AddRole", model));
        }