public ActionResult RateUpdate(ShippingByTotalModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings))
            {
                return Content(_localizationService.GetResource("Plugins.Shipping.ByTotal.ManageShippingSettings.AccessDenied"));
            }

            var shippingByTotalRecord = _shippingByTotalService.GetShippingByTotalRecordById(model.Id);
            shippingByTotalRecord.ZipPostalCode = model.ZipPostalCode == "*" ? null : model.ZipPostalCode;
            shippingByTotalRecord.DisplayOrder = model.DisplayOrder;
            shippingByTotalRecord.From = model.From;
            shippingByTotalRecord.To = model.To;
            shippingByTotalRecord.UsePercentage = model.UsePercentage;
            shippingByTotalRecord.ShippingChargePercentage = model.UsePercentage ? model.ShippingChargePercentage : 0;
            shippingByTotalRecord.ShippingChargeAmount = !model.UsePercentage ? model.ShippingChargeAmount : 0;
            shippingByTotalRecord.ShippingMethodId = model.ShippingMethodId;
            shippingByTotalRecord.StoreId = model.StoreId;
            shippingByTotalRecord.WarehouseId = model.WarehouseId;
            shippingByTotalRecord.StateProvinceId = model.StateProvinceId;
            shippingByTotalRecord.CountryId = model.CountryId;
            _shippingByTotalService.UpdateShippingByTotalRecord(shippingByTotalRecord);

            return new NullJsonResult();
        }
        public ActionResult RatesList(DataSourceRequest command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageShippingSettings))
            {
                return Content(_localizationService.GetResource("Plugins.Shipping.ByTotal.ManageShippingSettings.AccessDenied"));
            }

            var records = _shippingByTotalService.GetAllShippingByTotalRecords(command.Page - 1, command.PageSize);
            var sbtModel = records.Select(x =>
                {
                    var m = new ShippingByTotalModel
                    {
                        Id = x.Id,
                        StoreId = x.StoreId,
                        WarehouseId = x.WarehouseId,
                        ShippingMethodId = x.ShippingMethodId,
                        CountryId = x.CountryId,
                        DisplayOrder = x.DisplayOrder,
                        From = x.From,
                        To = x.To,
                        UsePercentage = x.UsePercentage,
                        ShippingChargePercentage = x.ShippingChargePercentage,
                        ShippingChargeAmount = x.ShippingChargeAmount,
                    };

                    // shipping method
                    var shippingMethod = _shippingService.GetShippingMethodById(x.ShippingMethodId);
                    m.ShippingMethodName = (shippingMethod != null) ? shippingMethod.Name : "Unavailable";

                    // store
                    var store = _storeService.GetStoreById(x.StoreId);
                    m.StoreName = (store != null) ? store.Name : "*";

                    // warehouse
                    var warehouse = _shippingService.GetWarehouseById(x.WarehouseId);
                    m.WarehouseName = (warehouse != null) ? warehouse.Name : "*";

                    // country
                    var c = _countryService.GetCountryById(x.CountryId);
                    m.CountryName = (c != null) ? c.Name : "*";
                    m.CountryId = x.CountryId;

                    // state/province
                    var s = _stateProvinceService.GetStateProvinceById(x.StateProvinceId);
                    m.StateProvinceName = (s != null) ? s.Name : "*";
                    m.StateProvinceId = x.StateProvinceId;

                    // ZIP / postal code
                    m.ZipPostalCode = (!String.IsNullOrEmpty(x.ZipPostalCode)) ? x.ZipPostalCode : "*";

                    return m;
                })
                .ToList();
            var gridModel = new DataSourceResult
            {
                Data = sbtModel,
                Total = records.TotalCount
            };

            return Json(gridModel);
        }