I have apply looping in datarow and i need to check that if user role is admin, i need to apply some condition.
Now a user can have multiple roles say User Smith has 3 roles: Admin, Developer and Tester. Hence for smith the condition comes true. For Jane she has 4 roles: Developer, Tester, Analyst & Normal user, so for jane the condition become false (as she is not admin)
Now i have written code as
// filling up the dataTable.
DataTable dtAssignedRoles = (DataTable (Session[GlobalConstants.SESSION_USER_ASSGN_ROLE_DT]);
if (dtAssignedRoles != null && dtAssignedRoles.Rows.Count > 0)
{
foreach (DataRow dr in dtAssignedRoles.Rows)
{
if (dr["OT_ROLE"].ToString().ToUpper().Equals("ADMIN"))
{
// apply condition for admin here!
}
}
}
// Condition that would execute for Jane
if (strICol.Equals("N"))
{
e.Row.Cells[0].Text = string.Empty;
e.Row.Cells[0].Controls.Clear();
Image imgIColumnDesc = new Image();
imgIColumnDesc.ImageUrl = "~/Images/blackcircle.png";
e.Row.Cells[0].Controls.Add(imgIColumnDesc);
}
Problem: For smith the condition fails as although he is admin, he is also developer and tester. hence 2 conditions get applied; one for admin and another for non-admin (dev + tester)
Hence i guess, i need to check in all the rows and if there is one role with admin, the condition should be met. But i don’t know how to do it?
Please guide. Thanks
You can use this helper function to determine if a user has a particular role…
EDIT: OR with Linq
Then to use…