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));
            }
        }
Ejemplo n.º 2
0
        public async Task ImportSaveTextAsync(int userId, EmailBaseText emailBaseText)
        {
            var dbEntity = _mapper.Map <EmailBaseText, Model.EmailBaseText>(emailBaseText);

            dbEntity.CreatedBy = userId;
            dbEntity.CreatedAt = _dateTimeProvider.Now;
            EntityEntry <Model.EmailBaseText> dbEntityEntry = _context.Entry(dbEntity);

            if (dbEntityEntry.State != EntityState.Detached)
            {
                dbEntityEntry.State = EntityState.Added;
            }
            else
            {
                await _context.EmailBaseTexts.AddAsync(dbEntity);
            }
            await SaveAsync();
        }