Exemplo n.º 1
0
        private Dictionary <string, string?> CreateProperties(List <EmailJob> jobs, App app, User user, EmailJob firstJob)
        {
            var notification = firstJob.Notification;

            var formattingProperties = new Dictionary <string, string?>(StringComparer.InvariantCulture)
            {
                ["app.name"]             = app.Name,
                ["user.name"]            = user.FullName,
                ["user.nameFull"]        = user.FullName,
                ["user.fullName"]        = user.FullName,
                ["user.email"]           = user.EmailAddress,
                ["user.emailAddress"]    = user.EmailAddress,
                ["notification.subject"] = notification.Formatting.Subject,
                ["notification.body"]    = notification.Formatting.Body,
                ["preferencesUrl"]       = emailUrl.EmailPreferences(user.ApiKey, user.PreferredLanguage)
            };

            foreach (var job in jobs)
            {
                var properties = job.Notification.Properties;

                if (properties != null)
                {
                    foreach (var(key, value) in properties)
                    {
                        formattingProperties[$"notification.custom.{key}"] = value;
                    }
                }
            }

            return(formattingProperties);
        }
Exemplo n.º 2
0
        private TemplateContext CreateContext(IEnumerable <BaseUserNotification> notifications, App app, User user)
        {
            var context = new TemplateContext(Options);

            var emailNotifications = notifications.Select(x => new EmailNotification(x, user.EmailAddress, imageFormatter)).ToArray();

            context.SetValue("app", app);
            context.SetValue("user", user);
            context.SetValue("notifications", emailNotifications);
            context.SetValue("preferencesUrl", emailUrl.EmailPreferences(user.ApiKey, user.PreferredLanguage));

            return(context);
        }