Exemplo n.º 1
0
        private static CreateMessageResult CreateSmsMessage(Person person, Dictionary <string, object> mergeObjects, SystemCommunication systemCommunication)
        {
            var isSmsEnabled        = MediumContainer.HasActiveSmsTransport() && !string.IsNullOrWhiteSpace(systemCommunication.SMSMessage);
            var createMessageResult = new CreateMessageResult();
            var smsNumber           = person.PhoneNumbers.GetFirstSmsNumber();
            var recipients          = new List <RockMessageRecipient>();

            if (string.IsNullOrWhiteSpace(smsNumber) || !isSmsEnabled)
            {
                var smsWarningMessage = $"No SMS number could be found for {person.FullName}.";
                if (!isSmsEnabled)
                {
                    smsWarningMessage = $"SMS is not enabled. {person.FullName} did not receive a notification.";
                }

                RockLogger.Log.Warning(RockLogDomains.Jobs, smsWarningMessage);
                createMessageResult.Warnings.Add(smsWarningMessage);
                return(createMessageResult);
            }

            recipients.Add(new RockSMSMessageRecipient(person, smsNumber, mergeObjects));

            var message = new RockSMSMessage(systemCommunication);

            message.SetRecipients(recipients);
            createMessageResult.Message = message;
            return(createMessageResult);
        }
Exemplo n.º 2
0
        private static CreateMessageResult CreateEmailMessage(Person person, Dictionary <string, object> mergeObjects, SystemCommunication systemCommunication)
        {
            var createMessageResult = new CreateMessageResult();

            if (string.IsNullOrWhiteSpace(person.Email))
            {
                var warning = $"{person.FullName} does not have an email address entered.";
                createMessageResult.Warnings.Add(warning);
                RockLogger.Log.Warning(RockLogDomains.Jobs, warning);
                return(createMessageResult);
            }

            if (!person.IsEmailActive)
            {
                var warning = $"{person.FullName.ToPossessive()} email address is inactive.";
                createMessageResult.Warnings.Add(warning);
                RockLogger.Log.Warning(RockLogDomains.Jobs, warning);
                return(createMessageResult);
            }

            if (person.EmailPreference == EmailPreference.DoNotEmail)
            {
                var warning = $"{person.FullName} is marked as do not email.";
                createMessageResult.Warnings.Add(warning);
                RockLogger.Log.Warning(RockLogDomains.Jobs, warning);
                return(createMessageResult);
            }

            var recipients = new List <RockMessageRecipient>
            {
                new RockEmailMessageRecipient(person, mergeObjects)
            };

            var message = new RockEmailMessage(systemCommunication);

            message.SetRecipients(recipients);
            createMessageResult.Message = message;
            return(createMessageResult);
        }