internal static void DeleteRow(IGatewayProviderService gatewayProviderService, IRuntimeCacheProvider cache, IShippingFixedRateTable rateTable, IShipRateTier shipRateTier) { //var row = Rows.FirstOrDefault(x => x.Key == shipRateTier.Key); //if (!Rows.Any() || row == null) return; //if (Rows.IndexOf(Rows.Last()) != Rows.IndexOf(row)) //{ // _shipRateTiers[Rows.IndexOf(row) + 1].RangeLow = row.RangeLow; //} //_shipRateTiers.Remove(row); var row = rateTable.Rows.FirstOrDefault(x => x.Key == shipRateTier.Key); if (!rateTable.Rows.Any() || row == null) { return; } if (rateTable.Rows.IndexOf(rateTable.Rows.Last()) != rateTable.Rows.IndexOf(row)) { rateTable.Rows.First(x => x.RangeLow == row.RangeHigh).RangeLow = row.RangeLow; } // clear the current cached item // TODO : This should use the distributed cache referesher cache.ClearCacheItem(CacheKeys.GatewayShipMethodCacheKey(rateTable.ShipMethodKey)); gatewayProviderService.Save(rateTable.Rows); gatewayProviderService.Delete(shipRateTier); cache.GetCacheItem(CacheKeys.GatewayShipMethodCacheKey(rateTable.ShipMethodKey), () => rateTable); }
internal static ShippingFixedRateTable GetShipRateTable(IGatewayProviderService gatewayProviderService, IRuntimeCacheProvider runtimeCacheProvider, Guid shipMethodKey) { return((ShippingFixedRateTable)runtimeCacheProvider.GetCacheItem( CacheKeys.GatewayShipMethodCacheKey(shipMethodKey), delegate { var rows = gatewayProviderService.GetShipRateTiersByShipMethodKey(shipMethodKey); return new ShippingFixedRateTable(shipMethodKey, rows); })); }
internal static void Save(IGatewayProviderService gatewayProviderService, IRuntimeCacheProvider cache, IShippingFixedRateTable rateTable) { // clear the current cached item // TODO : This should use the distributed cache referesher cache.ClearCacheItem(CacheKeys.GatewayShipMethodCacheKey(rateTable.ShipMethodKey)); // persist and enter into cache gatewayProviderService.Save(rateTable.Rows); cache.GetCacheItem(CacheKeys.GatewayShipMethodCacheKey(rateTable.ShipMethodKey), () => rateTable); }