Ejemplo n.º 1
0
        public Task <GetOrdersTransactionResult> Handle(GetOrdersTransaction request, CancellationToken cancellationToken)
        {
            IEnumerable <PersistentObject> datas = set.OrderByDescending(data => data.CreatedTimeUtc);

            var pageCount = 1;
            var pageIndex = 1;

            if (request.PagingOptions != null &&
                request.PagingOptions.PageIndex > 0 &&
                request.PagingOptions.PageSize > 0)
            {
                pageIndex = request.PagingOptions.PageIndex;
                pageCount = Convert.ToInt32(Math.Ceiling(Convert.ToDouble(datas.Count()) / Convert.ToDouble(request.PagingOptions.PageSize)));
                datas     = datas.Skip((request.PagingOptions.PageIndex - 1) * request.PagingOptions.PageSize)
                            .Take(request.PagingOptions.PageSize);
            }
            var result = new GetOrdersTransactionResult
            {
                PagingInfo =
                    new PagingInfo {
                    CurrentPageIndex = pageIndex, PageCount = pageCount
                }
            };

            foreach (var data in datas)
            {
                var item = mapper.MapToGetOrdersTransactionResultItem(data);
                result.Add(item);
            }

            return(Task.FromResult(result));
        }
Ejemplo n.º 2
0
        public async Task <GetOrdersTransactionResult> Handle(GetOrdersTransaction request, CancellationToken cancellationToken)
        {
            var connection = factory.Create(ConnectionType.Reporting);

            const string SELECT_SQL     = "SELECT * FROM orders ORDER BY CreatedTimeUtc DESC ";
            const string PAGING_SQL     = " LIMIT @offset,@take ";
            const string COUNT_SQL      = "SELECT COUNT(1) / @pageSize AS PageCount FROM orders";
            string       selectSQL      = SELECT_SQL;
            var          offset         = 0;
            var          take           = 0;
            int          pageIndex      = 1;
            int          totalPageCount = 1;

            if (request.PagingOptions != null &&
                request.PagingOptions.PageIndex > 0 &&
                request.PagingOptions.PageSize > 0)
            {
                selectSQL += PAGING_SQL;
                offset     = (request.PagingOptions.PageIndex - 1) * request.PagingOptions.PageSize;
                take       = request.PagingOptions.PageSize;
                var count = await connection.QuerySingleAsync <double>(COUNT_SQL, new { pageSize = request.PagingOptions.PageSize });

                pageIndex      = request.PagingOptions.PageIndex;
                totalPageCount = Convert.ToInt32(Math.Ceiling(count));
            }
            var queryResults = await connection.QueryAsync <PersistentObject>(selectSQL, new
            {
                offset,
                take
            });

            var result = new GetOrdersTransactionResult();

            foreach (var data in queryResults)
            {
                var item = mapper.MapToGetOrdersTransactionResultItem(data);
                result.Add(item);
            }
            result.PagingInfo = new PagingInfo {
                CurrentPageIndex = pageIndex, PageCount = totalPageCount
            };
            return(result);
        }
        public async Task <GetOrdersQueryResult> Handle(GetOrdersQuery request, CancellationToken cancellationToken)
        {
            var transaction = new GetOrdersTransaction();

            if (request.PagingOptions != null &&
                request.PagingOptions.PageIndex > 0 &&
                request.PagingOptions.PageSize > 0)
            {
                transaction.PagingOptions = new DataAccess.ReportingTransaction.PagingOptions
                {
                    PageIndex = transaction.PagingOptions.PageIndex,
                    PageSize  = transaction.PagingOptions.PageSize
                };
            }

            var transactionResult = await bus.SendAsync(transaction);

            var result = mapper.MapToGetOrdersQueryResult(transactionResult);

            return(result);
        }