public ActionResult AffiliatedOrderList(int affiliateId, GridCommand command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageAffiliates))
                return AccessDeniedView();

            var affiliate = _affiliateService.GetAffiliateById(affiliateId);
            if (affiliate == null)
                throw new ArgumentException("No affiliate found with the specified id");

            var orders = _orderService.GetAllOrders(affiliate.Id, command.Page - 1, command.PageSize);
            var model = new GridModel<AffiliateModel.AffiliatedOrderModel>
            {
                Data = orders.Select(order =>
                {
                    var orderModel = new AffiliateModel.AffiliatedOrderModel();
                    orderModel.Id = order.Id;
                    orderModel.OrderStatus = order.OrderStatus.GetLocalizedEnum(_localizationService, _workContext);
                    orderModel.PaymentStatus = order.PaymentStatus.GetLocalizedEnum(_localizationService, _workContext);
                    orderModel.ShippingStatus = order.ShippingStatus.GetLocalizedEnum(_localizationService, _workContext);
                    orderModel.OrderTotal = _priceFormatter.FormatPrice(order.OrderTotal, true, false);
                    orderModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc);
                    return orderModel;
                }),
                Total = orders.TotalCount
            };

            return new JsonResult
            {
                Data = model
            };
        }
        public ActionResult AffiliatedOrderList(int affiliateId, GridCommand command)
        {
            var model = new GridModel<AffiliateModel.AffiliatedOrderModel>();

            if (_permissionService.Authorize(StandardPermissionProvider.ManageAffiliates))
            {
                var affiliate = _affiliateService.GetAffiliateById(affiliateId);
                var orders = _orderService.GetAllOrders(affiliate.Id, command.Page - 1, command.PageSize);

                model.Data = orders.Select(order =>
                {
                    var orderModel = new AffiliateModel.AffiliatedOrderModel();
                    orderModel.Id = order.Id;
                    orderModel.OrderStatus = order.OrderStatus.GetLocalizedEnum(_localizationService, _workContext);
                    orderModel.PaymentStatus = order.PaymentStatus.GetLocalizedEnum(_localizationService, _workContext);
                    orderModel.ShippingStatus = order.ShippingStatus.GetLocalizedEnum(_localizationService, _workContext);
                    orderModel.OrderTotal = _priceFormatter.FormatPrice(order.OrderTotal, true, false);
                    orderModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(order.CreatedOnUtc, DateTimeKind.Utc);
                    return orderModel;
                });
                model.Total = orders.TotalCount;
            }
            else
            {
                model.Data = Enumerable.Empty<AffiliateModel.AffiliatedOrderModel>();

                NotifyAccessDenied();
            }

            return new JsonResult
            {
                Data = model
            };
        }