Пример #1
0
        public async Task <IReadOnlyList <UserRank> > GetUserRanksAsync(string userId)
        {
            var postFilterSpecification = new PostFilterSpecification(new PostSearchParams {
                UserId = userId
            });
            int userPostsCount = await _postRepository.GetTotalCountAsync(postFilterSpecification);

            double userPostRank = await _userRepository.GetUserRank <PostVote>(userId) / userPostsCount;

            var commentFilterSpecification = new CommentFilterSpecification(new CommentSearchParams {
                UserId = userId
            });
            int userCommentsCount = await _commentRepository.GetTotalCountAsync(commentFilterSpecification);

            double userCommentRank = await _userRepository.GetUserRank <CommentVote>(userId) / userCommentsCount;

            var userRanks = new List <UserRank>
            {
                new UserRank {
                    Entity = nameof(Post), Rank = userPostRank
                },
                new UserRank {
                    Entity = nameof(Comment), Rank = userCommentRank
                },
            };

            return(userRanks);
        }
Пример #2
0
        public async Task <IEnumerable <Comment> > ListAsync(long?customerId = null, long?propertyId = null, long?transactionId = null)
        {
            var spec = new CommentFilterSpecification(
                customerId: customerId,
                propertyId: propertyId,
                transactionId: transactionId
                );

            return(await _commentRepository.ListAsync(spec));
        }
Пример #3
0
        public async Task <IEnumerable <CommentViewModel> > GetCommentsAsync(CommentSearchParams searchParams)
        {
            User user = await _userManager.FindByIdAsync(searchParams.UserId);

            Guard.Against.NullItem(user.Id, nameof(user));

            var specification = new CommentFilterSpecification(searchParams);

            return(await _commentRepository.ListAsync <CommentViewModel>(specification,
                                                                         CommentHelpers.GetCommentMapperConfiguration()));
        }
Пример #4
0
        public async Task <int> GetCommentsCountAsync(CommentSearchParams searchParams)
        {
            User user = await _userManager.FindByIdAsync(searchParams.UserId);

            Guard.Against.NullItem(user, nameof(user));

            Post post = await _postRepository.GetByConditionAsync(x => x.Id == searchParams.PostId);

            Guard.Against.NullItem(post, nameof(post));

            var specification = new CommentFilterSpecification(searchParams);

            return(await _commentRepository.GetTotalCountAsync(specification));
        }
Пример #5
0
        public async Task <IReadOnlyList <Ranks> > GetCommentRanksAsync()
        {
            IReadOnlyList <Ranks> userRanks = await _userRepository.ListRanks <CommentVote>();

            foreach (Ranks userRank in userRanks)
            {
                var specification = new CommentFilterSpecification(new CommentSearchParams {
                    UserId = userRank.UserId
                });
                int userCommentsCount = await _commentRepository.GetTotalCountAsync(specification);

                userRank.Rank /= userCommentsCount;
            }

            return(userRanks);
        }