public async Task ReplaceBaseTextAsync(int emailBaseId,
                                               int languageId,
                                               EmailBaseText emailBaseText)
        {
            if (emailBaseText == null)
            {
                throw new ArgumentNullException(nameof(emailBaseText));
            }

            var currentBase = await _emailBaseRepository
                              .GetWithTextByIdAsync(emailBaseId, languageId);

            if (currentBase == null)
            {
                throw new GraException("Unable to find that base template in the database.");
            }

            currentBase.EmailBaseText.TemplateHtml = emailBaseText.TemplateHtml;
            currentBase.EmailBaseText.TemplateMjml = emailBaseText.TemplateMjml;
            currentBase.EmailBaseText.TemplateText = emailBaseText.TemplateText;

            await _emailBaseRepository.UpdateSaveWithText(GetActiveUserId(), currentBase);

            if (currentBase?.EmailBaseText?.LanguageId != null)
            {
                await _cache.RemoveAsync(GetCacheKey(CacheKey.EmailBase,
                                                     emailBaseId,
                                                     currentBase.EmailBaseText.LanguageId));
            }
        }
Example #2
0
        private async Task <EmailBase> GetEmailBase(int emailBaseId, int languageId)
        {
            string cacheKey = GetCacheKey(CacheKey.EmailBase, emailBaseId, languageId);

            var fromCache = await _cache.GetObjectFromCacheAsync <EmailBase>(cacheKey);

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

            var emailBase = await _emailBaseRepository.GetWithTextByIdAsync(emailBaseId,
                                                                            languageId);

            if (emailBase != null)
            {
                await _cache.SaveToCacheAsync(cacheKey, emailBase, CacheEmailTemplatesHours);
            }

            return(emailBase);
        }