public async Task <IEnumerable <UserRespond> > Handle(GetPaginatedUserQuery request, CancellationToken cancellationToken)
        {
            if (request.CurrentPage < 1 || request.PageSize < 1 || typeof(UserRespond).GetProperty(request.SortBy) == null)
            {
                throw new InvalidArgumentException();
            }

            var users = await _userService
                        .GetPaginatedResultAsyncAsNoTracking(request.CurrentPage, request.PageSize, request.SortBy, request.IsAsc);

            return(_mapper.Map <List <UserRespond> >(users));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetPaginatedResult(int?currentPage, int?pageSize, string sortBy, bool?isAsc)
        {
            try
            {
                var query  = new GetPaginatedUserQuery(currentPage, pageSize, sortBy, isAsc);
                var result = await _mediator.Send(query);

                return(Ok(result));
            }
            catch (InvalidArgumentException)
            {
                return(BadRequest(ModelConstants.InvalidQuery));
            }
        }