Exemplo n.º 1
0
        public void SendMessageToDonor(int donorId, int donationDistributionId, int fromContactId, string body, string tripName)
        {
            var template            = _communicationService.GetTemplate(_donorMessageTemplateId);
            var defaultContactId    = AppSetting("DefaultGivingContactEmailId");
            var defaultContactEmail = _communicationService.GetEmailFromContactId(defaultContactId);

            var messageData = new Dictionary <string, object>
            {
                { "TripName", tripName },
                { "DonorMessage", body }
            };
            var toEmail = _donorService.GetEmailViaDonorId(donorId);

            var to = new List <MpContact>()
            {
                new MpContact()
                {
                    ContactId    = toEmail.ContactId,
                    EmailAddress = toEmail.Email
                }
            };

            var authorId  = _communicationService.GetUserIdFromContactId(fromContactId);
            var fromEmail = _communicationService.GetEmailFromContactId(fromContactId);

            var comm = new MpCommunication
            {
                AuthorUserId = authorId,
                DomainId     = 1,
                ToContacts   = to,
                FromContact  = new MpContact()
                {
                    ContactId = defaultContactId, EmailAddress = defaultContactEmail
                },
                ReplyToContact = new MpContact()
                {
                    ContactId = fromContactId, EmailAddress = fromEmail
                },
                EmailSubject = _communicationService.ParseTemplateBody(template.Subject, messageData),
                EmailBody    = _communicationService.ParseTemplateBody(template.Body, messageData),
                MergeData    = messageData
            };

            _communicationService.SendMessage(comm);

            //mark donation distribution with message sent

            var distributionData = new Dictionary <string, object>
            {
                { "Donation_Distribution_ID", donationDistributionId },
                { "Message_Sent", true }
            };

            _ministryPlatformService.UpdateRecord(_donationDistributionPageId, distributionData, ApiLogin());
        }