コード例 #1
0
ファイル: RoleProvider.cs プロジェクト: jy4618272/Common
        /// <summary>
        /// Returns the identifier of the role with specified name.
        /// </summary>
        /// <param name="name">The name of the role.</param>
        /// <returns>The identifier of the role with specified name.</returns>
        public static Guid GetRoleIdByName(string name)
        {
            Guid roleId = Guid.Empty;

            if (!string.IsNullOrEmpty(name))
            {
                ConfigurationDataSet.RoleDataTable table = ConfigurationDataSet.Current.Role.Copy() as ConfigurationDataSet.RoleDataTable;
                ConfigurationDataSet.RoleRow[]     rows  = table.Select(string.Concat(table.NameColumn.ColumnName, " = '", name.Replace("'", "''"), "'")) as ConfigurationDataSet.RoleRow[];
                if (rows.Length > 0)
                {
                    roleId = rows[0].RoleId;
                }
            }
            return(roleId);
        }
コード例 #2
0
ファイル: RoleProvider.cs プロジェクト: jy4618272/Common
        internal static ArrayList GetRoleIdListByShortNames(ConfigurationDataSet.RoleDataTable table, IEnumerable shortName)
        {
            ArrayList roleIdList = new ArrayList();

            if ((table != null) && (shortName != null))
            {
                StringBuilder sb = new StringBuilder();
                foreach (string name in shortName)
                {
                    if (string.Compare(name, "*", StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        if (sb.Length > 0)
                        {
                            sb.Remove(0, sb.Length - 1);
                        }
                        break;
                    }
                    sb.AppendFormat(",'{0}'", name.Replace("'", "''"));
                }

                if (sb.Length > 0)
                {
                    sb.Remove(0, 1);
                    sb.Append(")");
                    sb.Insert(0, string.Concat(table.ShortNameColumn.ColumnName, " IN ("));
                }

                foreach (ConfigurationDataSet.RoleRow row in table.Select(sb.ToString()))
                {
                    if (!roleIdList.Contains(row.RoleId))
                    {
                        roleIdList.Add(row.RoleId);
                    }
                }
            }

            return(roleIdList);
        }