public Task SendEmail(string address, NotificationTemplateType type, Dictionary <string, string> parameters)
        {
            var templateDelegator = new NotificationDelegator();
            var template          = templateDelegator.GetTemplate(type, parameters);

            return(SendEmail(address, template));
        }
        private void UpdateAllowedTags()
        {
            lbAllowedTags.DataSource   = null;
            lbAllowedTags.SelectedItem = null;

            NotificationTemplateType templateType = (NotificationTemplateType)cbTemplateType.SelectedItem;

            if (NotificationTypeTag.NotificationTags.ContainsKey(templateType))
            {
                var allowedTags     = NotificationTypeTag.NotificationTags[templateType];
                var allowedTagnames = allowedTags.Select(a => NotificationTypeTag.TagName(a)).OrderBy(a => a).ToArray();
                lbAllowedTags.DataSource   = allowedTagnames;
                lbAllowedTags.SelectedItem = null;
            }
        }
Example #3
0
 public NotificationBindingPart(NotificationTemplateType template)
 {
     this.Template = template;
 }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(txTemplateName.Text))
            {
                Controller.HandleError("Name is required", "Validation Error");
                return;
            }

            if (String.IsNullOrWhiteSpace(txTemplateText.Text))
            {
                Controller.HandleError("Text is required", "Validation Error");
                return;
            }

            //if not General then can only have one

            NotificationTemplateType templateType = (NotificationTemplateType)cbTemplateType.SelectedItem;

            if (templateType != NotificationTemplateType.General)
            {
                var existing = _Context.NotificationTemplateSet.Where(a => a.TemplateType == templateType).FirstOrDefault();
                if (existing != null)
                {
                    if (_Item == null || _Item.id != existing.id)
                    {
                        Controller.HandleError("A template is already defined for " + templateType.ToString() + " please edit the existing tempalte", "Validation Error");
                        return;
                    }
                }

                //validate that all tags are valid

                var tags        = NotificationTemplate.GetAllTags(txTemplateText.Text);
                var allowedTags = NotificationTypeTag.NotificationTags[templateType];

                var allowedTagnames = allowedTags.Select(a => NotificationTypeTag.TagName(a)).ToArray();

                var tagsNotAllowed = tags.Where(a => !allowedTagnames.Contains(a)).ToList();
                if (tagsNotAllowed.Count() > 0)
                {
                    string errText = string.Empty;
                    foreach (var s in tagsNotAllowed)
                    {
                        errText += s + Environment.NewLine;
                    }

                    Controller.HandleError("The following tags are invalid for this message type " + Environment.NewLine +
                                           errText, "Validation Error");
                    return;
                }
            }

            if (_Item == null)
            {
                _Item = new NotificationTemplate();
                _Context.NotificationTemplateSet.Add(_Item);
            }

            _Item.TemplateName = txTemplateName.Text;
            _Item.MessageText  = txTemplateText.Text;
            _Item.TemplateType = (NotificationTemplateType)cbTemplateType.SelectedItem;

            try
            {
                bool isNew = _Item.id == 0;
                _Context.SaveChanges();

                if (isNew)
                {
                    _Data.Insert(0, _Item);
                }
                BindDataGrid();
                GotoReadOnly();
            }
            catch (DbUpdateException)
            {
                Controller.HandleError("Possible duplicate record detected", "Database Error");
            }
            catch (Exception ex2)
            {
                Controller.HandleError(ex2.Message);
            }
        }
Example #5
0
        public async Task <IActionResult> LoadNotifications(int pageIndex, int pageSize, NotificationTemplateType type)
        {
            var(notifications, loadMore) = await _notificationService.GetPagedNotificationsAsync(
                await _userService.GetCurrentUserIdAsync(),
                pageIndex, pageSize);

            var model = new NotificationTemplateModel
            {
                LoadMore      = loadMore,
                Notifications = notifications
            };

            string template;

            switch (type)
            {
            case NotificationTemplateType.Main:
                template = await _renderService.RenderViewToStringAsync("Templates/_MainNotification", model);

                break;

            case NotificationTemplateType.Mini:

                var liCollection = new List <string>();

                foreach (var notification in notifications)
                {
                    liCollection.Add(
                        await _renderService.RenderViewToStringAsync("Templates/_MiniNotification", notification));
                }

                template = string.Join("", liCollection);
                break;

            default:
                throw new InvalidOperationException(nameof(type));
            }

            return(Json(new
            {
                notifications = template,
                loadMore,
                type
            }));
        }