コード例 #1
0
        public async Task <IActionResult> Get(int page = 0, int pageSize = 10)
        {
            var query   = new StudentsArchive(page, pageSize);
            var results = await _mediator.Send(query);

            return(Ok(results));
        }
コード例 #2
0
        public async Task <PagedCollection <StudentArchiveItem> > Handle(StudentsArchive request, CancellationToken cancellationToken)
        {
            if (null == request)
            {
                throw new ArgumentNullException(nameof(request));
            }

            await using var conn = new SqlConnection(_connectionStringProvider.ConnectionString);
            var results = await conn.QueryMultipleAsync(query, new { offset = request.Page *request.PageSize, pageSize = request.PageSize });

            var items      = (await results.ReadAsync()).Select(r => new StudentArchiveItem(r.Id, r.FirstName, r.LastName));
            var totalCount = await results.ReadSingleAsync <int>();

            return(new PagedCollection <StudentArchiveItem>(items, request.Page, request.PageSize, totalCount));
        }