/// <summary>
        ///     Retrieves a page of community members from the Episerver Social Framework.
        /// </summary>
        /// <param name="communityMemberFilter">The filter by which to retrieve members by</param>
        /// <returns>The list of members that are part of the specified group.</returns>
        public IEnumerable <CommunityMember> Get(CommunityMemberFilter communityMemberFilter)
        {
            IEnumerable <CommunityMember> returnedMembers = null;

            try
            {
                var compositeFilter = BuildCriteria(communityMemberFilter);

                var compositeMember = _memberService.Get(compositeFilter).Results;
                returnedMembers = compositeMember.Select(x => _communityMemberAdapter.Adapt(x.Data, x.Extension));
            }
            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(returnedMembers);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Render the membership display block view.
        /// </summary>
        /// <param name="currentBlock">The current block instance.</param>
        public override ActionResult Index(MembershipAffiliationBlock currentBlock)
        {
            //Populate model to pass to the membership affiliation view
            var membershipAffiliationBlockModel = new MembershipAffiliationBlockViewModel(currentBlock);

            try
            {
                //Retrieve the groups that are associated with the currently loogged in user.
                var userId = userRepository.GetUserId(this.User);
                if (!String.IsNullOrWhiteSpace(userId))
                {
                    var memberFilter = new CommunityMemberFilter
                    {
                        UserId   = userRepository.CreateAuthenticatedUri(userId),
                        PageSize = currentBlock.DisplayPageSize
                    };
                    var listOfSocialMembers = this.memberRepository.Get(memberFilter);
                    GetAffiliatedGroups(membershipAffiliationBlockModel, listOfSocialMembers);
                }
                //If the user is not logged in let them know they will need to log in to see the groups they are affiliated with
                else
                {
                    var message = "Login to see the list of groups you are affiliated with.";
                    membershipAffiliationBlockModel.Messages.Add(new MessageViewModel(message, ErrorMessage));
                }
            }
            catch (SocialRepositoryException ex)
            {
                membershipAffiliationBlockModel.Messages.Add(new MessageViewModel(ex.Message, ErrorMessage));
            }

            //Return block view with populated model
            return(PartialView("~/Views/Social/MembershipAffiliationBlock/Index.cshtml", membershipAffiliationBlockModel));
        }
        /// <summary>
        /// Build the appropriate CompositeCriteria based the provided CommunityMemberFilter.
        /// The member filter will either contain a group id or a logged in user id. If neitheris provided an exception is thrown.
        /// </summary>
        /// <param name="communityMemberFilter">The provided member filter</param>
        /// <returns>A composite criteria of type MemberFilter and MemberExtensionData</returns>
        private CompositeCriteria <MemberFilter, MemberExtensionData> BuildCriteria(CommunityMemberFilter communityMemberFilter)
        {
            var pageInfo = new PageInfo {
                PageSize = communityMemberFilter.PageSize
            };
            var orderBy = new List <SortInfo> {
                new SortInfo(MemberSortFields.Id, false)
            };
            var compositeCriteria = new CompositeCriteria <MemberFilter, MemberExtensionData>()
            {
                PageInfo = pageInfo,
                OrderBy  = orderBy
            };

            if (!string.IsNullOrEmpty(communityMemberFilter.CommunityId) && (string.IsNullOrEmpty(communityMemberFilter.UserId)))
            {
                compositeCriteria.Filter = new MemberFilter {
                    Group = GroupId.Create(communityMemberFilter.CommunityId)
                };
            }
            else if ((!string.IsNullOrEmpty(communityMemberFilter.UserId) && (string.IsNullOrEmpty(communityMemberFilter.CommunityId))))
            {
                compositeCriteria.Filter = new MemberFilter {
                    User = Reference.Create(communityMemberFilter.UserId)
                };
            }
            else
            {
                throw new SocialException("This implementation of a CommunityMemberFilter should only contain either a CommunityId or a UserReference.");
            }

            return(compositeCriteria);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Render the rating block frontend view.
        /// </summary>
        /// <param name="currentBlock">The current frontend block instance.</param>
        /// <returns>The index action result.</returns>
        public override ActionResult Index(RatingBlock currentBlock)
        {
            var target = PageRouteHelper.Page.ContentGuid.ToString();

            var groupName = PageRouteHelper.Page is CommunityPage
                            ? ((CommunityPage)PageRouteHelper.Page).Memberships.GroupName
                            : "";

            var group = string.IsNullOrEmpty(groupName)
                        ? null
                        : _communityRepository.Get(groupName);

            var currentPageLink = PageRouteHelper.PageLink;

            // Create a rating block view model to fill the frontend block view
            var blockModel = new RatingBlockViewModel(currentBlock, currentPageLink)
            {
                //get messages for view
                Messages = RetrieveMessages(MessageKey)
            };

            // If user logged in, check if logged in user has already rated the page
            if (User.Identity.IsAuthenticated)
            {
                //Validate that the group exists
                if (group != null)
                {
                    var groupId      = group.Id;
                    var memberFilter = new CommunityMemberFilter
                    {
                        CommunityId = groupId,
                        PageSize    = 10000
                    };
                    var socialMembers = _memberRepository.Get(memberFilter).ToList();
                    var userId        = _userRepository.GetUserId(User);
                    blockModel.IsMemberOfGroup = socialMembers.FirstOrDefault(m => m.User.IndexOf(userId) > -1) != null;
                }
                GetRating(target, blockModel);
            }

            //Conditionally retrieving rating statistics based on any errors that might have been encountered
            var noMessages = blockModel.Messages.Count == 0;
            var noErrors   = blockModel.Messages.Any(x => x.Type != ErrorMessage);

            if (noMessages || noErrors)
            {
                GetRatingStatistics(target, blockModel);
            }

            return(PartialView("~/Features/Blocks/Views/RatingBlock.cshtml", blockModel));
        }
        /// <summary>
        /// Render the membership display block view.
        /// </summary>
        /// <param name="currentBlock">The current block instance.</param>
        public override ActionResult Index(MembershipDisplayBlock currentBlock)
        {
            //Populate model to pass to the membership display view
            var membershipDisplayBlockModel = new MembershipDisplayBlockViewModel(currentBlock);

            //Retrieve the group id assigned to the block and populate the member list
            try
            {
                var group = _communityRepository.Get(currentBlock.GroupName);

                //Validate that the group exists
                if (group != null)
                {
                    var groupId      = group.Id;
                    var memberFilter = new CommunityMemberFilter
                    {
                        CommunityId = groupId,
                        PageSize    = currentBlock.NumberOfMembers
                    };
                    var socialMembers = _memberRepository.Get(memberFilter).ToList();
                    membershipDisplayBlockModel.Members = Adapt(socialMembers);
                }
                else
                {
                    var message = "The group configured for this block cannot be found. Please update the block to use an existing group.";
                    membershipDisplayBlockModel.Messages.Add(new MessageViewModel(message, ErrorMessage));
                }
            }
            catch (SocialRepositoryException ex)
            {
                membershipDisplayBlockModel.Messages.Add(new MessageViewModel(ex.Message, ErrorMessage));
            }
            catch (GroupDoesNotExistException ex)
            {
                membershipDisplayBlockModel.Messages.Add(new MessageViewModel(ex.Message, ErrorMessage));
            }

            //Return block view with populated model
            return(PartialView("~/Features/Blocks/Views/MembershipDisplayBlock.cshtml", membershipDisplayBlockModel));
        }