ShareFactoryNewShareToEverybody Method (IContext, String, Int32, NullableInt32, NullableGuid) |
Create a new instance of share
for everybody and object
Namespace:
AskiaPortalCmn
Assembly:
AskiaPortalCmn (in AskiaPortalCmn.dll) Version: 1.7.0-build068
Syntax public static IShare NewShareToEverybody(
IContext context,
string objectType,
int objectId,
Nullable<int> surveyId = null,
Nullable<Guid> moduleGuid = null
)
Public Shared Function NewShareToEverybody (
context As IContext,
objectType As String,
objectId As Integer,
Optional surveyId As Nullable(Of Integer) = Nothing,
Optional moduleGuid As Nullable(Of Guid) = Nothing
) As IShare
public:
static IShare^ NewShareToEverybody(
IContext^ context,
String^ objectType,
int objectId,
Nullable<int> surveyId = nullptr,
Nullable<Guid> moduleGuid = nullptr
)
Parameters
- context
- Type: AskiaPortalCmnIContext
Context of execution - objectType
- Type: SystemString
Type of the object to share - objectId
- Type: SystemInt32
Id of the object to share - surveyId (Optional)
- Type: SystemNullableInt32
Id of survey from where the object belongs to - moduleGuid (Optional)
- Type: SystemNullableGuid
Guid of the module that manage the object (if null use the CurrentModule).
Return Value
Type:
IShareReturn a new instance of share
for everybody 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 the current module `template` 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;
}
int templateId = 12;
var share = ShareFactory.NewShareToEverybody(context, "template", templateId);
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