/// <summary>
        /// 批量创建权限
        /// </summary>
        /// <param name="infoSystemNo">信息系统编号</param>
        /// <param name="applicationType">应用程序类型</param>
        /// <param name="authorityParams">权限参数模型集</param>
        public void CreateAuthorities(string infoSystemNo, ApplicationType applicationType, IEnumerable <AuthorityParam> authorityParams)
        {
            IList <Authority> authorities = new List <Authority>();

            foreach (AuthorityParam param in authorityParams)
            {
                Authority authority = new Authority(infoSystemNo, applicationType, param.authorityName, param.authorityPath, param.description);

                #region # 验证

                if (this._repMediator.AuthorityRep.ExistsPath(infoSystemNo, applicationType, param.authorityPath))
                {
                    throw new ArgumentOutOfRangeException(nameof(authorityParams), "给定信息系统与应用程序类型已存在该权限路径!");
                }

                #endregion

                authorities.Add(authority);
            }

            //为系统管理员角色追加权限
            Guid adminRoleId = this._repMediator.RoleRep.GetManagerRoleId(infoSystemNo);
            Role adminRole   = this._unitOfWork.Resolve <Role>(adminRoleId);
            adminRole.AppendAuthorities(authorities);

            this._unitOfWork.RegisterAddRange(authorities);
            this._unitOfWork.RegisterSave(adminRole);
            this._unitOfWork.Commit();
        }
        /// <summary>
        /// 为角色追加权限
        /// </summary>
        /// <param name="roleId">角色Id</param>
        /// <param name="authorityIds">权限Id集</param>
        public void AppendAuthorities(Guid roleId, IEnumerable <Guid> authorityIds)
        {
            Role role = this._unitOfWork.Resolve <Role>(roleId);

            IEnumerable <Authority> authorities = authorityIds.Select(authorityId => this._unitOfWork.Resolve <Authority>(authorityId));

            role.AppendAuthorities(authorities);
            this._unitOfWork.RegisterSave(role);
            this._unitOfWork.UnitedCommit();
        }
Beispiel #3
0
        /// <summary>
        /// 追加权限
        /// </summary>
        /// <param name="systemNo">信息系统编号</param>
        /// <param name="authorityId">权限Id</param>
        private void AppendAuthorities(string systemNo, Guid authorityId)
        {
            Authority currentAuthority = this._unitOfWork.Resolve <Authority>(authorityId);

            //为系统管理员角色追加权限
            Guid adminRoleId = this._repMediator.RoleRep.GetManagerRoleId(systemNo);
            Role adminRole   = this._unitOfWork.Resolve <Role>(adminRoleId);

            adminRole.AppendAuthorities(new[] { currentAuthority });

            //注册保存
            this._unitOfWork.RegisterSave(adminRole);

            //提交
            this._unitOfWork.Commit();
        }
        /// <summary>
        /// 追加权限到角色
        /// </summary>
        /// <param name="roleId">角色Id</param>
        /// <param name="authorityIds">权限Id集</param>
        public void AppendAuthoritiesToRole(Guid roleId, IEnumerable <Guid> authorityIds)
        {
            #region # 验证

            authorityIds = authorityIds?.Distinct().ToArray() ?? Array.Empty <Guid>();
            if (!authorityIds.Any())
            {
                return;
            }

            #endregion

            ICollection <Authority> authorities = this._unitOfWork.ResolveRange <Authority>(authorityIds);

            Role role = this._unitOfWork.Resolve <Role>(roleId);
            role.AppendAuthorities(authorities);

            this._unitOfWork.RegisterSave(role);
            this._unitOfWork.Commit();
        }
        /// <summary>
        /// 创建权限
        /// </summary>
        /// <param name="infoSystemNo">信息系统编号</param>
        /// <param name="applicationType">应用程序类型</param>
        /// <param name="authorityName">权限名称</param>
        /// <param name="authorityPath">权限路径</param>
        /// <param name="description">描述</param>
        public void CreateAuthority(string infoSystemNo, ApplicationType applicationType, string authorityName, string authorityPath, string description)
        {
            #region # 验证

            if (this._repMediator.AuthorityRep.ExistsPath(infoSystemNo, applicationType, authorityPath))
            {
                throw new ArgumentOutOfRangeException(nameof(authorityPath), "给定信息系统与应用程序类型已存在该权限路径!");
            }

            #endregion

            Authority authority = new Authority(infoSystemNo, applicationType, authorityName, authorityPath, description);

            //为系统管理员角色追加权限
            Guid adminRoleId = this._repMediator.RoleRep.GetManagerRoleId(infoSystemNo);
            Role adminRole   = this._unitOfWork.Resolve <Role>(adminRoleId);
            adminRole.AppendAuthorities(new[] { authority });

            this._unitOfWork.RegisterAdd(authority);
            this._unitOfWork.RegisterSave(adminRole);
            this._unitOfWork.Commit();
        }