Reputation: 21
I have a user Control called DisabledControl. I need to create 1 if statement with these two conditions.
public static class DisabledControl
{
public static void AdminOnly(this Control control)
{
control.Enabled = User.IsInRole(new string[] { "Administrator" });
}
public static void OwnerOnly(this Control control, int ownerID)
{
control.Enabled = (User.ID == ownerID);
}
}
//I need help with syntax: if User isinRole 'Adminstrator" && user is OwnerOnly, btnSave.Enabled=true.
//I tried to use if user.id == OwnerOnly, it gives error.
Upvotes: 2
Views: 82
Reputation:
You can't do user.id == OwnerOnly
because OwnerOnly
is a method that returns void
. You would need user.id == ownerID
, or change OwnerOnly
to return a boolean
.
In response to your comments, try something like this:
public static void SetEnabledForAdminOrOwner(this Control control, int ownerID)
{
control.Enabled = User.IsInRole(new string[] { "Administrator" }) || User.ID == ownerID;
}
Upvotes: 1