示例#1
0
        public UserFollowUsersReturn GetGroupUsers(string urlkey, string currUserId, int pageIndex = 1, int pageSize = 24, string order = "reputationInGroup")
        {
            bool isLoggedIn = !string.IsNullOrEmpty(currUserId);

            if (isLoggedIn)
            {
                GetUserLikes(currUserId);
            }
            else
            {
                currentUserFollowings = new Dictionary <string, FollowState>();
            }
            UserFollowUsersReturn ret = new UserFollowUsersReturn();
            Group gr = GetGroupFromUrlKey(urlkey);

            if (gr == null)
            {
                return(ret);
            }

            int totalCount = _groupCacheService.GetFollowingUserCount(gr.Id) ??
                             _context.SetChild <UserGroup>().AsNoTracking().Count(p => p.GroupId == gr.Id && p.GroupFollowState == GroupFollowState.Followed);

            if (totalCount == 0)
            {
                return(ret);
            }
            List <UserGroup> followedUsers = _context.SetChild <UserGroup>().AsNoTracking()
                                             .Where(p => p.GroupId == gr.Id && p.GroupFollowState == GroupFollowState.Followed)
                                             .OrderByDescending(p => p.UserReputationInGroup)
                                             .Skip((pageIndex - 1) * pageSize)
                                             .Take(pageSize).ToList();

            var followedUserIds = followedUsers.Select(p => p.UserId);

            if (followedUserIds == null)
            {
                return(ret);
            }
            // Get Followed User Count

            // Get User Data From Database
            ret.Entities = _context.Set <UserInfo>().AsNoTracking().Where(p => followedUserIds.Contains(p.AppUserId))
                           .Select(p => new UserCardModel()
            {
                AppUserId    = p.AppUserId,
                ProfileImage = _userProfileImageSettings.UserImageUrlTemplate.Replace("{#appUserId}", p.AppUserId),
                Username     = p.UName,
            }).ToPaginatedList(pageIndex, pageSize, totalCount);
            // Get Total Reputation
            foreach (var item in ret.Entities)
            {
                item.Reputation = _userCacheService.GetUserReputation(item.AppUserId) ?? GetUserReputation(item.AppUserId, 10);
                // Check if the current user follows the users
                var followState = currentUserFollowings.SingleOrDefault(p => p.Key == item.AppUserId);
                item.FollowState = !isLoggedIn ? FollowState.Unfollowed: followState.Key == null ? FollowState.Unfollowed : followState.Value;
            }
            // return as paginated
            return(ret);
        }
示例#2
0
        public IActionResult GetGroupUsers([FromQuery] PaginatedGroupUrlkeyModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var   user    = HttpContext.User;
            Claim idClaim = User.FindFirst("sub");
            // Get group with followers
            UserFollowUsersReturn ret = _groupDataService.GetGroupUsers(model.Urlkey, idClaim?.Value, model.PageIndex, model.PageSize, model.Order);

            return(Ok(ret));
        }
示例#3
0
        public IActionResult GetUserFollowers([FromQuery] UserNameParameters model)
        {
            Claim idClaim             = User.FindFirst("sub");
            UserFollowUsersReturn ret = new UserFollowUsersReturn
            {
                Entities = _userInfoDataService.GetUserFollowers(model.Username, model.PageIndex, model.PageSize, idClaim?.Value)
            };

            return(Ok(Json(ret)));
            //}
            //catch (System.Exception)
            //{
            //    return BadRequest();
            //}
        }