Ejemplo n.º 1
0
        public static void SaveLocalizableValue(Entity entity, LocalizableString localizableValue, string columnName)
        {
            if (UseMultilanguageData)
            {
                return;
            }
            var    userConnection      = entity.UserConnection;
            var    entitySchemaManager = userConnection.EntitySchemaManager;
            var    query          = new EntitySchemaQuery(entitySchemaManager, "SysCulture");
            var    idColumnName   = query.AddColumn("Id").Name;
            var    nameColumnName = query.AddColumn("Name").Name;
            var    sysCultures    = query.GetEntityCollection(userConnection);
            string lczSchemaName  = entity.Schema.GetLocalizableStringsSchemaName();
            var    lczSchema      = entitySchemaManager.GetInstanceByName(lczSchemaName);

            foreach (var sysCulture in sysCultures)
            {
                string cultureName = sysCulture.GetTypedColumnValue <string>(nameColumnName);
                var    culture     = CultureInfo.GetCultureInfo(cultureName);
                string lczValue    = string.Empty;
                if (!localizableValue.HasCultureValue(culture))
                {
                    lczValue = localizableValue.GetCultureValue(GeneralResourceStorage.CurrentCulture);
                }
                else
                {
                    lczValue = localizableValue.GetCultureValue(culture);
                }
                Guid   cultureId         = sysCulture.GetTypedColumnValue <Guid>(idColumnName);
                Guid   columnUId         = entity.Schema.Columns.FindByName(columnName).UId;
                Entity newLczValueEntity = lczSchema.CreateEntity(userConnection);
                newLczValueEntity.SetDefColumnValues();
                newLczValueEntity.FetchFromDB(new Dictionary <string, object> {
                    { "SysCulture", cultureId },
                    { "Record", entity.PrimaryColumnValue },
                    { "ColumnUId", columnUId },
                });
                newLczValueEntity.SetColumnValue("SysCultureId", cultureId);
                newLczValueEntity.SetColumnValue("ColumnUId", columnUId);
                newLczValueEntity.SetColumnValue("Value", lczValue);
                newLczValueEntity.SetColumnValue("RecordId", entity.PrimaryColumnValue);
                newLczValueEntity.Save();
            }
        }