Пример #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 <ListPostViewModel> GetByBrandName(string brandName)
        {
            var specification = new PostFilterSpecification(brandName);
            var listPost      = new ListPostViewModel();
            var posts         = _repository.List(specification)
                                .Select(x => new ListPostItem {
                CarType         = x.Category.CarType.ToString(),
                City            = x.City,
                CreatedDate     = x.CreatedDate,
                DrivenDistance  = x.Car.DrivenDistance,
                Id              = x.Id.ToString(),
                Images          = x.Car.Images,
                IsImported      = x.Category.IsImported,
                IsUsed          = x.Category.IsUsed,
                ManufactureYear = x.Car.ManufactureYear,
                Phone           = x.User.PhoneNumber,
                Price           = x.Car.Price,
                Title           = x.Title,
                Tranmission     = x.Category.Transmission.ToString()
            });

            listPost.Items = await posts.ToListAsync();

            return(listPost);
        }
Пример #3
0
        public async Task <int> GetPostsCountInNewsFeed(string userId, PostSearchParams searchParams)
        {
            Community community =
                await _communityRepository.GetByConditionAsync(x => x.Name == searchParams.CommunityName);

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

            searchParams.Followers = await _userRepository.ListUserFollowingsAsync(userId);

            var specification = new PostFilterSpecification(searchParams);

            return(await _postRepository.GetTotalCountAsync(specification));
        }
Пример #4
0
        public async Task <IEnumerable <PostViewModel> > GetNewsFeedPosts(string userId, PostSearchParams searchParams)
        {
            Community community =
                await _communityRepository.GetByConditionAsync(x => x.Name == searchParams.CommunityName);

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

            searchParams.Followers = await _userRepository.ListUserFollowingsAsync(userId);

            var specification = new PostFilterSpecification(searchParams);

            return(await _postRepository.ListAsync <PostViewModel>(specification,
                                                                   PostHelpers.GetPostMapperConfiguration()));
        }
Пример #5
0
        public async Task <int> GetPostsCountAsync(PostSearchParams searchParams)
        {
            Community community =
                await _communityRepository.GetByConditionAsync(x => x.Name == searchParams.CommunityName);

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

            User user = await _userManager.FindByIdAsync(searchParams.UserId);

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

            var specification = new PostFilterSpecification(searchParams);

            return(await _postRepository.GetTotalCountAsync(specification));
        }
Пример #6
0
        public async Task <IEnumerable <PostViewModel> > GetPostsAsync(PostSearchParams searchParams)
        {
            User user = await _userManager.FindByIdAsync(searchParams.UserId);

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

            Community community =
                await _communityRepository.GetByConditionAsync(x => x.Name == searchParams.CommunityName);

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

            var specification = new PostFilterSpecification(searchParams);

            return(await _postRepository.ListAsync <PostViewModel>(specification,
                                                                   PostHelpers.GetPostMapperConfiguration()));
        }
Пример #7
0
        public async Task <IReadOnlyList <Ranks> > GetPostRanksAsync()
        {
            IReadOnlyList <Ranks> userRanks = await _userRepository.ListRanks <PostVote>();

            foreach (Ranks userRank in userRanks)
            {
                var specification = new PostFilterSpecification(new PostSearchParams {
                    UserId = userRank.UserId
                });
                int userPostsCount = await _postRepository.GetTotalCountAsync(specification);

                userRank.Rank /= userPostsCount;
            }

            return(userRanks);
        }
Пример #8
0
        public async Task <IEnumerable <Post> > GetByKeywordAsync(string keyword)
        {
            var filter = new PostFilterSpecification(keyword);

            return(await postRepository.ListAsync(filter));
        }
Пример #9
0
        public IEnumerable <Post> GetAll()
        {
            var filter = new PostFilterSpecification();

            return(postRepository.List(filter));
        }