Exemplo n.º 1
0
        /// <summary>
        /// Gets user emails for a specified role.
        /// </summary>
        /// <param name="roleName">
        /// The role name.
        /// </param>
        /// <returns>
        /// Returns user's emails.
        /// </returns>
        private string GetRoleMembers(string roleName)
        {
            IEnumerable <string> emails = null;
            Role role = Role.Exists(roleName) ? Role.FromName(roleName) : null;

            if (role != null)
            {
                IEnumerable <Account> users = RolesInRolesManager.GetRoleMembers(role, false).Where(account => account.AccountType == AccountType.User);
                emails = users.Where(user => !string.IsNullOrEmpty(((User)user).Profile.Email)).Select(user => ((User)user).Profile.Email);
            }

            string emailList = emails != null?string.Join(",", emails.ToArray()) : null;

            return(emailList);
        }
Exemplo n.º 2
0
        protected override void ProcessRecord()
        {
            if (!this.CanFindAccount(Identity, AccountType.Role))
            {
                return;
            }

            var role = Role.FromName(Identity.Name);

            switch (ParameterSetName)
            {
            case "Id":
                WriteObject(RolesInRolesManager.GetRoleMembers(role, Recursive), true);
                break;

            case "UsersOnly":
                WriteObject(RolesInRolesManager.GetUsersInRole(role, Recursive), true);
                break;

            case "RolesOnly":
                WriteObject(RolesInRolesManager.GetRolesInRole(role, Recursive), true);
                break;
            }
        }