public DeleteAuthorityGroupResponse DeleteAuthorityGroup(DeleteAuthorityGroupRequest request)
        {
            var broker         = PersistenceContext.GetBroker <IAuthorityGroupBroker>();
            var authorityGroup = PersistenceContext.Load <AuthorityGroup>(request.AuthorityGroupRef, EntityLoadFlags.Proxy);

            if (request.DeleteOnlyWhenEmpty)
            {
                var count = broker.GetUserCountForGroup(authorityGroup);
                if (count > 0)
                {
                    throw new AuthorityGroupIsNotEmptyException(authorityGroup.Name, count);
                }
            }

            // before we can delete an authority group, first need to remove all tokens and users
            authorityGroup.AuthorityTokens.Clear();
            authorityGroup.RemoveAllUsers();

            // delete group
            broker.Delete(authorityGroup);

            PersistenceContext.SynchState();

            return(new DeleteAuthorityGroupResponse());
        }
Beispiel #2
0
        public DeleteAuthorityGroupResponse DeleteAuthorityGroup(DeleteAuthorityGroupRequest request)
        {
            Platform.CheckForNullReference(request, "request");
            Platform.CheckMemberIsSet(request.AuthorityGroupRef, "AuthorityGroupRef");

            var broker         = PersistenceContext.GetBroker <IAuthorityGroupBroker>();
            var authorityGroup = PersistenceContext.Load <AuthorityGroup>(request.AuthorityGroupRef, EntityLoadFlags.Proxy);

            if (authorityGroup.BuiltIn)
            {
                throw new RequestValidationException(SR.MessageCannotManageBuiltInAuthorityGroups);
            }

            if (request.DeleteOnlyWhenEmpty)
            {
                var count = broker.GetUserCountForGroup(authorityGroup);
                if (count > 0)
                {
                    throw new AuthorityGroupIsNotEmptyException(authorityGroup.Name, count);
                }
            }

            // before we can delete an authority group, first need to remove all tokens and users
            authorityGroup.AuthorityTokens.Clear();
            authorityGroup.RemoveAllUsers();

            // delete group
            broker.Delete(authorityGroup);

            PersistenceContext.SynchState();

            return(new DeleteAuthorityGroupResponse());
        }