public void UpdateLanguage(string code, string key, string value)
        {
            ListResult <LanguageDetailDto> langsInCache = GetLanguageInCache();
            LanguageDetail langDetail = languageDetailRepository.GetFirstByCondition(x => x.LanguageCode == code && x.LanguageKey == key);

            if (langDetail != null)
            {
                langDetail.LanguageValue = value;
                langDetail.UpdateToken   = Guid.NewGuid();
                langDetail.ModifiedDate  = DateTime.Now;
                langDetail.ModifiedBy    = GetCurrentUserLogin();
                languageDetailRepository.Update(langDetail);
                unitOfWork.SaveChanges();
                LanguageDetailDto langDetailDto = mapper.Map <LanguageDetailDto>(langDetail);
                AddLanguageToCache(langDetailDto);
            }
        }
 private void AddLanguageToCache(LanguageDetailDto languageDetailDto)
 {
     if (languageDetailDto.LanguageCode == CultureInfo.CurrentCulture.Name)
     {
         ListResult <LanguageDetailDto> languagesInCache = GetLanguageInCache();
         LanguageDetailDto lang = languagesInCache.DataList.Where(x => x.LanguageKey == languageDetailDto.LanguageKey).FirstOrDefault();
         if (lang == null)
         {
             languagesInCache.DataList.Add(languageDetailDto);
             memoryCache.Set(ConstantConfig.MemoryCacheConfig.LanguageCache, languagesInCache);
         }
         else
         {
             lang.LanguageValue = languageDetailDto.LanguageValue;
         }
     }
 }
        public string GetlangByKey(string key)
        {
            // fix key
            if (!key.StartsWith("LBL_"))
            {
                key = "LBL_" + key.ToUpper();
            }
            else
            {
                key = key.ToUpper();
            }

            string langCode  = CultureInfo.CurrentCulture.Name;
            string langValue = "[" + key + "]";
            ListResult <LanguageDetailDto> langsInCache = GetLanguageInCache();
            LanguageDetailDto langDetailDto             = langsInCache.GetFirstByCondition(x => x.LanguageCode == langCode && x.LanguageKey == key);

            if (langDetailDto == null)
            {
                string[] allLangCodes = languageRepository.GetAll().Select(x => x.LangCode).ToArray();
                foreach (string code in allLangCodes)
                {
                    LanguageDetail langDetail = new LanguageDetail()
                    {
                        LanguageCode  = code,
                        LanguageKey   = key,
                        LanguageValue = langValue,
                        CreatedBy     = GetCurrentUserLogin(),
                        CreatedDate   = DateTime.Now,
                        ModifiedDate  = DateTime.Now
                    };
                    langDetail = languageDetailRepository.Add(langDetail);

                    if (code.Equals(langCode))
                    {
                        langDetailDto = mapper.Map <LanguageDetailDto>(langDetail);
                    }
                }

                unitOfWork.SaveChanges();
                AddLanguageToCache(langDetailDto);
            }
            return(langDetailDto.LanguageValue);
        }