Exemplo n.º 1
0
        public static void CreateMultiLingualMap <TMultiLingualEntity, TMultiLingualEntityPrimaryKey, TTranslation, TDestination>(
            this IMapperConfigurationExpression configuration, MultiLingualMapContext multiLingualMapContext)
            where TTranslation : class, IEntityTranslation <TMultiLingualEntity, TMultiLingualEntityPrimaryKey>
            where TMultiLingualEntity : IMultiLingualEntity <TTranslation>
        {
            configuration.CreateMap <TTranslation, TDestination>();

            configuration.CreateMap <TMultiLingualEntity, TDestination>().BeforeMap((source, destination, context) =>
            {
                var translation = source.Translations.FirstOrDefault(pt => pt.Language == CultureInfo.CurrentUICulture.Name);
                if (translation != null)
                {
                    context.Mapper.Map(translation, destination);
                    return;
                }

                var defaultLanguage = multiLingualMapContext.SettingManager
                                      .GetSettingValue(LocalizationSettingNames.DefaultLanguage);

                translation = source.Translations.FirstOrDefault(pt => pt.Language == defaultLanguage);
                if (translation != null)
                {
                    context.Mapper.Map(translation, destination);
                    return;
                }

                translation = source.Translations.FirstOrDefault();
                if (translation != null)
                {
                    context.Mapper.Map(translation, destination);
                }
            });
        }
Exemplo n.º 2
0
 public static void CreateMultiLingualMap <TMultiLingualEntity, TTranslation, TDestination>(this IMapperConfigurationExpression configuration, MultiLingualMapContext multiLingualMapContext)
     where TTranslation : class, IEntity, IEntityTranslation <TMultiLingualEntity, int>
     where TMultiLingualEntity : IMultiLingualEntity <TTranslation>
 {
     configuration.CreateMultiLingualMap <TMultiLingualEntity, int, TTranslation, TDestination>(multiLingualMapContext);
 }