Example #1
0
        public ActionResult TestTemplate(int id, int languageId = 0)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageMessageTemplates))
            {
                return(AccessDeniedView());
            }

            var messageTemplate = _messageTemplateService.GetMessageTemplateById(id);

            if (messageTemplate == null)
            {
                //No message template found with the specified id
                return(RedirectToAction("List"));
            }

            var model = new TestMessageTemplateModel
            {
                Id         = messageTemplate.Id,
                LanguageId = languageId
            };

            //filter tokens to the current template
            var subject = messageTemplate.GetLocalized(mt => mt.Subject, languageId);
            var body    = messageTemplate.GetLocalized(mt => mt.Body, languageId);

            model.Tokens = _messageTokenProvider.GetListOfAllowedTokens().Where(x => subject.Contains(x) || body.Contains(x)).ToList();

            return(View(model));
        }
        /// <summary>
        /// Prepare test message template model
        /// </summary>
        /// <param name="model">Test message template model</param>
        /// <param name="messageTemplate">Message template</param>
        /// <param name="languageId">Language identifier</param>
        /// <returns>Test message template model</returns>
        public virtual TestMessageTemplateModel PrepareTestMessageTemplateModel(TestMessageTemplateModel model,
                                                                                MessageTemplate messageTemplate, int languageId)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            if (messageTemplate == null)
            {
                throw new ArgumentNullException(nameof(messageTemplate));
            }

            model.Id         = messageTemplate.Id;
            model.LanguageId = languageId;

            //filter tokens to the current template
            var subject = messageTemplate.GetLocalized(entity => entity.Subject, languageId);
            var body    = messageTemplate.GetLocalized(entity => entity.Body, languageId);

            model.Tokens = _messageTokenProvider.GetListOfAllowedTokens()
                           .Where(token => subject.Contains(token) || body.Contains(token)).ToList();

            return(model);
        }
Example #3
0
        public ActionResult TestTemplate(TestMessageTemplateModel model, FormCollection form)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageMessageTemplates))
                return AccessDeniedView();

            var messageTemplate = _messageTemplateService.GetMessageTemplateById(model.Id);
            if (messageTemplate == null)
                //No message template found with the specified id
                return RedirectToAction("List");

            var tokens = new List<Token>();
            foreach (var formKey in form.AllKeys)
                if (formKey.StartsWith("token_", StringComparison.InvariantCultureIgnoreCase))
                {
                    var tokenKey = formKey.Substring("token_".Length).Replace("%", "");
                    var tokenValue = form[formKey];
                    tokens.Add(new Token(tokenKey, tokenValue));
                }

            _workflowMessageService.SendTestEmail(messageTemplate.Id, model.SendTo, tokens, model.LanguageId);

            if (ModelState.IsValid)
            {
                SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.MessageTemplates.Test.Success"));
            }

            return RedirectToAction("Edit", new {id = messageTemplate.Id});
        }
        public IActionResult TestTemplate(TestMessageTemplateModel model, IFormCollection form)
        {
            var messageTemplate = _messageTemplateService.GetMessageTemplateById(model.Id);

            if (messageTemplate == null)
            {
                //No message template found with the specified id
                return(RedirectToAction("List"));
            }

            var tokens = new List <Token>();

            foreach (var formKey in form.Keys)
            {
                if (formKey.StartsWith("token_", StringComparison.OrdinalIgnoreCase))
                {
                    var tokenKey   = formKey.Substring("token_".Length).Replace("%", "");
                    var tokenValue = form[formKey];
                    tokens.Add(new Token(tokenKey, tokenValue));
                }
            }

            _workflowMessageService.SendTestEmail(messageTemplate.Id, model.SendTo, tokens, model.LanguageId);

            if (ModelState.IsValid)
            {
                SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.MessageTemplates.Test.Success"));
            }

            return(RedirectToAction("Edit", new { id = messageTemplate.Id }));
        }
        public IActionResult TestTemplate(string id, string languageId = "")
        {
            var messageTemplate = _messageTemplateService.GetMessageTemplateById(id);

            if (messageTemplate == null)
            {
                //No message template found with the specified id
                return(RedirectToAction("List"));
            }

            var model = new TestMessageTemplateModel
            {
                Id         = messageTemplate.Id,
                LanguageId = languageId
            };
            var tokens = _messageTokenProvider.GetListOfAllowedTokens().Distinct().ToList();
            //filter them to the current template
            var subject = messageTemplate.GetLocalized(mt => mt.Subject, languageId);
            var body    = messageTemplate.GetLocalized(mt => mt.Body, languageId);

            tokens       = tokens.Where(x => subject.Contains(x) || body.Contains(x)).ToList();
            model.Tokens = tokens;

            return(View(model));
        }
Example #6
0
        public virtual ActionResult TestTemplate(TestMessageTemplateModel model, FormCollection form)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageMessageTemplates))
            {
                return(AccessDeniedView());
            }

            var messageTemplate = _messageTemplateService.GetMessageTemplateById(model.Id);

            if (messageTemplate == null)
            {
                //No message template found with the specified id
                return(RedirectToAction("List"));
            }

            var tokens = new List <Token>();

            foreach (var formKey in form.AllKeys)
            {
                if (formKey.StartsWith("token_", StringComparison.InvariantCultureIgnoreCase))
                {
                    var tokenKey    = formKey.Substring("token_".Length).Replace("%", "");
                    var stringValue = form[formKey];

                    //try get non-string value
                    object  tokenValue;
                    bool    boolValue;
                    int     intValue;
                    decimal decimalValue;
                    if (bool.TryParse(stringValue, out boolValue))
                    {
                        tokenValue = boolValue;
                    }
                    else if (int.TryParse(stringValue, out intValue))
                    {
                        tokenValue = intValue;
                    }
                    else if (decimal.TryParse(stringValue, out decimalValue))
                    {
                        tokenValue = decimalValue;
                    }
                    else
                    {
                        tokenValue = stringValue;
                    }

                    tokens.Add(new Token(tokenKey, tokenValue));
                }
            }

            _workflowMessageService.SendTestEmail(messageTemplate.Id, model.SendTo, tokens, model.LanguageId);

            if (ModelState.IsValid)
            {
                SuccessNotification(_localizationService.GetResource("Admin.ContentManagement.MessageTemplates.Test.Success"));
            }

            return(RedirectToAction("Edit", new { id = messageTemplate.Id }));
        }
        public virtual IActionResult TestTemplate(TestMessageTemplateModel model, IFormCollection form)
        {
            //try to get a message template with the specified id
            var messageTemplate = _messageTemplateService.GetMessageTemplateById(model.Id);

            if (messageTemplate == null)
            {
                return(RedirectToAction("List"));
            }

            var tokens = new List <Token>();

            foreach (var formKey in form.Keys)
            {
                if (formKey.StartsWith("token_", StringComparison.InvariantCultureIgnoreCase))
                {
                    var tokenKey    = formKey.Substring("token_".Length).Replace("%", string.Empty);
                    var stringValue = form[formKey].ToString();

                    //try get non-string value
                    object tokenValue;
                    if (bool.TryParse(stringValue, out var boolValue))
                    {
                        tokenValue = boolValue;
                    }
                    else if (int.TryParse(stringValue, out var intValue))
                    {
                        tokenValue = intValue;
                    }
                    else if (decimal.TryParse(stringValue, out var decimalValue))
                    {
                        tokenValue = decimalValue;
                    }
                    else
                    {
                        tokenValue = stringValue;
                    }

                    tokens.Add(new Token(tokenKey, tokenValue));
                }
            }

            _workflowMessageService.SendTestEmail(messageTemplate.Id, model.SendTo, tokens);

            if (ModelState.IsValid)
            {
                _notificationService.SuccessNotification("Email has been successfully queued.");
            }

            return(RedirectToAction("Edit", new { id = messageTemplate.Id }));
        }
        public virtual async Task <IActionResult> TestTemplate(TestMessageTemplateModel model, IFormCollection form)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageMessageTemplates))
            {
                return(AccessDeniedView());
            }

            //try to get a message template with the specified id
            var messageTemplate = await _messageTemplateService.GetMessageTemplateByIdAsync(model.Id);

            if (messageTemplate == null)
            {
                return(RedirectToAction("List"));
            }

            var tokens = new List <Token>();

            foreach (var formKey in form.Keys)
            {
                if (formKey.StartsWith("token_", StringComparison.InvariantCultureIgnoreCase))
                {
                    var tokenKey    = formKey["token_".Length..].Replace("%", string.Empty);