Click or drag to resize

ShareFactory.FindRule Method (IContext, String, Int32, IUser, Nullable<Int32>, Nullable<Guid>)

Find or calculate the appropriate share rule applied on the specified object and user, return null if no rule found.

Namespace:  AskiaPortalCmn
Assembly:  AskiaPortalCmn (in AskiaPortalCmn.dll) Version: 1.7.0-build068
Syntax
public static IShareRule FindRule(
	IContext context,
	string objectType,
	int objectId,
	IUser user,
	Nullable<int> surveyId = null,
	Nullable<Guid> moduleGuid = null
)

Parameters

context
Type: AskiaPortalCmn.IContext
Context of execution.
objectType
Type: System.String
Type of object to find.
objectId
Type: System.Int32
Id of the object to find.
user
Type: AskiaPortalCmn.IUser
Contact to find.
surveyId (Optional)
Type: System.Nullable<Int32>
Id of the survey, to scope the search.
moduleGuid (Optional)
Type: System.Nullable<Guid>
Guid of the module that manage the object (if null use the CurrentModule).

Return Value

Type: IShareRule
Return null if the share rule was not found or if the user within the context doesn't have enough right to access it
Remarks

This method return the more accurate share.

- If the share is apply on the group and the user, the share of the user will be returned.
- The share apply on group closer to the user will be returned.

The rule find could be a database record or a calculated rule, specially for administrators.

A user that can manage a group is like a membership of that group.

Examples

Find if the `template` with id 5, is share to the user.

var context = ContextFactory.CreateByUserGuid(Guid.Parse("20BE5F84-F006-49A0-9674-4B16A090AF2D"));   
var contextValidation = context.Validate();
if (!contextValidation.Success)
{
    throw contextValidation.Exception;
}
var user = UserFactory.FindById(context, 2);
if (user == null)
{
    Console.WriteLine("The specified user doesn't exist, or the current user within the context could not access it");
}

var share = ShareFactory.FindRule(context, "template", 5, user);
if (share != null)
{
    Console.WriteLine($@"The user {user.FirstName} {user.LastName} have the {share.Permission} on the `{share.ObjectType}` {share.ObjectId}");
}
else
{
    Console.WriteLine($@"The user {user.FirstName} {user.LastName} could not access the specified `template` object");
}
See Also