I have problem with management a grants for an user enabled for two/three different areas, for example, a user with this profile I don't have problems:
User = Foo
Area = East
Level = 2
Instead, for a user profile:
User = Pluto
Area = East
Area = West
Level = 2
The statement Users() that performs access control on a table of authorized users according to the area of membership and the expected level (0, 1 and 2) takes into account only the West Area User Pluto, rather than enable both Area East and West.
My code below.
Any help would be appreciated, thanks in advance.
protected void Users()
{
using (OdbcConnection conn =
new OdbcConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString))
{
sql = " SELECT * FROM ";
sql = sql + " tblUsers ";
sql = sql + " WHERE (Email = ? ";
sql = sql + " AND degree IS NOT NULL); ";
using (OdbcCommand command =
new OdbcCommand(sql, conn))
{
try
{
command.Parameters.AddWithValue("param1", Server.UrlDecode(Request.Cookies["email"].Value));
command.Connection.Open();
using (OdbcDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
degree = reader["degree"].ToString();
area = reader["Area"].ToString();
}
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
command.Connection.Close();
}
}
}
}
EDIT 1
string Level;
string Area;
public class GrantUser
{
public string Area { get; set; }
public string Level { get; set; }
public GrantUser() { }
public GrantUser(string Area, string Level)
{
this.Area = Area;
this.Level = Level;
}
}
protected void Users()
{
using (OdbcConnection conn =
new OdbcConnection(ConfigurationManager.ConnectionStrings["cn"].ConnectionString))
{
sql = " SELECT * FROM tblUsers WHERE (Email = ? AND Level IS NOT NULL); ";
using (OdbcCommand command =
new OdbcCommand(sql, conn))
{
try
{
command.Parameters.AddWithValue("param1", Server.UrlDecode(Request.Cookies["email"].Value));
command.Connection.Open();
List<GrantUser> lsGrantUser = new List<GrantUser>();
using (OdbcDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
Level = reader["Level"].ToString();
Area = reader["Area"].ToString();
lsGrantUser.Add(new GrantUser(reader["Area"].ToString(), reader["Level"].ToString()));
}
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
command.Connection.Close();
}
}
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Label area = (Label)e.Row.FindControl("Area");
if (!string.IsNullOrEmpty(Level.ToString()))
{
if (Level.ToString() == "0")
{
//here the condition 0
}
if (Level.ToString() == "1")
{
if (area.Text == Area.ToString())
{
//here the condition 1
}
}
if (Level.ToString() == "2")
{
if (area.Text == Area.ToString())
{
//here the condition 2
}
}
}
}
}
public DataTable GridViewBind()
{
sql = " SELECT ....... ; ";
try
{
dadapter = new OdbcDataAdapter(sql, conn);
dset = new DataSet();
dset.Clear();
dadapter.Fill(dset);
DataTable dt = dset.Tables[0];
GridView1.DataSource = dt;
conn.Open();
GridView1.DataBind();
if (dt.Rows.Count == 0)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('No data.');", true);
}
return dt;
}
catch (Exception ex)
{
throw ex;
}
finally
{
dadapter.Dispose();
dadapter = null;
conn.Close();
}
}
EDIT 2
Users();
GridView1.DataBind();