I'm filtering Contact_data by the user's permission e.i super_admins can pull all Contact_data and normal_users can only pull their own Contact_data.
this is my query:
var contacts= db.Contacts.Where(x => x.Contact != null); // unfilteres & returns all contacts
int UserId = Convert.ToInt32(Session["UserId"].ToString()); // returns the logged-in user id
if (user.Role.Name != "Super Administrator")
{
contacts= db.Contacts.Where(x => x.CreatedBy == UserId); //CreatedBy is type int
}
else
{
contacts= db.Contacts.Where(x => x.Contact != null);
}
I get the error: Object reference not set to an instance of an object. //if (user.Role.Name != "Super Administrator")
What am I doing wrong?