Beispiel #1
0
        public override string[] GetUsersInRole(string roleName)
        {
            var userNames = new List <string>();

            using (var transaction = new TransactionScope(mConfiguration))
            {
                var  rDS  = new RoleDataStore(transaction);
                Role role = rDS.FindByName(mApplicationName, roleName);
                var  userInRoleDataStore = new UserInRoleDataStore(transaction);

                IList <UserInRole> listUserInRole = userInRoleDataStore.FindForRole(ApplicationName, role);

                foreach (UserInRole ur in listUserInRole)
                {
                    userNames.Add(ur.User.Name);
                }
            }

            return(userNames.ToArray());
        }
Beispiel #2
0
        public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
        {
            using (var transaction = new TransactionScope(mConfiguration))
            {
                var roleStore           = new RoleDataStore(transaction);
                var userInRoleDataStore = new UserInRoleDataStore(transaction);

                //Find role
                Role role = roleStore.FindByName(ApplicationName, roleName);
                if (role == null)
                {
                    throw new RoleNotFoundException(roleName);
                }

                IList <UserInRole> listUserInRole = userInRoleDataStore.FindForRole(ApplicationName, role);

                if (throwOnPopulatedRole && listUserInRole.Count > 0)
                {
                    throw new ProviderException("Cannot delete a populated role.");
                }

                foreach (UserInRole ur in listUserInRole)
                {
                    ur.Deleted = true;
                    userInRoleDataStore.Update(ur);
                }

                role.Deleted = true;
                role.Name   += DateTimeHelper.GetCurrentTimestamp();
                roleStore.Update(role);

                transaction.Commit();
            }

            return(true);
        }