public virtual CatalogProperty ToProperty(catalogDto.Property propertyDto, Language currentLanguage)
        {
            var retVal = new CatalogProperty();

            retVal.Id        = propertyDto.Id;
            retVal.Name      = propertyDto.Name;
            retVal.Type      = propertyDto.Type;
            retVal.ValueType = propertyDto.ValueType;

            //Set display names and set current display name for requested language
            if (propertyDto.DisplayNames != null)
            {
                retVal.DisplayNames = propertyDto.DisplayNames.Select(x => new LocalizedString(new Language(x.LanguageCode), x.Name)).ToList();
                retVal.DisplayName  = retVal.DisplayNames.FindWithLanguage(currentLanguage, x => x.Value, null);
            }

            //if display name for requested language not set get system property name
            if (string.IsNullOrEmpty(retVal.DisplayName))
            {
                retVal.DisplayName = propertyDto.Name;
            }

            //For multilingual properties need populate LocalizedValues collection and set value for requested language
            if (propertyDto.Multilanguage ?? false)
            {
                if (propertyDto.Values != null)
                {
                    retVal.LocalizedValues = propertyDto.Values.Where(x => x.Value != null).Select(x => new LocalizedString(new Language(x.LanguageCode), x.Value.ToString())).ToList();
                }
            }

            //Set property value
            if (propertyDto.Values != null)
            {
                var propValue = propertyDto.Values.FirstOrDefault(x => x.Value != null);
                if (propValue != null)
                {
                    //Use only one prop value (reserve multi-values to other scenarios)
                    retVal.Value   = propValue.Value;
                    retVal.ValueId = propValue.ValueId;
                }
            }

            //Try to set value for requested language
            if (retVal.LocalizedValues.Any())
            {
                retVal.Value = retVal.LocalizedValues.FindWithLanguage(currentLanguage, x => x.Value, retVal.Value);
            }

            return(retVal);
        }
Esempio n. 2
0
 public static CatalogProperty ToProperty(this catalogDto.Property propertyDto, Language currentLanguage)
 {
     return(CatalogConverterInstance.ToProperty(propertyDto, currentLanguage));
 }
Esempio n. 3
0
        public static CatalogProperty ToProperty(this catalogDto.Property propertyDto, Language currentLanguage)
        {
            var result = new CatalogProperty
            {
                Id           = propertyDto.Id,
                Name         = propertyDto.Name,
                Type         = propertyDto.Type,
                ValueType    = propertyDto.ValueType,
                IsMultivalue = propertyDto.Multivalue ?? false
            };

            //Set display names and set current display name for requested language
            if (propertyDto.DisplayNames != null)
            {
                result.DisplayNames = propertyDto.DisplayNames.Select(x => new LocalizedString(new Language(x.LanguageCode), x.Name)).ToList();
                result.DisplayName  = result.DisplayNames.FindWithLanguage(currentLanguage, x => x.Value, null);
            }

            //if display name for requested language not set get system property name
            if (string.IsNullOrEmpty(result.DisplayName))
            {
                result.DisplayName = propertyDto.Name;
            }

            //For multilingual properties need populate LocalizedValues collection and set value for requested language
            if (propertyDto.Multilanguage ?? false)
            {
                if (propertyDto.Values != null)
                {
                    result.LocalizedValues = propertyDto.Values.Where(x => x.Value != null).Select(x => new LocalizedString(new Language(x.LanguageCode), x.Value.ToString())).ToList();
                }
            }

            //Set property value
            var propValue = propertyDto.Values?.FirstOrDefault(v => v.Value != null);

            if (propValue != null)
            {
                //Use only one prop value (reserve multi-values to other scenarios)
                result.Value   = propValue.Value?.ToString();
                result.ValueId = propValue.ValueId;
            }

            //Try to set value for requested language
            if (result.LocalizedValues.Any())
            {
                result.Value = result.LocalizedValues.FindWithLanguage(currentLanguage, x => x.Value, result.Value);
            }

            //Set multivalues
            if (result.IsMultivalue && propertyDto.Values != null)
            {
                if (result.LocalizedValues.Any())
                {
                    result.Values = result.LocalizedValues.GetLocalizedStringsForLanguage(currentLanguage).Select(x => x.Value).ToList();
                }
                else
                {
                    result.Values = propertyDto.Values.Where(x => x != null).Select(x => x.Value.ToString()).ToList();
                }
            }

            return(result);
        }