protected override IQuery <Comment> ApplyWhereClause(IQuery <Comment> query, CommentFilterDto filter)
        {
            var simplePredicate = new SimplePredicate(nameof(Comment.PostId), ValueComparingOperator.Equal, filter.PostId);

            return(filter.PostId.Equals(null)
                ? query
                : query.Where(simplePredicate));
        }
Exemplo n.º 2
0
        protected override IQuery <Comment> ApplyWhereClause(IQuery <Comment> query, CommentFilterDto filter)
        {
            throw new NotImplementedException();

            /*
             * if (string.IsNullOrWhiteSpace(filter.Email))
             * {
             *     return query;
             * }
             * return query.Where(new SimplePredicate(nameof(AppUser.Email), ValueComparingOperator.Equal, filter.Email));
             */
        }
Exemplo n.º 3
0
        public async Task <IActionResult> GetAllCategories(CommentFilterDto filterDto)
        {
            try
            {
                var records = await _commentService.GetAllAsync(filterDto);

                return(PagedOk(records, filterDto, records.TotalPageCount));
            }
            catch (KeyNotFoundException)
            {
                return(NotFound());
            }
        }
Exemplo n.º 4
0
        public async Task <Paged <CommentDto> > GetAllAsync(CommentFilterDto filterDto)
        {
            var result = await _articleRepository.GetCommentsAsync(filterDto);

            var list      = result.List.Select(x => x.Adapt <CommentDto>()).ToList();
            var returnDto = new Paged <CommentDto>
            {
                List           = list,
                PageIndex      = filterDto.PageIndex,
                PageSize       = filterDto.PageSize,
                TotalPageCount = result.TotalPageCount,
                FilteredCount  = result.FilteredCount,
                TotalCount     = result.TotalCount
            };

            return(returnDto);
        }
Exemplo n.º 5
0
        protected override IQuery <Comment> ApplyWhereClause(IQuery <Comment> query, CommentFilterDto filter)
        {
            var definedPredicates = new List <IPredicate>();

            AddIfDefined(FilterAuction(filter), definedPredicates);
            AddIfDefined(FilterUser(filter), definedPredicates);

            if (definedPredicates.Count == 0)
            {
                return(query);
            }
            if (definedPredicates.Count == 1)
            {
                return(query.Where(definedPredicates.First()));
            }
            var resultPredicate = new CompositePredicate(definedPredicates);

            return(query.Where(resultPredicate));
        }
Exemplo n.º 6
0
        public async Task <Paged <Comment> > GetCommentsAsync(CommentFilterDto filterDto)
        {
            var query = _ctx.Comments.Include(x => x.Article).Where(x => !x.IsDeleted);

            if (filterDto.ArticleId != Guid.Empty)
            {
                query = query.Where(x => x.ArticleId == filterDto.ArticleId);
            }

            var totalPagesCount = query.CalculatePageCount(filterDto.PageSize);

            var comments = await query.AsQueryable().OrderBy(filterDto.Ordination)
                           .SkipTake(filterDto.PageIndex, filterDto.PageSize)
                           .ToListAsync();

            return(new Paged <Comment>
            {
                List = comments,
                PageIndex = filterDto.PageIndex,
                PageSize = filterDto.PageSize,
                TotalPageCount = totalPagesCount
            });
        }
Exemplo n.º 7
0
 private static SimplePredicate FilterUser(CommentFilterDto filter)
 {
     return(filter.UserId.Equals(Guid.Empty)
         ? null
         : new SimplePredicate(nameof(Comment.UserId), ValueComparingOperator.Equal, filter.UserId));
 }
Exemplo n.º 8
0
        private async Task <QueryResultDto <CommentDto, CommentFilterDto> > GetCommentsByFilter(CommentFilterDto commentFilter)
        {
            commentFilter.SortCriteria  = nameof(Comment.PostedAt);
            commentFilter.SortAscending = true;
            var comments = await _commentService.GetCommentsByFilter(commentFilter);

            foreach (var comment in comments.Items)
            {
                var user = await _basicUsersService.GetAsync(comment.UserId);

                comment.NickName = user.NickName;
            }

            return(comments);
        }
Exemplo n.º 9
0
        //Get posts by filter, when is commentFilter not null then load also comments
        public async Task <QueryResultDto <UserProfilePostDto, PostFilterDto> > GetPostsWithUsersNicknamesAndCommentsByFilters(PostFilterDto postFilter, CommentFilterDto commentFilter)
        {
            using (UnitOfWorkProvider.Create())
            {
                postFilter.SortCriteria = nameof(Post.PostedAt);
                var posts = await _userProfilePostService.GetPostsByFilterAsync(postFilter);

                foreach (var post in posts.Items)
                {
                    if (postFilter.UserId == null && post.UserId != null)
                    {
                        //Add Nicknames
                        post.NickName = (await _basicUsersService.GetAsync((int)post.UserId)).NickName;
                    }

                    if (commentFilter != null)
                    {
                        commentFilter.PostId = post.Id;
                        post.Comments        = await GetCommentsByFilter(commentFilter);
                    }
                }

                return(posts);
            }
        }
Exemplo n.º 10
0
        public async Task <UserProfileUserDto> GetUserProfile(PostFilterDto postFilter, CommentFilterDto commentFilter)
        {
            using (UnitOfWorkProvider.Create())
            {
                var user = await _userProfileUserService.GetUserProfileUserByIdAsync(postFilter.UserId);

                user.Friends = (await _friendshipService.GetFriendsByUserIdAsync(user.Id, true)).ToList();
                user.Posts   = await GetPostsWithUsersNicknamesAndCommentsByFilters(postFilter, commentFilter);

                return(user);
            }
        }