예제 #1
0
        public static EmailNotification Create(UserNotification notification, IImageFormatter imageFormatter)
        {
            var result = new EmailNotification
            {
                Body        = OrNull(notification.Formatting.Body),
                LinkText    = OrNull(notification.Formatting.LinkText),
                LinkUrl     = OrNull(notification.Formatting.LinkUrl),
                TrackingUrl = notification.TrackingUrl,
                Subject     = notification.Formatting.Subject,
            };

            if (!string.IsNullOrWhiteSpace(notification.Formatting.ImageLarge))
            {
                result.ImageLarge = imageFormatter.Format(notification.Formatting.ImageLarge, "EmailLarge");
            }

            if (!string.IsNullOrWhiteSpace(notification.Formatting.ImageSmall))
            {
                result.ImageSmall = imageFormatter.Format(notification.Formatting.ImageSmall, "EmailLarge");
            }

            if (notification.Formatting.ConfirmMode == ConfirmMode.Explicit)
            {
                result.ConfirmText = OrNull(notification.Formatting.ConfirmText);
                result.ConfirmUrl  = notification.ConfirmUrl;
            }

            return(result);
        }
예제 #2
0
        private TemplateContext CreateContext(IEnumerable <UserNotification> notifications, App app, User user)
        {
            var context = new TemplateContext();

            var emailNotifications = notifications.Select(x => EmailNotification.Create(x, imageFormatter)).ToList();

            context.SetValue("app", app);
            context.SetValue("user", user);
            context.SetValue("notifications", emailNotifications);

            context.MemberAccessStrategy.MemberNameStrategy = MemberNameStrategies.CamelCase;
            context.MemberAccessStrategy.Register <EmailNotification>();

            return(context);
        }