Click or drag to resize

ShareFactoryNewShareToGroup Method (IContext, ShareObjectType, Int32, IGroup, NullableInt32)

Create a new instance of share for the specified group and `AskiaPortal` object

Namespace:  AskiaPortalCmn
Assembly:  AskiaPortalCmn (in AskiaPortalCmn.dll) Version: 1.7.0-build068
Syntax
public static IShare NewShareToGroup(
	IContext context,
	ShareObjectType objectType,
	int objectId,
	IGroup group,
	Nullable<int> surveyId = null
)

Parameters

context
Type: AskiaPortalCmnIContext
Context of execution
objectType
Type: AskiaPortalCmnShareObjectType
Type of the `AskiaPortal` object to share
objectId
Type: SystemInt32
Id of the object to share
group
Type: AskiaPortalCmnIGroup
Group to share with
surveyId (Optional)
Type: SystemNullableInt32
Id of survey from where the object belongs to

Return Value

Type: IShare
Return a new instance of share for the specified group and object or null if the user in the context doesn't have enough right to create this share
Examples

Create a new share for AskiaPortal `survey` object and save it

var context = ContextFactory.CreateByUserGuid(Guid.Parse("20BE5F84-F006-49A0-9674-4B16A090AF2D"));   
var contextValidation = context.Validate();
if (!contextValidation.Success)
{
    throw contextValidation.Exception;
}

// Sharing information
IGroup targetGroup = GroupFactory.FindById(context, 4);
if (targetGroup == null)
{
    Console.Error.WriteLine("Could not find the specified group");
    return;
}

var share = ShareFactory.NewShareToGroup(context, ShareObjectType.Survey, 12, targetGroup);
if (share == null)
{
    Console.Error.WriteLine("Could not create this share");
    return;
}

share.Permission = AccessLevel.ReadOnly;
share.CanReshare = false;

var saveResult = share.Save();
if (saveResult.Success)
{
    Console.WriteLine("The share (Id={0}) was successfully saved",
                                    share.Id);
}
else
{
    Console.Error.Write(saveResult.Exception.Message);
}
See Also