private void LoadAllRoles()
        {
            var rc = new RoleController();
            ArrayList roles = rc.GetRoles();

            foreach (RoleInfo role in roles)
            {
                if (role.PortalID == PortalId)
                {
                    var li = new ListItem(role.RoleName, role.RoleID.ToString(CultureInfo.InvariantCulture));
                    lstItems.Items.Add(li);
                }
            }
        }
        private static string GetUserRoles()
        {
            if (HttpContext.Current != null && HttpContext.Current.User.Identity.IsAuthenticated)
            {
                var sb = new StringBuilder(128);

                UserInfo ui = UserController.GetCurrentUserInfo();
                var rc = new RoleController();

                // Not sure why DNN methods that return roles don't consistently return RoleInfo objects. hk
                if (ui.IsSuperUser)
                {
                    foreach (RoleInfo role in rc.GetRoles())
                    {
                        sb.Append("'");
                        sb.Append(role.RoleName);
                        sb.Append("',");
                    }
                }
                else
                {
                    string[] roles = rc.GetRolesByUser(ui.UserID, ui.PortalID);
                    foreach (string s in roles)
                    {
                        sb.Append("'");
                        sb.Append(s);
                        sb.Append("',");
                    }
                }

                // trim the last ,
                if (sb.Length > 0)
                {
                    sb.Length -= 1;
                }

                return sb.ToString();
            }

            return "'Everyone'"; // is this always 'Everyone'?
        }
        private void DisplayRoles()
        {
            // Get all the Roles
            RoleController RoleController = new RoleController();
            ArrayList colArrayList = RoleController.GetRoles();

            // Create a ListItemCollection to hold the Roles 
            ListItemCollection colListItemCollection = new ListItemCollection();

            // Add the Roles to the List
            foreach (RoleInfo Role in colArrayList)
            {
                if (Role.PortalID == PortalId)
                {
                    ListItem RoleListItem = new ListItem();
                    RoleListItem.Text = Role.RoleName;
                    RoleListItem.Value = Role.RoleID.ToString();
                    colListItemCollection.Add(RoleListItem);
                }
            }

            // Add the Roles to the ListBox
            ddlRole.DataSource = colListItemCollection;
            ddlRole.DataBind();
        }
Exemplo n.º 4
0
        public static string GetRoleName(int RoleID)
        {
            if (Convert.ToString(RoleID) == glbRoleAllUsers)
            {
                return "All Users";
            }
            else if (Convert.ToString(RoleID) == glbRoleUnauthUser)
            {
                return "Unauthenticated Users";
            }

            Hashtable htRoles = null;
            if (PerformanceSetting != PerformanceSettings.NoCaching)
            {
                htRoles = (Hashtable)DataCache.GetCache("GetRoles");
            }

            if (htRoles == null)
            {
                RoleController objRoleController = new RoleController();
                ArrayList arrRoles;
                arrRoles = objRoleController.GetRoles();
                htRoles = new Hashtable();
                int i;
                for (i = 0; i <= arrRoles.Count - 1; i++)
                {
                    RoleInfo objRole;
                    objRole = (RoleInfo)arrRoles[i];
                    htRoles.Add(objRole.RoleID, objRole.RoleName);
                }
                if (PerformanceSetting != PerformanceSettings.NoCaching)
                {
                    DataCache.SetCache("GetRoles", htRoles);
                }
            }
            return Convert.ToString(htRoles[RoleID]);
        }
        private void DisplayAdminRoleDropDown()
        {
            // Get all the Roles
            RoleController RoleController = new RoleController();
            ArrayList colArrayList = RoleController.GetRoles();

            // Create a ListItemCollection to hold the Roles 
            ListItemCollection colListItemCollection = new ListItemCollection();

            // Add the Roles to the List
            foreach (RoleInfo Role in colArrayList)
            {
                if (Role.PortalID == PortalId)
                {
                    ListItem RoleListItem = new ListItem();
                    RoleListItem.Text = Role.RoleName;
                    RoleListItem.Value = Role.RoleID.ToString();
                    colListItemCollection.Add(RoleListItem);
                }
            }

            // Add the Roles to the ListBox
            ddlAdminRole.DataSource = colListItemCollection;
            ddlAdminRole.DataBind();

            // Get Admin Role
            string strAdminRoleID = GetAdminRole();

            try
            {
                // Try to set the role
                ddlAdminRole.SelectedValue = strAdminRoleID;
            }
            catch
            {

            }
        }