Example #1
0
        public virtual IList <LocalizablePropertyValues> Map(ILanguageEntity languageEntity, IList <LocalizablePropertyValues> entityLocalizableProperties)
        {
            Type t = typeof(TCommerceEntity);

            var commerceEntity = Activator.CreateInstance(t) as TCommerceEntity;

            ILanguageEntity <TSourceEntity> l = languageEntity as ILanguageEntity <TSourceEntity>;

            if (l == null)
            {
                Context.Abort(Context.CommerceContext.AddMessage(Context.GetPolicy <KnownResultCodes>().Error, "LanguageEntityMissing", null, "Language entity cannot be null").Result, Context);
            }
            else
            {
                MapLocalizeValues(l.Entity, commerceEntity);

                if (entityLocalizableProperties == null)
                {
                    entityLocalizableProperties = LocalizablePropertyListManager.GetEntityProperties(t, Context);
                    entityLocalizableProperties = entityLocalizableProperties?.Clone();
                }

                if (entityLocalizableProperties == null || !entityLocalizableProperties.Any())
                {
                    return(new List <LocalizablePropertyValues>());
                }

                var properties = TypePropertyListManager.GetProperties(t);
                foreach (var localizablePropertyValues in entityLocalizableProperties)
                {
                    if (!string.IsNullOrEmpty(localizablePropertyValues.PropertyName))
                    {
                        var propertyInfo = properties.FirstOrDefault(x =>
                                                                     x.Name.Equals(localizablePropertyValues.PropertyName, StringComparison.OrdinalIgnoreCase));
                        if (propertyInfo != null)
                        {
                            var propertyValue = propertyInfo.GetValue(commerceEntity);
                            var parameter     = localizablePropertyValues.Parameters.FirstOrDefault(x =>
                                                                                                    x.Key.Equals(languageEntity.Language, StringComparison.OrdinalIgnoreCase));

                            if (parameter == null)
                            {
                                parameter = new Parameter {
                                    Key = languageEntity.Language, Value = null
                                };
                                localizablePropertyValues.Parameters.Add(parameter);
                            }

                            parameter.Value = propertyValue;
                        }
                    }
                }
            }

            return(entityLocalizableProperties);
        }
        public virtual LocalizableComponentPropertiesValues Map(ILanguageEntity languageEntity, LocalizableComponentPropertiesValues localizableComponentPropertiesValues)
        {
            Type t = typeof(T);

            var component = Activator.CreateInstance(t) as T;

            MapLocalizeValues(component);

            if (localizableComponentPropertiesValues == null)
            {
                var entityComponentsLocalizableProperties =
                    LocalizablePropertyListManager.GetEntityComponentProperties(ComponentHandler.GetEntityType(),
                                                                                Context);

                if (entityComponentsLocalizableProperties == null || !entityComponentsLocalizableProperties.Any())
                {
                    return(null);
                }

                var path = GetLocalizableComponentPath(component);

                var componentProperties =
                    entityComponentsLocalizableProperties.FirstOrDefault(x =>
                                                                         x.Path.Equals(path, StringComparison.OrdinalIgnoreCase));

                if (componentProperties == null || !componentProperties.PropertyValues.Any())
                {
                    return(null);
                }

                localizableComponentPropertiesValues = componentProperties.Clone();
            }


            var properties = TypePropertyListManager.GetProperties(t);

            foreach (var localizablePropertyValues in localizableComponentPropertiesValues.PropertyValues)
            {
                if (!string.IsNullOrEmpty(localizablePropertyValues.PropertyName))
                {
                    var propertyInfo = properties.FirstOrDefault(x =>
                                                                 x.Name.Equals(localizablePropertyValues.PropertyName, StringComparison.OrdinalIgnoreCase));
                    if (propertyInfo != null)
                    {
                        var propertyValue = propertyInfo.GetValue(component);
                        var parameter     = localizablePropertyValues.Parameters.FirstOrDefault(x =>
                                                                                                x.Key.Equals(languageEntity.Language, StringComparison.OrdinalIgnoreCase));

                        if (parameter == null)
                        {
                            parameter = new Parameter {
                                Key = languageEntity.Language, Value = null
                            };
                            localizablePropertyValues.Parameters.Add(parameter);
                        }

                        parameter.Value = propertyValue;
                    }
                }
            }

            return(localizableComponentPropertiesValues);
        }