ShareFactoryNewShareToUser Method (IContext, ShareObjectType, Int32, IUser, NullableInt32) |
Namespace: AskiaPortalCmn
public static IShare NewShareToUser( IContext context, ShareObjectType objectType, int objectId, IUser user, Nullable<int> surveyId = null )
Create a new share for the survey 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 IUser targetUser = UserFactory.FindById(context, 3); if (targetUser == null) { Console.Error.WriteLine("Could not find the specified user"); return; } var share = ShareFactory.NewShareToUser(context, ShareObjectType.Survey, 12, targetUser); 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); }