コード例 #1
0
        /// <summary>
        /// 从角色回收权限
        /// </summary>
        public static void RevokeAuthFromRole(ICollection authIDs, string roleID)
        {
            IList authList = GetAuthList(authIDs);

            using (new SessionScope())
            {
                SysRole role = SysRole.Find(roleID);

                using (TransactionScope trans = new TransactionScope())
                {
                    try
                    {
                        IEnumerable <SysAuth> tAuths = role.Auth.Where(ent => authList.Contains(ent.AuthID));
                        while (tAuths.Count() > 0)
                        {
                            role.Auth.Remove(tAuths.First());
                        }

                        trans.VoteCommit();
                    }
                    catch (Exception ex)
                    {
                        trans.VoteRollBack();

                        throw ex;
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// 授权给角色
        /// </summary>
        public static void GrantAuthToRole(ICollection authIDs, string roleID)
        {
            ICollection <SysAuth> tAuths = GetAuthByIDs(authIDs);

            using (new SessionScope())
            {
                SysRole role = SysRole.Find(roleID);

                using (TransactionScope trans = new TransactionScope())
                {
                    try
                    {
                        foreach (SysAuth auth in tAuths)
                        {
                            role.Auth.Add(auth);
                        }

                        trans.VoteCommit();
                    }
                    catch (Exception ex)
                    {
                        trans.VoteRollBack();

                        throw ex;
                    }
                }
            }
        }