Exemplo n.º 1
0
        public async Task <IActionResult> Get([FromQuery] PagedResults paging)
        {
            _logger.LogInformation("UserBooksController:: GETPAGED called");

            try
            {
                var books = await _unitOfWork.Books.GetBooksPagedAsync(paging);

                var totalRecords = await _unitOfWork.Books.GetAllAsync();

                if (books.Count() <= 0)
                {
                    return(NotFound(new { message = "Database empty, please add some books to the library" }));
                }

                var response = PagedResultsHelper <BookDto> .PagingResponse(_mapper.Map <BookDto[]>(books), paging.PageIndex, paging.PageSize, totalRecords.Count());

                return(Ok(response));
            }
            catch (Exception ex)
            {
                _logger.LogError("BooksController:: GETPAGED error", ex.StackTrace);
                return(StatusCode(StatusCodes.Status500InternalServerError, "Server error"));
            }
        }
        public async Task <IActionResult> Get([FromQuery] PagedResults paging, bool includebooks = false)
        {
            _logger.LogInformation("UsersController:: GET called");

            try
            {
                var users = await _unitOfWork.Users.GetUsersPagedAsync(paging, includebooks);

                var totalRecords = await _unitOfWork.Users.GetAllAsync();

                if (users.Count() <= 0)
                {
                    return(NotFound(new { message = "Database empty, please register some users" }));
                }

                var response = PagedResultsHelper <UserDto> .PagingResponse(_mapper.Map <UserDto[]>(users), paging.PageIndex, paging.PageSize, totalRecords.Count());

                return(Ok(response));
            }
            catch (Exception ex)
            {
                _logger.LogError("UsersController:: GET error", ex.StackTrace);
                return(StatusCode(StatusCodes.Status500InternalServerError, "Server error"));
            }
        }