Esempio n. 1
0
        public static PriceModel Parse(IDictionary<string, object> propertyDictionary)
        {
            var retVal = new PriceModel();

            var key = propertyDictionary.Keys.FirstOrDefault(x => x.Equals(PriceProperty, StringComparison.OrdinalIgnoreCase));
            if (!string.IsNullOrEmpty(key))
            {
                decimal price;
                decimal.TryParse(propertyDictionary.ParsePropertyToString(PriceProperty), out price);
                retVal.Price = price;
            }

            key = propertyDictionary.Keys.FirstOrDefault(x => x.Equals(IsFreeProperty, StringComparison.OrdinalIgnoreCase));
            if (!string.IsNullOrEmpty(key))
            {
                bool isFree;
                bool.TryParse((string)propertyDictionary[IsFreeProperty], out isFree);
                retVal.IsFree = isFree;
            }

            key = propertyDictionary.Keys.FirstOrDefault(x => x.Equals(CurrencyProperty, StringComparison.OrdinalIgnoreCase));
            if (!string.IsNullOrEmpty(key))
            {
                retVal.Currency = (string)propertyDictionary[CurrencyProperty];
            }

            if (!retVal.IsFree && !string.IsNullOrWhiteSpace(retVal.Currency))
            {
                retVal.FormatedPrice = CurrencyHelper.FormatCurrency(retVal.Price, retVal.Currency);
            }

            if (retVal.IsFree)
            {
                retVal.FormatedPrice = "Free";
            }

            return retVal;
        }