I want to create a method to find if the user has the 'Role' for specific 'Company'.
My 'UserRole' table contains 'CompanyId' as foreign key to the company table along with 'UserId' and 'RoleId'.
I am struggling to implement a method to use with the notation like 'User.IsInCompanyRole(role,company)
', as the 'User.IsInRole
' method.
Please guide me on this.
I found a solution as @Zoran mentioned. No need of claims for me right now. Create the extension method works like a charm. Extension Methods (C# Programming Guide)
Here is my extention.
public static class Extention
{
public static bool IsInCompanyRole(this IPrincipal user, string role, int companyId)
{
// Code goes here
}
}
ans usage is simple like
User.IsInEntityRole("Admin",1)