Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public PaginatedUserInfoRecommendation GetPaginatedUserRecommendations(string currUserId, string[] followingUserIds, int[] followingGroups, PaginatedRequest parameters)
        {
            PaginatedUserInfoRecommendation ret = new PaginatedUserInfoRecommendation();

            string[] currUserFollowingIds = currentUserFollowings.Where(p => p.Value == FollowState.Confirmed).Select(p => p.Key).ToArray();

            string[] reccIds = _context.SetChild <FollowInfo>()
                               .AsNoTracking()
                               .Where(p => followingUserIds.Contains(p.FollowerId) && p.FollowState == FollowState.Confirmed && !currUserFollowingIds.Contains(p.FollowedId) && p.FollowedId != currUserId)
                               .OrderByDescending(p => p.DateUtcFollowed)
                               .Skip((parameters.PageIndex - 1) * parameters.PageSize)
                               .Take(parameters.PageSize)
                               .Select(f => f.FollowedId)
                               .ToArray();

            ret.Entities = _context.Set <UserInfo>().AsNoTracking().Where(p => reccIds.Contains(p.AppUserId))
                           .Select(p => new UserCardModel()
            {
                AppUserId    = p.AppUserId,
                ProfileImage = _userProfileImageSettings.UserImageUrlTemplate.Replace("{#appUserId}", p.AppUserId),
                Username     = p.UName,
            }).ToPaginatedList(parameters.PageIndex, parameters.PageSize, int.MaxValue);
            // Get Total Reputation
            foreach (var item in ret.Entities)
            {
                item.Reputation = _userCacheService.GetUserReputation(item.AppUserId) ?? GetUserReputation(item.AppUserId, 1);
                // Check if the current user follows the users fetched from database
                var followState = currentUserFollowings.SingleOrDefault(p => p.Key == item.AppUserId);
                item.FollowState = followState.Key == null ? FollowState.Unfollowed : followState.Value;
            }

            // return as paginated
            return(ret);
        }
Ejemplo n.º 3
0
        public UserInfoProfileReturn GetUserProfileInfo(string userName, string currUserId)
        {
            UserInfoProfileReturn ret;
            var uInfo = _context.Set <UserInfo>().AsNoTracking().Select(p => new { Entity = p, p.ProfilePicture }).FirstOrDefault(p => p.Entity.UName == userName);

            if (uInfo == null)
            {
                ret = new UserInfoProfileReturn();
                ret.IsActionSucceed                  = false;
                ret.ErrorInformation.ErrorType       = ErrorType.NotFound;
                ret.ErrorInformation.UserInformation = "User not found!";
                return(ret);
            }
            var followEntity   = _context.SetChild <FollowInfo>().AsNoTracking().FirstOrDefault(p => p.FollowerId == currUserId && p.FollowedId == uInfo.Entity.AppUserId);
            var followedEntity = _context.SetChild <FollowInfo>().AsNoTracking().FirstOrDefault(p => p.FollowerId == uInfo.Entity.AppUserId && p.FollowedId == currUserId);
            var followState    = followEntity == null ? FollowState.Unfollowed : followEntity.FollowState;
            var followedState  = followedEntity == null ? FollowState.Unfollowed : followedEntity.FollowState;

            ret = new UserInfoProfileReturn()
            {
                Id                       = uInfo.Entity.Id,
                Status                   = uInfo.Entity.Status,
                AppUserId                = uInfo.Entity.AppUserId,
                AlphaColor               = uInfo.Entity.AlphaColor,
                Username                 = uInfo.Entity.UName,
                Name                     = uInfo.Entity.Name,
                TotalReputation          = _userCacheService.GetUserReputation(uInfo.Entity.AppUserId) ?? GetUserReputation(uInfo.Entity.AppUserId, 0),
                ProfileImageUrl          = uInfo.Entity.ProfilePicture.SmallPath,
                Surname                  = uInfo.Entity.Surname,
                InterestCount            = _userCacheService.GetUserInterestCount(uInfo.Entity.AppUserId) ?? GetUserInterestCount(uInfo.Entity.AppUserId, 60),
                FollowingCount           = _userFollowCacheService.GetUserFollowingCount(uInfo.Entity.AppUserId) ?? GetUserFollowingCount(uInfo.Entity.AppUserId, 60),
                FollowerCount            = _userFollowCacheService.GetUserFollowerCount(uInfo.Entity.AppUserId) ?? GetUserFollowerCount(uInfo.Entity.AppUserId, 60),
                FollowingState           = followState,
                CurrentUserFollowedState = followedState,
            };
            return(ret);
        }