Esempio n. 1
0
        async Task <CommunicationBlast> ICommunicationBlastFinder.FindAsync(Creative creative)
        {
            var blast = await Rdb.CommunicationBlasts.FirstOrDefaultAsync(z => z.CreativeId == creative.CreativeId);

            if (blast != null)
            {
                return(blast);
            }
            var comm = await Rdb.Communications.OrderBy(z => z.CommunicationId).Take(1).SingleAsync();

            var blastSpecificCreative = new Creative(creative);
            var filler = new CommunicationsFiller(CreativeSettingsFinder, null);

            filler.Flatten(blastSpecificCreative.CreativeSettings);
            Rdb.Creatives.Add(blastSpecificCreative);
            blast = new CommunicationBlast
            {
                Communication = comm,
                Creative      = blastSpecificCreative,
            };
            Rdb.CommunicationBlasts.Add(blast);
            await Rdb.SaveChangesAsync();

            return(blast);
        }
Esempio n. 2
0
        public static void Fill(
            this MimeMessage message,
            ICreativeSettingsFinder finder,
            ICollection <ReusableValue> reusableValues,
            Creative creative,
            CommunicationTypes ct,
            ApplicationUser u,
            Contact c,
            object model)
        {
            Requires.NonNull(message, nameof(message));
            Requires.NonNull(creative, nameof(creative));

            var filler = new CommunicationsFiller(finder, reusableValues);

            if (c != null)
            {
                message.ContactId(c.ContactId);
            }
            else if (u != null)
            {
                message.ContactId(u.ContactId);
            }


            var context = new Dictionary <string, object> {
                { "User", u }, { "Contact", c }, { "Model", model }
            };
            var compiledContext = new CommunicationsFiller.CompiledContext(context);
            var indexerByName   = new Dictionary <string, IDictionary <string, string> >();

            MimeEntity textPart = null;
            MimeEntity htmlPart = null;

            switch (ct)
            {
            case CommunicationTypes.Email:
                message.Subject = filler.Evaluate(creative, z => z.EmailSubject, compiledContext);
                textPart        = new TextPart(TextFormat.Text)
                {
                    Text = filler.Evaluate(creative, z => z.EmailTextBody, compiledContext)
                };
                htmlPart = new TextPart(TextFormat.Html)
                {
                    Text = filler.Evaluate(creative, z => z.EmailHtmlBody, compiledContext)
                };
                break;

            case CommunicationTypes.Sms:
                textPart = new TextPart(TextFormat.Text)
                {
                    Text = filler.Evaluate(creative, z => z.TextMessageBody, compiledContext)
                };
                break;

            default:
                throw new UnexpectedSwitchValueException(ct);
            }

            if (textPart == null || htmlPart == null)
            {
                message.Body = textPart ?? htmlPart;
            }
            else
            {
                message.Body = new MultipartAlternative(textPart, htmlPart);
            }
        }