Exemplo 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));
        }
Exemplo n.º 2
0
        public GetOrdersQueryResult MapToGetOrdersQueryResult(GetOrdersTransactionResult items)
        {
            var result = new GetOrdersQueryResult();

            foreach (var item in items)
            {
                var data = MaotpGetOrdersQueryResultItem(item);
                result.Add(data);
            }
            result.PagingInfo = MapToPagingInfo(items.PagingInfo);
            return(result);
        }
Exemplo n.º 3
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);
        }