public override bool TryGetValue(IEnumerable <IMvxSourceStep> steps, out object value) { var priceString = string.Empty; var values = steps.ToList(); var priceValue = values.FirstOrDefault(x => x.SourceType == typeof(Decimal) || x.SourceType == typeof(Decimal?)); if (priceValue != null) { object priceFormatted = null; var priceFormatConverter = new PriceFormatConverter(); if (priceValue.SourceType == typeof(Decimal)) { var price = Convert.ToDecimal(priceValue.GetValue()); priceFormatted = priceFormatConverter.Convert(price, typeof(Decimal), null, null); } else if (priceValue.SourceType == typeof(Decimal?)) { var price = (decimal?)priceValue.GetValue(); if (price.HasValue) { priceFormatted = priceFormatConverter.Convert(price, typeof(Decimal), null, null); } } priceString += priceFormatted ?? string.Empty; } if (_config.PriceType == PriceType.Default || _config.PriceType == PriceType.To) { value = priceString; return(true); } var maxPriceValue = values.LastOrDefault(x => x.SourceType == typeof(Decimal) || x.SourceType == typeof(Decimal?)); if (maxPriceValue != null && maxPriceValue != priceValue) { bool format = false; if (maxPriceValue.SourceType == typeof(Decimal)) { format = true; } else if (maxPriceValue.SourceType == typeof(Decimal?)) { var price = (decimal?)maxPriceValue.GetValue(); format = price.HasValue; } if (format) { priceString = $"{_localizationService.GetLocalizableString(ProductsConstants.RESX_NAME, "Catalog_PriceFrom")} {priceString}"; } } value = priceString; return(true); }
protected virtual void BindMaxPrice(UILabel maxPrice, MvxFluentBindingDescriptionSet <CatalogGridCell, ICatalogItemVM> set) { if (maxPrice == null) { return; } if (!(Config.PriceType == PriceType.To || Config.PriceType == PriceType.FromTo)) { maxPrice.Hidden = true; return; } MvxFluentBindingDescription <UILabel, ICatalogItemVM> priceBinding; if (Config.UnitNameEnabled) { priceBinding = set.Bind(maxPrice).ByCombining(new PriceUnitCombiner(), new [] { "MaxPrice", "UnitName" }); } else { priceBinding = set.Bind(maxPrice).To(vm => vm.MaxPrice); } priceBinding.WithConversion( "StringFormat", new StringFormatParameter() { StringFormat = (arg) => { if (!Config.UnitNameEnabled) { arg = new PriceFormatConverter().Convert(arg, typeof(Decimal?), null, null); } return($"{LocalizationService.GetLocalizableString(ProductsConstants.RESX_NAME, "Catalog_PriceTo")} {arg}"); } } ); set.Bind(maxPrice).For("Visibility").To(vm => vm.MaxPrice).WithConversion("Visibility"); }