public override IDictionary<string, IEnumerable<string>> FillRights()
{
var rightsWithRoles = new Dictionary<string, IEnumerable<string>>();
using (var conn = this.CreateConnection())
{
if (conn.HasConnection)
{
var sqlQuery = string.Format("SELECT RightName FROM {0}Rights WHERE BlogId = {1}blogid ", this.tablePrefix, this.parmPrefix);
using (var cmd = conn.CreateTextCommand(sqlQuery))
{
cmd.Parameters.Add(conn.CreateParameter(FormatParamName("blogid"), Blog.CurrentInstance.Id.ToString()));
using (var rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
rightsWithRoles.Add(rdr.GetString(0), new HashSet<string>(StringComparer.OrdinalIgnoreCase));
}
}
// Get Right Roles.
cmd.CommandText = string.Format("SELECT RightName, Role FROM {0}RightRoles WHERE BlogId = {1}blogid ", this.tablePrefix, this.parmPrefix);
// don't need to add "blogid" parameter again since the same cmd is being used.
using (var rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
string rightName = rdr.GetString(0);
string roleName = rdr.GetString(1);
if (rightsWithRoles.ContainsKey(rightName))
{
var roles = (HashSet<string>)rightsWithRoles[rightName];
if (!roles.Contains(roleName))
{
roles.Add(roleName);
}
}
}
}
}
}
}
return rightsWithRoles;
}