Esempio n. 1
0
        // do NOT leak that language, it's not deep-cloned!
        private ILanguage GetDefault()
        {
            // get all cached
            var languages = (TypedCachePolicy?.GetAllCached(PerformGetAll) //try to get all cached non-cloned if using the correct cache policy (not the case in unit tests)
                             ?? CachePolicy.GetAll(Array.Empty <int>(), PerformGetAll)).ToList();

            var language = languages.FirstOrDefault(x => x.IsDefault);

            if (language != null)
            {
                return(language);
            }

            // this is an anomaly, the service/repo should ensure it cannot happen
            Logger.Warn <LanguageRepository>("There is no default language. Fix this anomaly by editing the language table in database and setting one language as the default language.");

            // still, don't kill the site, and return "something"

            ILanguage first = null;

            foreach (var l in languages)
            {
                if (first == null || l.Id < first.Id)
                {
                    first = l;
                }
            }

            return(first);
        }