示例#1
0
        public void AddOrUpdate(System.Globalization.CultureInfo culture, EntityKey key, IEnumerable<PropertyTranslation> propertyTranslations)
        {
            using (var db = new MultilingualDbContext(InstanceName))
            {
                var entry = db.Translations.Find(GetUnderlyingEntityKey(culture.Name, key));
                if (entry == null)
                {
                    entry = new EntityTranslationDbEntry
                    {
                        Culture = culture.Name,
                        EntityType = key.EntityType.Name,
                        EntityKey = key.Value.ToString()
                    };

                    entry.Properties = JsonConvert.SerializeObject(propertyTranslations);
                    db.Translations.Add(entry);
                }
                else
                {
                    entry.Properties = JsonConvert.SerializeObject(propertyTranslations);
                    entry.IsOutOfDate = false;
                }

                db.SaveChanges();

                Event.Raise(new TranslationUpdated(key, propertyTranslations, culture), GetInstance());
            }
        }
        public void AddOrUpdate(System.Globalization.CultureInfo culture, EntityKey key, IEnumerable <PropertyTranslation> propertyTranslations)
        {
            using (var db = new MultilingualDbContext(InstanceName))
            {
                var entry = db.Translations.Find(GetUnderlyingEntityKey(culture.Name, key));
                if (entry == null)
                {
                    entry = new EntityTranslationDbEntry
                    {
                        Culture    = culture.Name,
                        EntityType = key.EntityType.Name,
                        EntityKey  = key.Value.ToString()
                    };

                    entry.Properties = JsonConvert.SerializeObject(propertyTranslations);
                    db.Translations.Add(entry);
                }
                else
                {
                    entry.Properties  = JsonConvert.SerializeObject(propertyTranslations);
                    entry.IsOutOfDate = false;
                }

                db.SaveChanges();

                Event.Raise(new TranslationUpdated(key, propertyTranslations, culture), GetInstance());
            }
        }