Exemplo n.º 1
0
        /// <summary>
        /// Search payment transactions
        /// </summary>
        /// <param name="orderguid">Order ident by guid</param>
        /// <param name="storeId">Store ident</param>
        /// <param name="customerEmail">Customer email</param>
        /// <param name="ts">Transaction status</param>
        /// <param name="pageIndex">Page index</param>
        /// <param name="pageSize">Page size</param>
        /// <param name="createdFromUtc">Created date from (UTC); null to load all records</param>
        /// <param name="createdToUtc">Created date to (UTC); null to load all records</param>
        /// <returns>Page list payment transaction</returns>
        public virtual async Task <IPagedList <PaymentTransaction> > SearchPaymentTransactions(
            Guid?orderguid          = null,
            string storeId          = "",
            string customerEmail    = "",
            TransactionStatus?ts    = null,
            int pageIndex           = 0, int pageSize = int.MaxValue,
            DateTime?createdFromUtc = null,
            DateTime?createdToUtc   = null)
        {
            var model = new GetPaymentTransactionQuery()
            {
                CreatedFromUtc = createdFromUtc,
                CreatedToUtc   = createdToUtc,
                PageIndex      = pageIndex,
                PageSize       = pageSize,
                OrderGuid      = orderguid,
                CustomerEmail  = customerEmail,
                StoreId        = storeId,
                Ts             = ts,
            };

            var query = await _mediator.Send(model);

            return(await PagedList <PaymentTransaction> .Create(query, pageIndex, pageSize));
        }
        public Task <IQueryable <PaymentTransaction> > Handle(GetPaymentTransactionQuery request, CancellationToken cancellationToken)
        {
            var query = from p in _paymentTransactionRepository.Table
                        select p;

            if (!string.IsNullOrEmpty(request.StoreId))
            {
                query = query.Where(rr => request.StoreId == rr.StoreId);
            }

            if (!string.IsNullOrEmpty(request.CustomerEmail))
            {
                query = query.Where(rr => request.CustomerEmail == rr.CustomerEmail.ToLowerInvariant());
            }

            if (request.OrderGuid.HasValue)
            {
                query = query.Where(rr => request.OrderGuid == request.OrderGuid.Value);
            }

            if (request.Ts.HasValue)
            {
                query = query.Where(rr => rr.TransactionStatus == request.Ts.Value);
            }

            if (request.CreatedFromUtc.HasValue)
            {
                query = query.Where(rr => request.CreatedFromUtc.Value <= rr.CreatedOnUtc);
            }

            if (request.CreatedToUtc.HasValue)
            {
                query = query.Where(rr => request.CreatedToUtc.Value >= rr.CreatedOnUtc);
            }

            query = query.OrderByDescending(rr => rr.CreatedOnUtc);

            return(Task.FromResult(query));
        }