public ToDoWithFiltersForCountSpec(GetToDoListQuery query)
     : base(x =>
            (!query.Title.HasValue() || x.Title.ToLower().Contains(query.Title)) &&
            (!query.Description.HasValue() || x.Description.ToLower().Contains(query.Description))
            )
 {
 }
        public async Task <Pagination <ToDoResponse> > Handle(GetToDoListQuery request, CancellationToken cancellationToken)
        {
            var spec       = new ToDoSpec(request);
            var countSpec  = new ToDoWithFiltersForCountSpec(request);
            var totalItems = await _toDoRepository.CountAsync(countSpec);

            var todo = await _toDoRepository.ListWithSpecAsync(spec);

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

            return(new Pagination <ToDoResponse>(request.PageIndex, request.PageSize, totalItems, data));
        }
Пример #3
0
        public ToDoSpec(GetToDoListQuery query) : base(x =>
                                                       (!query.Title.HasValue() || x.Title.ToLower().Contains(query.Title)) &&
                                                       (!query.Description.HasValue() || x.Description.ToLower().Contains(query.Description))
                                                       )
        {
            AddInclude(x => x.Comments);
            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;
                }
            }
        }