Exemple #1
0
        /// <summary>
        ///     Submits a membership request to the specified group's
        ///     moderation workflow for approval.
        /// </summary>
        /// <param name="member">The member information for the membership request</param>
        public void AddAModeratedMember(CommunityMember member)
        {
            // Define a unique reference representing the entity
            // under moderation. Note that this entity may be
            // transient or may not yet have been assigned a
            // unique identifier. Defining an item reference allows
            // you to bridge this gap.

            // For example: "members:/{group-id}/{user-reference}"

            var targetReference = CreateUri(member.GroupId, member.User);

            // Retrieve the workflow supporting moderation of
            // membership for the group to which the user is
            // being added.

            var moderationWorkflow = GetWorkflowFor(member.GroupId);

            // The workflow defines the intial (or 'start') state
            // for moderation.

            var initialState = moderationWorkflow.InitialState;

            // Create a new workflow item...

            var workflowItem = new WorkflowItem(
                WorkflowId.Create(moderationWorkflow.Id), // ...under the group's moderation workflow
                new WorkflowState(initialState),          // ...in the workflow's initial state
                Reference.Create(targetReference)         // ...identified with this reference
                );

            var memberRequest = _memberAdapter.Adapt(member);

            try
            {
                _workflowItemService.Add(workflowItem, memberRequest);
            }
            catch (SocialAuthenticationException ex)
            {
                throw new SocialRepositoryException("The application failed to authenticate with Episerver Social.",
                                                    ex);
            }
            catch (MaximumDataSizeExceededException ex)
            {
                throw new SocialRepositoryException(
                          "The application request was deemed too large for Episerver Social.", ex);
            }
            catch (SocialCommunicationException ex)
            {
                throw new SocialRepositoryException("The application failed to communicate with Episerver Social.", ex);
            }
            catch (SocialException ex)
            {
                throw new SocialRepositoryException("Episerver Social failed to process the application request.", ex);
            }
        }
        /// <summary>
        ///     Adds a member to the Episerver Social Framework.
        /// </summary>
        /// <param name="communityMember">The member to add.</param>
        /// <returns>The added member.</returns>
        public CommunityMember Add(CommunityMember communityMember)
        {
            CommunityMember addedSocialMember = null;

            try
            {
                var userReference        = Reference.Create(communityMember.User);
                var groupId              = GroupId.Create(communityMember.GroupId);
                var member               = new Member(userReference, groupId);
                var extensionData        = new MemberExtensionData(communityMember.Email, communityMember.Company);
                var addedCompositeMember = _memberService.Add(member, extensionData);
                addedSocialMember =
                    _communityMemberAdapter.Adapt(addedCompositeMember.Data, addedCompositeMember.Extension);

                if (addedSocialMember == null)
                {
                    throw new SocialRepositoryException("The new member could not be added. Please try again");
                }
            }
            catch (SocialAuthenticationException ex)
            {
                throw new SocialRepositoryException("The application failed to authenticate with Episerver Social.",
                                                    ex);
            }
            catch (MaximumDataSizeExceededException ex)
            {
                throw new SocialRepositoryException(
                          "The application request was deemed too large for Episerver Social.", ex);
            }
            catch (SocialCommunicationException ex)
            {
                throw new SocialRepositoryException("The application failed to communicate with Episerver Social.", ex);
            }
            catch (SocialException ex)
            {
                throw new SocialRepositoryException("Episerver Social failed to process the application request.", ex);
            }

            return(addedSocialMember);
        }