예제 #1
0
        public ICollection <InterestCard> GetPostGroups(int postId, string currUserId)
        {
            bool isLoggedIn = !string.IsNullOrEmpty(currUserId);

            int[] gp = _context.SetChild <GroupPost>().AsNoTracking().Where(p => p.PostId == postId).Select(p => p.GroupId).ToArray();
            IQueryable <InterestCard> ret = _context.Set <Group>().AsNoTracking()
                                            .Select(p => new InterestCard()
            {
                AlphaColor   = p.ColorAlpha,
                Id           = p.Id,
                Name         = p.Name,
                UrlKey       = p.UrlKey,
                ProfileImage = p.ProfileImage.SmallPath
            })
                                            .Where(p => gp.Contains(p.Id));

            foreach (var item in ret)
            {
                item.FollowerCount          = _groupCacheService.GetFollowingUserCount(item.Id) ?? _groupDataService.GetGroupFollowerCount(item.Id, 20);
                item.IsCurrentUserFollowing = !isLoggedIn ? false : userGroupFollowIds.Contains(item.Id);
            }
            return(ret.ToList());
        }