Beispiel #1
0
        public TrendingPostsReturnModel GetTrendingPosts(int pageIndex, int pageSize, string currUserId, string culture = "WW")
        {
            TrendingPostsReturnModel model = new TrendingPostsReturnModel();

            var popularPosts = _popularitySet.AsNoTracking()
                               .Where(f => f.OnTrendingStartUtcTime != null && f.OnTrendingEndUtcTime == null && f.CultureCode == culture && f.PostId != null)
                               .OrderByDescending(p => p.PopularityLevel)
                               .Skip((pageIndex - 1) * pageSize)
                               .Take(pageSize).Select(f => f.PostId).ToArray();
            int popularPostCount = _popularitySet.AsNoTracking().Where(f => f.OnTrendingStartUtcTime != null && f.OnTrendingEndUtcTime == null && f.PostId != null).Count();

            model.Posts = _postSet.AsNoTracking()
                          .Include(p => p.PostParts).ThenInclude(f => f.Image).Include(p => p.LikedUsers).Include(p => p.UserInfo)
                          .Where(p => popularPosts.Contains(p.Id))
                          .Select(p => new PostCard()
            {
                DateUtcPublished = p.DateUtcPublished,
                Description      = p.Description,
                AuthorInfo       = new BaseUserInfoDisplay()
                {
                    AppUserId    = p.UserInfo.AppUserId,
                    Name         = p.UserInfo.Name,
                    ProfileImage = p.UserInfo.ProfilePicture.SmallPath,
                    Surname      = p.UserInfo.Surname,
                    Username     = p.UserInfo.UName
                },
                Content            = p.Content,
                IsCurrentUserLiked = p.LikedUsers.Any(q => q.UserInfoId == currUserId),
                IsPublished        = p.IsPublished,
                LikeCount          = p.LikedUsers.Count(),
                PostParts          = p.PostParts.Select(f => new PostPartDisplay()
                {
                    Description = f.Description,
                    Image       = new BaseImageReturn()
                    {
                        Dimension = f.Image.ImageDimension,
                        Extension = f.Image.FileExtension,
                        LazyUrl   = f.Image.SmallPath,
                        Url       = f.Image.ResizedPath
                    },
                    Id    = f.Id,
                    Title = f.Title
                }).ToList(),
                ReviewCount = p.Reviews.Count(),
                Id          = p.Id
            })
                          .ToPaginatedList(pageIndex, pageSize, popularPostCount);

            return(model);
        }
Beispiel #2
0
        public TrendingPostsReturnModel GetPosts([FromQuery] int pageSize, int pageIndex, string culture)
        {
            TrendingPostsReturnModel model = new TrendingPostsReturnModel();
            var   user    = HttpContext.User;
            Claim idClaim = User.FindFirst("sub");

            if (string.IsNullOrEmpty(culture))
            {
                culture = "WW";
            }
            if (idClaim != null)
            {
                return(_trendingDataService.GetTrendingPosts(pageIndex, pageSize, idClaim.Value, culture));
            }
            else
            {
                return(_trendingDataService.GetTrendingPosts(pageIndex, pageSize, null, culture));
            }
        }