public bool Create(string context, int?idx, string langCode, string value, string orgValue)
        {
            // start transaction
            try
            {
                beginDbTransaction();

                int key = EditableString.GetKey(context, orgValue, idx);
                storeNewPersistentString(key, context, idx, value, orgValue, langCode);

                commitDbTransaction();
            }
            catch (Exception ex)
            {
                logError("Error creating ES", ex);
                rollbackDbTransaction();
                return(false);
            }
            finally
            {
                disposeDbTransaction();
            }
            // remove conext from cache
            if (!string.IsNullOrWhiteSpace(context))
            {
                string cacheKey = getCacheContextKey(langCode, context);
                cacheService.Remove(cacheKey);
            }
            return(true);
        }
        public virtual EditableString GetString(string context, string t, int?idx)
        {
            var curUICulture = System.Threading.Thread.CurrentThread.CurrentUICulture;
            var langCode     = curUICulture.TwoLetterISOLanguageName;
            // we are caching by contexts and language
            string cacheKey         = getCacheContextKey(langCode, context);
            var    stringsInContext = cacheService.Get(cacheKey, -1,
                                                       () =>
            {
                var inContext = getDbQuery().Where(x => x.ESContext == context && x.ESLanguageCode == langCode).ToList();
                return(toEditableStringList(inContext).ToDictionary(x => x.Key));
            });

            int key = EditableString.GetKey(context, t, idx);
            // find key in our (possibly cached) list
            EditableString found = null;

            if (stringsInContext.TryGetValue(key, out found))
            {
                return(found);
            }
            return(null);
        }
        public virtual int RecalcKeys()
        {
            int updatedCount = 0;

            try
            {
                beginDbTransaction();

                var existingData = getDbQuery().ToList();
                foreach (var es in existingData)
                {
                    es.ESKey = EditableString.GetKey(es.ESContext, es.ESOriginalValue, es.ESIndex);
                    updatePersistentString(es);
                    updatedCount++;
                }

                commitDbTransaction();
            }
            catch (Exception ex)
            {
                logError("Error updating keys", ex);
                rollbackDbTransaction();
                updatedCount = -1;
            }
            finally
            {
                disposeDbTransaction();
            }

            // remove from cache
            if (updatedCount > 0)
            {
                cacheService.RemoveByPattern(CACHE_PER_LANG_CONTEXT_KEY);
            }

            return(updatedCount);
        }