Пример #1
0
        /// <summary>
        /// Render the feed block frontend view.
        /// </summary>
        /// <param name="currentBlock">The current frontend block instance.</param>
        /// <returns>The action's result.</returns>
        public override ActionResult Index(FeedBlock currentBlock)
        {
            // Create a feed block view model to fill the frontend block view
            var blockViewModel = new FeedBlockViewModel(currentBlock)
            {
                Messages = new List <MessageViewModel>()
            };

            // If user logged in, retrieve activity feed for logged in user
            if (User.Identity.IsAuthenticated)
            {
                GetSocialActivityFeed(currentBlock, blockViewModel);
            }

            return(PartialView("~/Features/Blocks/FeedBlock/FeedBlock.cshtml", blockViewModel));
        }
Пример #2
0
        /// <summary>
        /// Gets the activity feed for the logged in user
        /// </summary>
        /// <param name="currentBlock">The current frontend block instance.</param>
        /// <param name="blockViewModel">a reference to the FeedBlockViewModel to
        ///populate with activity feed for the logged in user and errors, if any</param>
        private void GetSocialActivityFeed(FeedBlock currentBlock, FeedBlockViewModel blockViewModel)
        {
            try
            {
                var userId = _userRepository.GetUserId(User);

                if (!string.IsNullOrWhiteSpace(userId))
                {
                    blockViewModel.Feed = _feedRepository.Get(new CommunityFeedFilter
                    {
                        Subscriber = userId,
                        PageSize   = currentBlock.FeedDisplayMax
                    });
                }
                else
                {
                    blockViewModel.Messages.Add(new MessageViewModel(ErrorGettingUserIdMessage, ErrorMessage));
                }
            }
            catch (SocialRepositoryException ex)
            {
                blockViewModel.Messages.Add(new MessageViewModel(ex.Message, ErrorMessage));
            }
        }