コード例 #1
0
        /// <summary>
        /// 获取角色相关权限数据项列表
        /// </summary>
        /// <param name="roleId">角色Id</param>
        /// <returns>权限数据项列表</returns>
        public ICollection <Item> GetRoleAuthorityItems(Guid roleId)
        {
            IAuthorizationContract authorizationContract = this._authorizationContract.Channel;
            RoleInfo role = authorizationContract.GetRole(roleId);

            AuthorityInfo[] infoSystemAuthorities = authorizationContract.GetAuthorities(null, role.InfoSystemNo, null, null, null).ToArray();
            AuthorityInfo[] roleSystemAuthorities = authorizationContract.GetAuthorities(null, null, null, null, role.Id).ToArray();

            ICollection <Item> authorityItems = infoSystemAuthorities.Select(x => x.ToItem()).ToList();

            foreach (Item authorityItem in authorityItems)
            {
                if (roleSystemAuthorities.Any(x => x.Id == authorityItem.Id))
                {
                    authorityItem.IsChecked = true;
                }
            }

            return(authorityItems);
        }
コード例 #2
0
        /// <summary>
        /// 批量删除菜单
        /// </summary>
        public async void RemoveMenus()
        {
            #region # 加载勾选

            IList <Models.Menu> checkedMenus = new List <Models.Menu>();
            foreach (Models.Menu menu in this.Menus)
            {
                if (menu.IsChecked == true)
                {
                    checkedMenus.Add(menu);
                }
                foreach (Models.Menu subNode in menu.GetDeepSubNodes())
                {
                    if (subNode.IsChecked == true)
                    {
                        checkedMenus.Add(subNode);
                    }
                }
            }
            if (!checkedMenus.Any())
            {
                MessageBox.Show("请勾选要删除的菜单!", "警告", MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            #endregion

            MessageBoxResult result = MessageBox.Show("确定要删除吗?", "警告", MessageBoxButton.YesNo, MessageBoxImage.Warning);
            if (result == MessageBoxResult.Yes)
            {
                this.Busy();

                IAuthorizationContract authorizationContract = this._authorizationContract.Channel;
                await Task.Run(() => checkedMenus.ForEach(menu => authorizationContract.RemoveMenu(menu.Id)));

                await this.ReloadMenus();

                this.Idle();
                this.ToastSuccess("删除成功!");
            }
        }
コード例 #3
0
        /// <summary>
        /// 关联权限到菜单
        /// </summary>
        public async void RelateAuthoritiesToMenus()
        {
            this.Busy();

            await Task.Run(() =>
            {
                IAuthorizationContract authorizationContract = this._authorizationContract.Channel;
                MenuRelatedAuthority[] relatedAuthorities    = ExcelReader.ReadFile <MenuRelatedAuthority>(ExcelPath, "菜单相关权限");

                MenuInfo[] menuInfos           = authorizationContract.GetMenus(null, null, null).ToArray();
                AuthorityInfo[] authorityInfos = authorizationContract.GetAuthorities(null, null, null, null, null).ToArray();

                var relatedAuthorityGroups = relatedAuthorities.GroupBy(x => new
                {
                    x.信息系统编号,
                    x.应用程序类型,
                    x.菜单名称
                });
                foreach (var relatedAuthorityGroup in relatedAuthorityGroups)
                {
                    ApplicationType applicationType = (ApplicationType)Enum.Parse(typeof(ApplicationType), relatedAuthorityGroup.Key.应用程序类型);
                    MenuInfo menuInfo = menuInfos.Single(x => x.InfoSystemNo == relatedAuthorityGroup.Key.信息系统编号 && x.ApplicationType == applicationType && x.Name == relatedAuthorityGroup.Key.菜单名称);

                    IList <AuthorityInfo> relatedAuthorityInfos = new List <AuthorityInfo>();
                    foreach (MenuRelatedAuthority relatedAuthority in relatedAuthorityGroup)
                    {
                        AuthorityInfo authorityInfo = authorityInfos.Single(x => x.InfoSystemInfo.Number == relatedAuthority.信息系统编号 && x.ApplicationType == applicationType && x.Name == relatedAuthority.权限名称);
                        relatedAuthorityInfos.Add(authorityInfo);
                    }

                    IEnumerable <Guid> authorityIds = relatedAuthorityInfos.Select(x => x.Id);
                    authorizationContract.RelateAuthoritiesToMenu(menuInfo.Id, authorityIds);
                }
            });

            this.Idle();
            this.ToastSuccess("关联权限到菜单成功!");
        }
コード例 #4
0
        /// <summary>
        /// 导入菜单
        /// </summary>
        public async void ImportMenus()
        {
            this.Busy();

            await Task.Run(() =>
            {
                IAuthorizationContract authorizationContract = this._authorizationContract.Channel;
                Menu[] menus = ExcelReader.ReadFile <Menu>(ExcelPath, "菜单");

                IEnumerable <IGrouping <string, Menu> > menuGroups = menus.GroupBy(x => x.信息系统编号);
                foreach (IGrouping <string, Menu> menuGroup in menuGroups)
                {
                    //获取信息系统根级菜单
                    Guid infoSystemMenuId = authorizationContract.GetMenus(null, menuGroup.Key, null).First().Id;

                    IList <Menu> rootMenus = menuGroup.Where(x => string.IsNullOrWhiteSpace(x.级Id)).ToList();
                    this.CreateMenus(authorizationContract, menuGroup.Key, menus, rootMenus, infoSystemMenuId);
                }
            });

            this.Idle();
            this.ToastSuccess("导入菜单成功!");
        }
コード例 #5
0
 /// <summary>
 /// 依赖注入构造器
 /// </summary>
 /// <param name="authorizationContract">权限服务接口</param>
 public InfoSystemPresenter(IAuthorizationContract authorizationContract)
 {
     this._authorizationContract = authorizationContract;
 }
コード例 #6
0
 /// <summary>
 /// 依赖注入构造器
 /// </summary>
 public AuthorizationController(IAuthorizationContract authorizationContract)
 {
     this._authorizationContract = authorizationContract;
 }
コード例 #7
0
 /// <summary>
 /// 依赖注入构造器
 /// </summary>
 public MenuController(IMenuPresenter menuPresenter, IInfoSystemPresenter infoSystemPresenter, IAuthorizationContract authorizationContract)
 {
     this._menuPresenter         = menuPresenter;
     this._infoSystemPresenter   = infoSystemPresenter;
     this._authorizationContract = authorizationContract;
 }
コード例 #8
0
 /// <summary>
 /// 依赖注入构造器
 /// </summary>
 public RolePresenter(IAuthorizationContract authorizationContract, IUserContract userContract)
 {
     this._authorizationContract = authorizationContract;
     this._userContract          = userContract;
 }
コード例 #9
0
 /// <summary>
 /// 依赖注入构造器
 /// </summary>
 /// <param name="systemPresenter">信息系统呈现器接口</param>
 /// <param name="authorityPresenter">权限呈现器接口</param>
 /// <param name="authorizationContract">权限服务接口</param>
 public AuthorityController(IInfoSystemPresenter systemPresenter, IAuthorityPresenter authorityPresenter, IAuthorizationContract authorizationContract)
 {
     this._systemPresenter       = systemPresenter;
     this._authorityPresenter    = authorityPresenter;
     this._authorizationContract = authorizationContract;
 }
コード例 #10
0
 /// <summary>
 /// 依赖注入构造器
 /// </summary>
 public InfoSystemController(IInfoSystemPresenter infoSystemPresenter, IAuthorizationContract authorizationContract)
 {
     this._infoSystemPresenter   = infoSystemPresenter;
     this._authorizationContract = authorizationContract;
 }
コード例 #11
0
 /// <summary>
 /// 依赖注入构造器
 /// </summary>
 public AuthorityPresenter(IAuthorizationContract authorizationContract)
 {
     this._authorizationContract = authorizationContract;
 }
コード例 #12
0
 /// <summary>
 /// 依赖注入构造器
 /// </summary>
 public RoleController(IRolePresenter rolePresenter, IInfoSystemPresenter infoSystemPresenter, IAuthorizationContract authorizationContract)
 {
     this._rolePresenter         = rolePresenter;
     this._infoSystemPresenter   = infoSystemPresenter;
     this._authorizationContract = authorizationContract;
 }