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());
            }
        }
 public IEnumerable <Language> All()
 {
     using (var db = new MultilingualDbContext(InstanceName))
     {
         return(db.Languages.ToList());
     }
 }
 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);
        }
 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());
            }
        }
 public IEnumerable<Language> All()
 {
     using (var db = new MultilingualDbContext(InstanceName))
     {
         return db.Languages.ToList();
     }
 }
 public bool Exists(string name)
 {
     using (var db = new MultilingualDbContext(InstanceName))
     {
         return db.Languages.Any(l => l.Name == name);
     }
 }
 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());
     }
 }
 public void Update(Language language)
 {
     using (var db = new MultilingualDbContext(InstanceName))
     {
         var existing = db.Languages.Find(language.Name);
         existing.DisplayName = language.DisplayName;
         db.SaveChanges();
     }
 }
        public void Add(Language language)
        {
            using (var db = new MultilingualDbContext(InstanceName))
            {
                db.Languages.Add(language);
                db.SaveChanges();

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

                Event.Raise(new LanguageAdded(language.Name), GetInstance());
            }
        }
        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());
            }
        }
        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());
            }
        }
 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();
         }
     }
 }
 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();
         }
     }
 }
 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();
         }
     }
 }
        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;
                }));
            }
        }
        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;
        }
 public void Update(Language language)
 {
     using (var db = new MultilingualDbContext(InstanceName))
     {
         var existing = db.Languages.Find(language.Name);
         existing.DisplayName = language.DisplayName;
         db.SaveChanges();
     }
 }
 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();
     }
 }
 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();
         }
     }
 }
        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;
                         });
            }
        }