Ejemplo n.º 1
0
        public TranslationVal GetTranslation(TranslationValKey key)
        {
            TranslationVal translationVal = null;
            string         cacheKey       = key == null ? "TranslationValKey_null" : key.GetCacheKey();

            if (key != null && !TryGetCacheData(cacheKey, out translationVal, _cacheName))
            {
                translationVal = GetTranslationManager().GetTranslation(key);
                SetCacheData(_cacheName, cacheKey, translationVal);
            }
            return(translationVal);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Delete data in database
        /// </summary>
        /// <param name="key">Primary Key</param>
        public void Delete(TranslationValKey key)
        {
            if (key == null || key.CultureId < 0 || string.IsNullOrWhiteSpace(key.Key))
            {
                return;
            }

            var row = _dbContext.Table <TranslationRow>().Where(m => m.CultureId == key.CultureId && m.Key == key.Key).FirstOrDefault();

            if (row != null)
            {
                _dbContext.Delete(row);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get data in database
        /// </summary>
        /// <param name="key">Primary Key</param>
        /// <returns>read data</returns>
        public TranslationVal Get(TranslationValKey key)
        {
            if (key == null || key.CultureId < 0 || string.IsNullOrWhiteSpace(key.Key))
            {
                return(null);
            }

            var row = _dbContext.Table <TranslationRow>().Where(m => m.CultureId == key.CultureId && m.Key == key.Key).FirstOrDefault();

            if (row != null)
            {
                return(TranslationTransformer.ToBean(row));
            }
            return(null);
        }
        /// <summary>
        /// Get translation in database
        /// </summary>
        /// <param name="key">Translation key</param>
        /// <returns>Transaltion value</returns>
        public static string GetInDB(string key)
        {
            string result = Get("DB_" + key, true);

            if (result == null)
            {
                try
                {
                    int currentCultureId = GetCurrentCultureId();

                    var translationService = new TranslationService(_dbContext);
                    var translationValKey  = new TranslationValKey()
                    {
                        CultureId = currentCultureId,
                        Key       = key
                    };
                    var trValue = translationService.GetTranslation(translationValKey);

                    if (trValue != null && trValue.Value != null)
                    {
                        result = trValue.Value;
                    }
                    else
                    {
                        ILogger.Instance.Info(string.Format("Translation database not found {0}", key));
                    }
                }
                catch (Exception except)
                {
                    ILogger.Instance.Error("Get translation database error", except);
                }
                //Add translation in memory
                if (result != null)
                {
                    _currentTranslation.Add("DB_" + key, result);
                }
            }

            return(result);
        }
 internal TranslationVal GetTranslation(TranslationValKey key)
 {
     return(_module.Get(key));
 }