public void Save(params ILocalizedObject[] list)
        {
            using (var context = new LocalizationContext())
            {
                context.Objects.AddOrUpdate(list.Cast <LocalizedObject>().ToArray());
                context.SaveChanges();
            }

            LocalizationCache.Clear();
        }
        public void Disable(params ILocalizedObject[] list)
        {
            foreach (var obj in list)
            {
                obj.Disable();
            }

            Repository.Save(list);
            LocalizationCache.Clear();
        }
        public IEnumerable <CultureInfo> GetCultures()
        {
            var lst = LocalizationCache.Get <IEnumerable <CultureInfo> >("cultures");

            if (lst == null || lst.Count() == 0)
            {
                lst = Repository.GetCultures().ToList();
                LocalizationCache.Insert("cultures", lst);
            }

            return(lst);
        }
        public IEnumerable <ILocalizedObject> GetAll(CultureInfo culture)
        {
            var lst = LocalizationCache.Get <IEnumerable <ILocalizedObject> >(culture.Name);

            if (lst == null || lst.Count() == 0)
            {
                lst = Repository.GetAll(culture).ToList();
                LocalizationCache.Insert(culture.Name, lst);
            }

            return(lst);
        }
        public ILocalizedObject Get(int key)
        {
            var obj = LocalizationCache.Get <ILocalizedObject>(key.ToString());

            if (obj == null)
            {
                using (var context = new LocalizationContext())
                {
                    obj = context.Objects.SingleOrDefault(o => o.Key == key);
                }

                LocalizationCache.Set(key.ToString(), obj);
            }

            return(obj);
        }
        public IEnumerable <ILocalizedObject> GetAll(CultureInfo culture)
        {
            var result = LocalizationCache.Get <IEnumerable <ILocalizedObject> >(culture.Name);

            if (result == null || !result.Any())
            {
                using (var context = new LocalizationContext())
                {
                    result = context.Objects.Where(obj => obj.LocaleId == culture.LCID && obj.Scope.StartsWith("~/")).ToList();
                }

                LocalizationCache.Set(culture.Name, result);
            }

            return(result);
        }
        public ILocalizedObject Get(int key, bool ignoreDisabled = false)
        {
            var obj = LocalizationCache.Get <ILocalizedObject>(key.ToString());

            if (obj == null)
            {
                obj = Repository.Get(key);
                LocalizationCache.Insert(key.ToString(), obj);
            }

            if (ignoreDisabled && obj.IsDisabled())
            {
                return(null);
            }

            return(obj);
        }
        public void Delete(params ILocalizedObject[] list)
        {
            using (var context = new LocalizationContext())
            {
                foreach (var obj in list)
                {
                    var stored = context.Objects.Where(x => x.Key == obj.Key).FirstOrDefault();
                    if (stored != null)
                    {
                        context.Objects.Remove(stored as LocalizedObject);
                    }
                }

                context.SaveChanges();
            }

            LocalizationCache.Clear();
        }
Exemple #9
0
        public IEnumerable <ILocalizedObject> GetAll(CultureInfo culture, string scope = null)
        {
            IEnumerable <ILocalizedObject> result = null;

            if (culture != null && scope == null)
            {
                result = LocalizationCache.Get <IEnumerable <ILocalizedObject> >(culture.Name);
            }

            if (result == null || !result.Any())
            {
                using (var context = new LocalizationContext())
                {
                    var query = context.Objects.Where(obj => obj.Scope.StartsWith("~/"));

                    if (culture != null)
                    {
                        query = query.Where(obj => obj.LocaleId == culture.LCID);
                    }

                    if (scope != null)
                    {
                        query = query.Where(obj => obj.Scope == scope);
                    }

                    result = query.ToList();
                }

                if (culture != null && scope == null)
                {
                    LocalizationCache.Set(culture.Name, result);
                }
            }

            return(result);
        }
 public void Save(params ILocalizedObject[] list)
 {
     Repository.Save(list);
     LocalizationCache.Clear();
 }