Exemplo n.º 1
0
 public Language Find(string name)
 {
     using (var db = new MultilingualDbContext(InstanceName))
     {
         return(db.Languages.Find(name));
     }
 }
        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());
            }
        }
Exemplo n.º 3
0
 public IEnumerable <Language> All()
 {
     using (var db = new MultilingualDbContext(InstanceName))
     {
         return(db.Languages.ToList());
     }
 }
Exemplo n.º 4
0
 public bool Exists(string name)
 {
     using (var db = new MultilingualDbContext(InstanceName))
     {
         return(db.Languages.Any(l => l.Name == name));
     }
 }
        public EntityTransaltion[] Find(System.Globalization.CultureInfo culture, params EntityKey[] keys)
        {
            var result = new EntityTransaltion[keys.Length];

            using (var db = new MultilingualDbContext(InstanceName))
            {
                for (var i = 0; i < keys.Length; i++)
                {
                    var key   = keys[i];
                    var entry = db.Translations.Find(GetUnderlyingEntityKey(culture.Name, key));

                    if (entry != null)
                    {
                        var translation = new EntityTransaltion(culture.Name, new EntityKey(key.EntityType, key.Value))
                        {
                            IsOutOfDate          = entry.IsOutOfDate,
                            PropertyTranslations = JsonConvert.DeserializeObject <List <PropertyTranslation> >(entry.Properties)
                        };

                        result[i] = translation;
                    }
                }
            }

            return(result);
        }
Exemplo n.º 6
0
 public Language Find(string name)
 {
     using (var db = new MultilingualDbContext(InstanceName))
     {
         return db.Languages.Find(name);
     }
 }
Exemplo n.º 7
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());
            }
        }
Exemplo n.º 8
0
 public IEnumerable<Language> All()
 {
     using (var db = new MultilingualDbContext(InstanceName))
     {
         return db.Languages.ToList();
     }
 }
Exemplo n.º 9
0
 public bool Exists(string name)
 {
     using (var db = new MultilingualDbContext(InstanceName))
     {
         return db.Languages.Any(l => l.Name == name);
     }
 }
Exemplo n.º 10
0
 public int TotalOutOfDate(CultureInfo culture, Type entityType)
 {
     using (var db = new MultilingualDbContext(InstanceName))
     {
         return(db.Translations.Where(it => it.Culture == culture.Name && it.EntityType == entityType.Name && it.IsOutOfDate).Count());
     }
 }
Exemplo n.º 11
0
 public void Update(Language language)
 {
     using (var db = new MultilingualDbContext(InstanceName))
     {
         var existing = db.Languages.Find(language.Name);
         existing.DisplayName = language.DisplayName;
         db.SaveChanges();
     }
 }
Exemplo n.º 12
0
        public void Add(Language language)
        {
            using (var db = new MultilingualDbContext(InstanceName))
            {
                db.Languages.Add(language);
                db.SaveChanges();

                Event.Raise(new LanguageAdded(language.Name), GetInstance());
            }
        }
Exemplo n.º 13
0
        public void Add(Language language)
        {
            using (var db = new MultilingualDbContext(InstanceName))
            {
                db.Languages.Add(language);
                db.SaveChanges();

                Event.Raise(new LanguageAdded(language.Name), GetInstance());
            }
        }
Exemplo n.º 14
0
        public void Delete(string name)
        {
            using (var db = new MultilingualDbContext(InstanceName))
            {
                var lang = db.Languages.Find(name);
                db.Languages.Remove(lang);
                db.SaveChanges();

                Event.Raise(new LanguageDeleted(lang.Name), GetInstance());
            }
        }
Exemplo n.º 15
0
        public void Delete(string name)
        {
            using (var db = new MultilingualDbContext(InstanceName))
            {
                var lang = db.Languages.Find(name);
                db.Languages.Remove(lang);
                db.SaveChanges();

                Event.Raise(new LanguageDeleted(lang.Name), GetInstance());
            }
        }
Exemplo n.º 16
0
 public void Delete(CultureInfo culture, EntityKey key)
 {
     using (var db = new MultilingualDbContext(InstanceName))
     {
         var entry = db.Translations.Find(GetUnderlyingEntityKey(culture.Name, key));
         if (entry != null)
         {
             db.Translations.Remove(entry);
             db.SaveChanges();
         }
     }
 }
Exemplo n.º 17
0
 public void MarkOutOfDate(CultureInfo culture, EntityKey key)
 {
     using (var db = new MultilingualDbContext(InstanceName))
     {
         var entry = db.Translations.Find(GetUnderlyingEntityKey(culture.Name, key));
         if (entry != null)
         {
             entry.IsOutOfDate = true;
             db.SaveChanges();
         }
     }
 }
Exemplo n.º 18
0
 public void Delete(CultureInfo culture, EntityKey key)
 {
     using (var db = new MultilingualDbContext(InstanceName))
     {
         var entry = db.Translations.Find(GetUnderlyingEntityKey(culture.Name, key));
         if (entry != null)
         {
             db.Translations.Remove(entry);
             db.SaveChanges();
         }
     }
 }
Exemplo n.º 19
0
        public Pagination <EntityTransaltion> FindOutOfDate(CultureInfo culture, Type entityType, int pageInex, int pageSize)
        {
            using (var db = new MultilingualDbContext(InstanceName))
            {
                return(db.Translations
                       .Where(t => t.Culture == culture.Name && t.EntityType == entityType.Name && t.IsOutOfDate)
                       .OrderBy(t => t.EntityKey)
                       .Paginate(pageInex, pageSize)
                       .Transform(entry =>
                {
                    var keyType = EntityKey.GetKeyProperty(entityType).PropertyType;
                    var translation = new EntityTransaltion(culture.Name, new EntityKey(entityType, Convert.ChangeType(entry.EntityKey, keyType)))
                    {
                        IsOutOfDate = true,
                        PropertyTranslations = JsonConvert.DeserializeObject <List <PropertyTranslation> >(entry.Properties)
                    };

                    return translation;
                }));
            }
        }
Exemplo n.º 20
0
        public EntityTransaltion[] Find(System.Globalization.CultureInfo culture, params EntityKey[] keys)
        {
            var result = new EntityTransaltion[keys.Length];

            using (var db = new MultilingualDbContext(InstanceName))
            {
                for (var i = 0; i < keys.Length; i++)
                {
                    var key = keys[i];
                    var entry = db.Translations.Find(GetUnderlyingEntityKey(culture.Name, key));

                    if (entry != null)
                    {
                        var translation = new EntityTransaltion(culture.Name, new EntityKey(key.EntityType, key.Value))
                        {
                            IsOutOfDate = entry.IsOutOfDate,
                            PropertyTranslations = JsonConvert.DeserializeObject<List<PropertyTranslation>>(entry.Properties)
                        };

                        result[i] = translation;
                    }
                }
            }

            return result;
        }
Exemplo n.º 21
0
 public void Update(Language language)
 {
     using (var db = new MultilingualDbContext(InstanceName))
     {
         var existing = db.Languages.Find(language.Name);
         existing.DisplayName = language.DisplayName;
         db.SaveChanges();
     }
 }
Exemplo n.º 22
0
 public int TotalTranslated(CultureInfo culture, Type entityType)
 {
     using (var db = new MultilingualDbContext(InstanceName))
     {
         return db.Translations.Where(it => it.Culture == culture.Name && it.EntityType == entityType.Name).Count();
     }
 }
Exemplo n.º 23
0
 public void MarkOutOfDate(CultureInfo culture, EntityKey key)
 {
     using (var db = new MultilingualDbContext(InstanceName))
     {
         var entry = db.Translations.Find(GetUnderlyingEntityKey(culture.Name, key));
         if (entry != null)
         {
             entry.IsOutOfDate = true;
             db.SaveChanges();
         }
     }
 }
Exemplo n.º 24
0
        public Pagination<EntityTransaltion> FindOutOfDate(CultureInfo culture, Type entityType, int pageInex, int pageSize)
        {
            using (var db = new MultilingualDbContext(InstanceName))
            {
                return db.Translations
                         .Where(t => t.Culture == culture.Name && t.EntityType == entityType.Name && t.IsOutOfDate)
                         .OrderBy(t => t.EntityKey)
                         .Paginate(pageInex, pageSize)
                         .Transform(entry =>
                         {
                             var keyType = EntityKey.GetKeyProperty(entityType).PropertyType;
                             var translation = new EntityTransaltion(culture.Name, new EntityKey(entityType, Convert.ChangeType(entry.EntityKey, keyType)))
                             {
                                 IsOutOfDate = true,
                                 PropertyTranslations = JsonConvert.DeserializeObject<List<PropertyTranslation>>(entry.Properties)
                             };

                             return translation;
                         });
            }
        }