/// <returns>A task that represents the asynchronous operation</returns>
        public virtual async Task <IActionResult> HistoryList(RecurringPaymentHistorySearchModel searchModel)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageRecurringPayments))
            {
                return(await AccessDeniedDataTablesJson());
            }

            //try to get a recurring payment with the specified id
            var payment = await _orderService.GetRecurringPaymentByIdAsync(searchModel.RecurringPaymentId)
                          ?? throw new ArgumentException("No recurring payment found with the specified id");

            //prepare model
            var model = await _recurringPaymentModelFactory.PrepareRecurringPaymentHistoryListModelAsync(searchModel, payment);

            return(Json(model));
        }
        public virtual IActionResult HistoryList(RecurringPaymentHistorySearchModel searchModel)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageRecurringPayments))
            {
                return(AccessDeniedKendoGridJson());
            }

            //try to get a recurring payment with the specified id
            var payment = _orderService.GetRecurringPaymentById(searchModel.RecurringPaymentId)
                          ?? throw new ArgumentException("No recurring payment found with the specified id");

            //prepare model
            var model = _recurringPaymentModelFactory.PrepareRecurringPaymentHistoryListModel(searchModel, payment);

            return(Json(model));
        }
        /// <summary>
        /// Prepare recurring payment history search model
        /// </summary>
        /// <param name="searchModel">Recurring payment history search model</param>
        /// <param name="recurringPayment">Recurring payment</param>
        /// <returns>Recurring payment history search model</returns>
        protected virtual RecurringPaymentHistorySearchModel PrepareRecurringPaymentHistorySearchModel(RecurringPaymentHistorySearchModel searchModel,
                                                                                                       RecurringPayment recurringPayment)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            if (recurringPayment == null)
            {
                throw new ArgumentNullException(nameof(recurringPayment));
            }

            searchModel.RecurringPaymentId = recurringPayment.Id;

            //prepare page parameters
            searchModel.SetGridPageSize();

            return(searchModel);
        }
        /// <summary>
        /// Prepare paged recurring payment history list model
        /// </summary>
        /// <param name="searchModel">Recurring payment history search model</param>
        /// <param name="recurringPayment">Recurring payment</param>
        /// <returns>Recurring payment history list model</returns>
        public virtual RecurringPaymentHistoryListModel PrepareRecurringPaymentHistoryListModel(RecurringPaymentHistorySearchModel searchModel,
                                                                                                RecurringPayment recurringPayment)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            if (recurringPayment == null)
            {
                throw new ArgumentNullException(nameof(recurringPayment));
            }

            //get recurring payments history
            var recurringPayments = recurringPayment.RecurringPaymentHistory
                                    .OrderBy(historyEntry => historyEntry.CreatedOnUtc).ToList()
                                    .ToPagedList(searchModel);

            //prepare list model
            var model = new RecurringPaymentHistoryListModel().PrepareToGrid(searchModel, recurringPayments, () =>
            {
                return(recurringPayments.Select(historyEntry =>
                {
                    //fill in model values from the entity
                    var historyModel = historyEntry.ToModel <RecurringPaymentHistoryModel>();

                    //convert dates to the user time
                    historyModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(historyEntry.CreatedOnUtc, DateTimeKind.Utc);

                    //fill in additional values (not existing in the entity)
                    var order = _orderService.GetOrderById(historyEntry.OrderId);
                    if (order == null)
                    {
                        return historyModel;
                    }

                    historyModel.OrderStatus = _localizationService.GetLocalizedEnum(order.OrderStatus);
                    historyModel.PaymentStatus = _localizationService.GetLocalizedEnum(order.PaymentStatus);
                    historyModel.ShippingStatus = _localizationService.GetLocalizedEnum(order.ShippingStatus);
                    historyModel.CustomOrderNumber = order.CustomOrderNumber;

                    return historyModel;
                }));
            });

            return(model);
        }
Example #5
0
        /// <summary>
        /// Prepare paged recurring payment history list model
        /// </summary>
        /// <param name="searchModel">Recurring payment history search model</param>
        /// <param name="recurringPayment">Recurring payment</param>
        /// <returns>Recurring payment history list model</returns>
        public virtual RecurringPaymentHistoryListModel PrepareRecurringPaymentHistoryListModel(RecurringPaymentHistorySearchModel searchModel,
                                                                                                RecurringPayment recurringPayment)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            if (recurringPayment == null)
            {
                throw new ArgumentNullException(nameof(recurringPayment));
            }

            //get recurring payments history
            var recurringPayments = recurringPayment.RecurringPaymentHistory.OrderBy(historyEntry => historyEntry.CreatedOnUtc).ToList();

            //prepare list model
            var model = new RecurringPaymentHistoryListModel
            {
                Data = recurringPayments.PaginationByRequestModel(searchModel).Select(historyEntry =>
                {
                    //fill in model values from the entity
                    var historyModel = new RecurringPaymentHistoryModel
                    {
                        Id                 = historyEntry.Id,
                        OrderId            = historyEntry.OrderId,
                        RecurringPaymentId = historyEntry.RecurringPaymentId
                    };

                    //convert dates to the user time
                    historyModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(historyEntry.CreatedOnUtc, DateTimeKind.Utc);

                    //fill in additional values (not existing in the entity)
                    var order = _orderService.GetOrderById(historyEntry.OrderId);
                    if (order == null)
                    {
                        return(historyModel);
                    }

                    historyModel.OrderStatus       = order.OrderStatus.GetLocalizedEnum(_localizationService, _workContext);
                    historyModel.PaymentStatus     = order.PaymentStatus.GetLocalizedEnum(_localizationService, _workContext);
                    historyModel.ShippingStatus    = order.ShippingStatus.GetLocalizedEnum(_localizationService, _workContext);
                    historyModel.CustomOrderNumber = order.CustomOrderNumber;

                    return(historyModel);
                }),
                Total = recurringPayments.Count
            };

            return(model);
        }