Пример #1
0
        /// <summary>
        ///     从数据源中移除已配置的 applicationName 的角色。
        /// </summary>
        /// <param name="roleName"></param>
        /// <param name="throwOnPopulatedRole">如果为 true,则在 roleName 具有一个或多个成员时引发异常,并且不删除 roleName。</param>
        /// <returns></returns>
        /// <exception cref="ProviderException">more than one user reference role named</exception>
        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            SessionWrapper s = SessionManager.GetSessionWrapper();

            try
            {
                IRoleDao roleDao = OrnamentContext.DaoFactory.MemberShipFactory.CreateRoleDao();
                if (throwOnPopulatedRole)
                {
                    if (roleDao.IsUsesInRole(roleName))
                    {
                        throw new ProviderException("more than one user reference role named " + roleName);
                    }
                }
                roleDao.Delete(new Role(roleName));
                return(true);
            }
            catch
            {
                return(false);
            }
            finally
            {
                s.Close();
            }
        }