Esempio n. 1
0
        public async Task <IActionResult> List(DataSourceRequest command, PaymentTransactionListModel model)
        {
            if (await _groupService.IsStaff(_workContext.CurrentCustomer))
            {
                model.StoreId = _workContext.CurrentCustomer.StaffStoreId;
            }
            DateTime?startDateValue = (model.StartDate == null) ? null
                : (DateTime?)_dateTimeService.ConvertToUtcTime(model.StartDate.Value, _dateTimeService.CurrentTimeZone);

            DateTime?endDateValue = (model.EndDate == null) ? null
                : (DateTime?)_dateTimeService.ConvertToUtcTime(model.EndDate.Value, _dateTimeService.CurrentTimeZone);

            var paymentTransactions = await _paymentTransactionService.SearchPaymentTransactions(
                customerEmail : model.SearchCustomerEmail,
                ts : model.SearchTransactionStatus >= 0?(TransactionStatus)model.SearchTransactionStatus : null,
                createdFromUtc : startDateValue,
                createdToUtc : endDateValue,
                storeId : model.StoreId,
                pageIndex : command.Page - 1,
                pageSize : command.PageSize);

            var dataModel = new List <PaymentTransactionModel>();

            foreach (var item in paymentTransactions)
            {
                var order = await _orderService.GetOrderByGuid(item.OrderGuid);

                var trmodel = new PaymentTransactionModel();
                trmodel.Id                      = item.Id;
                trmodel.OrderCode               = item.OrderCode;
                trmodel.CustomerEmail           = item.CustomerEmail;
                trmodel.CustomerId              = item.CustomerId;
                trmodel.CurrencyCode            = item.CurrencyCode;
                trmodel.TransactionAmount       = item.TransactionAmount;
                trmodel.PaidAmount              = item.PaidAmount;
                trmodel.PaymentMethodSystemName = item.PaymentMethodSystemName;
                trmodel.RefundedAmount          = item.RefundedAmount;
                trmodel.OrderId                 = order?.Id;
                trmodel.OrderNumber             = order?.OrderNumber;
                trmodel.CreatedOn               = _dateTimeService.ConvertToUserTime(item.CreatedOnUtc, DateTimeKind.Utc);
                trmodel.TransactionStatus       = item.TransactionStatus;
                trmodel.Status                  = item.TransactionStatus.GetTranslationEnum(_translationService, _workContext);
                dataModel.Add(trmodel);
            }

            var gridModel = new DataSourceResult
            {
                Data  = dataModel.ToList(),
                Total = paymentTransactions.TotalCount,
            };

            return(Json(gridModel));
        }