public ToDoCommentWithFiltersForCountSpec(GetToDoCommentListQuery query)
     : base(x =>
            (!query.ToDoId.HasValue || x.TodoId.Equals(query.ToDoId)) &&
            (!query.Comment.HasValue() || x.Comment.ToLower().Contains(query.Comment))
            )
 {
 }
示例#2
0
        public async Task <Pagination <ToDoCommentResponse> > Handle(GetToDoCommentListQuery request, CancellationToken cancellationToken)
        {
            var spec       = new ToDoCommentSpec(request);
            var countSpec  = new ToDoCommentWithFiltersForCountSpec(request);
            var totalItems = await _toDoCommentRepository.CountAsync(countSpec);

            var todo = await _toDoCommentRepository.ListWithSpecAsync(spec);

            var data = _mapper.Map <IReadOnlyList <Domain.Entities.ToDoComment>, IReadOnlyList <ToDoCommentResponse> >(todo);

            return(new Pagination <ToDoCommentResponse>(request.PageIndex, request.PageSize, totalItems, data));
        }
        public ToDoCommentSpec(GetToDoCommentListQuery query) : base(x =>
                                                                     (!query.ToDoId.HasValue || x.TodoId.Equals(query.ToDoId)) &&
                                                                     (!query.Comment.HasValue() || x.Comment.ToLower().Contains(query.Comment))
                                                                     )
        {
            AddOrderByDescending(x => x.CreatedDateTime);
            ApplyPaging(query.PageSize * (query.PageIndex - 1), query.PageSize);

            if (!string.IsNullOrEmpty(query.Sort))
            {
                switch (query.Sort)
                {
                case "createdDateAsc":
                    AddOrderBy(p => p.CreatedDateTime);
                    break;

                case "createdDateDesc":
                    AddOrderByDescending(p => p.CreatedDateTime);
                    break;
                }
            }
        }