public async Task<IViewComponentResult> InvokeAsync(int count, Guid? gameId, Guid? userId, Guid? oldestId, DateTime? oldestDate, bool? articlesOnly)
        {
            UserPreferencesViewModel preferences = _userPreferencesAppService.GetByUserId(CurrentUserId);

            ActivityFeedRequestViewModel vm = new ActivityFeedRequestViewModel
            {
                CurrentUserId = CurrentUserId,
                Count = count,
                GameId = gameId,
                UserId = userId,
                Languages = preferences.Languages,
                OldestId = oldestId,
                OldestDate = oldestDate,
                ArticlesOnly = articlesOnly
            };

            List<UserContentViewModel> model = _userContentAppService.GetActivityFeed(vm).ToList();

            ApplicationUser user = await UserManager.FindByIdAsync(CurrentUserId.ToString());
            bool userIsAdmin = user != null && await UserManager.IsInRoleAsync(user, Roles.Administrator.ToString());

            foreach (UserContentViewModel item in model)
            {
                if (item.UserContentType == UserContentType.TeamCreation)
                {
                    FormatTeamCreationPost(item);
                }
                if (item.UserContentType == UserContentType.JobPosition)
                {
                    FormatJobPositionPostForTheFeed(item);
                }
                else
                {
                    item.Content = ContentHelper.FormatContentToShow(item.Content);
                }

                foreach (CommentViewModel comment in item.Comments)
                {
                    comment.Text = ContentHelper.FormatHashTagsToShow(comment.Text);
                }

                item.Permissions.CanEdit = !item.HasPoll && (item.UserId == CurrentUserId || userIsAdmin);

                item.Permissions.CanDelete = item.UserId == CurrentUserId || userIsAdmin;
            }

            if (model.Any())
            {
                UserContentViewModel oldest = model.OrderByDescending(x => x.CreateDate).Last();

                ViewData["OldestPostGuid"] = oldest.Id;
                ViewData["OldestPostDate"] = oldest.CreateDate.ToString("o");
            }

            ViewData["IsMorePosts"] = oldestId.HasValue;

            ViewData["UserId"] = userId;

            return await Task.Run(() => View(model));
        }
        public IEnumerable <UserContentViewModel> GetActivityFeed(ActivityFeedRequestViewModel vm)
        {
            try
            {
                List <UserContent> allModels = userContentDomainService.GetActivityFeed(vm.GameId, vm.UserId, vm.Languages, vm.OldestId, vm.OldestDate, vm.ArticlesOnly, vm.Count).ToList();

                IEnumerable <UserContentViewModel> viewModels = mapper.Map <IEnumerable <UserContent>, IEnumerable <UserContentViewModel> >(allModels);

                foreach (UserContentViewModel item in viewModels)
                {
                    UserProfile authorProfile = GetCachedProfileByUserId(item.UserId);
                    if (authorProfile == null)
                    {
                        item.AuthorName = Constants.UnknownSoul;
                    }
                    else
                    {
                        item.AuthorName = authorProfile.Name;
                    }

                    item.AuthorPicture = UrlFormatter.ProfileImage(item.UserId, 40);

                    item.IsArticle = !string.IsNullOrWhiteSpace(item.Title) && !string.IsNullOrWhiteSpace(item.Introduction);

                    item.HasFeaturedImage = !string.IsNullOrWhiteSpace(item.FeaturedImage) && !item.FeaturedImage.Contains(Constants.DefaultFeaturedImage);

                    item.FeaturedMediaType = GetMediaType(item.FeaturedImage);
                    if (item.FeaturedMediaType == MediaType.Youtube)
                    {
                        item.Content = string.Empty;
                    }

                    if (item.FeaturedMediaType != MediaType.Youtube)
                    {
                        item.FeaturedImage           = ContentHelper.SetFeaturedImage(item.UserId, item.FeaturedImage, ImageRenderType.Full);
                        item.FeaturedImageResponsive = ContentHelper.SetFeaturedImage(item.UserId, item.FeaturedImage, ImageRenderType.Responsive);
                        item.FeaturedImageLquip      = ContentHelper.SetFeaturedImage(item.UserId, item.FeaturedImage, ImageRenderType.LowQuality);
                    }

                    item.LikeCount = item.Likes.Count;

                    item.CommentCount = item.Comments.Count;

                    item.Poll = SetPoll(vm.CurrentUserId, item.Id);

                    LoadAuthenticatedData(vm.CurrentUserId, item);


                    item.Content = item.Content.ReplaceCloudname();
                }

                return(viewModels);
            }
            catch (Exception ex)
            {
                string msg = $"Unable to save get the Activity Feed.";
                logger.Log(LogLevel.Error, ex, msg);
                throw;
            }
        }
        public async Task <IViewComponentResult> InvokeAsync(int count, Guid?gameId, Guid?userId, Guid?oldestId, DateTime?oldestDate, bool?articlesOnly)
        {
            UserPreferencesViewModel preferences = _userPreferencesAppService.GetByUserId(CurrentUserId);

            ActivityFeedRequestViewModel vm = new ActivityFeedRequestViewModel
            {
                CurrentUserId = CurrentUserId,
                Count         = count,
                GameId        = gameId,
                UserId        = userId,
                Languages     = preferences.Languages,
                OldestId      = oldestId,
                OldestDate    = oldestDate,
                ArticlesOnly  = articlesOnly
            };

            List <UserContentViewModel> model = _userContentAppService.GetActivityFeed(vm).ToList();

            bool userIsAdmin = User.Identity.IsAuthenticated && User.IsInRole(Roles.Administrator.ToString());

            foreach (UserContentViewModel item in model)
            {
                if (item.UserContentType == UserContentType.TeamCreation)
                {
                    FormatTeamCreationPost(item);
                }
                if (item.UserContentType == UserContentType.JobPosition)
                {
                    FormatJobPositionPostForTheFeed(item);
                }
                else
                {
                    item.Content = ContentFormatter.FormatContentToShow(item.Content);
                    if (item.FeaturedMediaType == MediaType.Youtube)
                    {
                        item.FeaturedImageResponsive = ContentFormatter.GetYoutubeVideoId(item.FeaturedImage);
                        item.FeaturedImageLquip      = ContentHelper.SetFeaturedImage(Guid.Empty, Constants.DefaultFeaturedImageLquip, ImageRenderType.LowQuality);
                    }
                }

                foreach (CommentViewModel comment in item.Comments)
                {
                    comment.Text = ContentFormatter.FormatHashTagsToShow(comment.Text);
                }

                item.Permissions.CanEdit = !item.HasPoll && (item.UserId == CurrentUserId || userIsAdmin);

                item.Permissions.CanDelete = item.UserId == CurrentUserId || userIsAdmin;
            }

            if (model.Any())
            {
                UserContentViewModel oldest = model.OrderByDescending(x => x.CreateDate).Last();

                ViewData["OldestPostGuid"] = oldest.Id;
                ViewData["OldestPostDate"] = oldest.CreateDate.ToString("yyyy-MM-ddTHH:mm:ss.fffffff");
            }

            ViewData["IsMorePosts"] = oldestId.HasValue;

            ViewData["UserId"] = userId;

            return(await Task.Run(() => View(model)));
        }