public bool ApplyFilter(IFilterRow row) { bool result = false; if (row != null) { String sku = row.GetColumn(Sku).Value; String weightAsString = row.GetColumn(Weight).Value; String volumeAsString = row.GetColumn(Volume).Value; if (String.IsNullOrWhiteSpace(weightAsString) == false && String.IsNullOrWhiteSpace(volumeAsString) == false) { if (decimal.TryParse(weightAsString, out decimal weightAsLBS) && decimal.TryParse(volumeAsString, out decimal volumeAsCubicFeet)) { decimal gramConversionFactor = (decimal)453.59237; decimal weight = gramConversionFactor * weightAsLBS; WeightCubicVolumeInformation wi = new WeightCubicVolumeInformation(weight, weightAsLBS, volumeAsCubicFeet); MatchingRowIds.Add(sku, wi); result = true; } } } return(result); }
public void Update(CsvRow row) { String?sku = row?.GetColumn(Sku).Value; if (MatchingRowIds.ContainsKey(sku)) { WeightCubicVolumeInformation wi = MatchingRowIds[sku]; if (wi != null) { row?.SetColumn("Variant Grams", wi.Grams.ToString(CultureInfo.InvariantCulture)); row?.SetColumn(Weight, wi.Weight.ToString()); } } }
public bool ApplyFilter(IFilterRow row) { bool result = false; if (row != null) { String volumeAsString = row.GetColumn("cubic_volume (in.)").Value; String weightAsString = row.GetColumn(Weight).Value; String priceAsString = row.GetColumn(Price).Value; String msrpAsString = row.GetColumn(Msrp).Value; String mapAsString = row.GetColumn(Map).Value; String sku = row.GetColumn(Sku).Value; WeightCubicVolumeInformation wi = null; decimal.TryParse(msrpAsString, out decimal msrp); decimal.TryParse(weightAsString, out decimal weight); decimal.TryParse(volumeAsString, out decimal volume); decimal.TryParse(mapAsString, out decimal map); if (String.IsNullOrWhiteSpace(weightAsString) == false && String.IsNullOrWhiteSpace(volumeAsString) == false) { if (decimal.TryParse(weightAsString, out decimal weightAsLBS) && decimal.TryParse(volumeAsString, out decimal volumeAsCubicFeet)) { decimal gramConversionFactor = (decimal)453.59237; weight = gramConversionFactor * weightAsLBS; wi = new WeightCubicVolumeInformation(weight, weightAsLBS, volumeAsCubicFeet); } } decimal.TryParse(priceAsString, out decimal price); decimal costPerItem = price; price = (price * (decimal)ProfitMargin); if (price > (decimal)3.0) { price = (Math.Floor(price) + (decimal)0.47); } if (price < costPerItem) { price = (costPerItem * (decimal)ProfitMargin); } if (String.IsNullOrWhiteSpace(mapAsString) == false) { if (price < map) { price = Math.Floor(map) + (decimal)0.49; } } if (msrp > 0) { if (price > msrp) { price = msrp; } } else { msrp = price + (price * (decimal)0.20); } IFilterValue storage = row.GetColumn("storage"); if (storage != null && string.IsNullOrWhiteSpace(storage.Value) == false && (storage.Value == Refrigerated || storage.Value == Frozen)) { price += (decimal)ShippingSurcharge; } decimal volumeShippingCost = 0; decimal weightShippingCost = 0; if (wi != null && ShouldAddShipping) { (volumeShippingCost, weightShippingCost) = ShippingCost.Get(wi); if (volumeShippingCost < weightShippingCost) { price += weightShippingCost; } else { price += volumeShippingCost; } } PriceInformation pi = new PriceInformation(msrp.ToString("C2"), msrp.ToString("C2"), costPerItem.ToString("C2"), price.ToString("C2")); MatchingRowIds.Add(row.GetColumn(Sku).Value, pi); result = true; } return(result); }