示例#1
0
        public void SendEmail(CommunicationDTO emailData)
        {
            var replyToContactId = emailData.ReplyToContactId ?? DefaultContactEmailId;

            var from = new MpContact {
                ContactId = DefaultContactEmailId, EmailAddress = _communicationService.GetEmailFromContactId(DefaultContactEmailId)
            };
            var replyTo = new MpContact {
                ContactId = replyToContactId, EmailAddress = _communicationService.GetEmailFromContactId(replyToContactId)
            };

            var comm = new MpCommunication
            {
                AuthorUserId   = DefaultAuthorUserId,
                DomainId       = DomainID,
                EmailBody      = emailData.Body,
                EmailSubject   = emailData.Subject,
                FromContact    = from,
                ReplyToContact = replyTo,
                MergeData      = new Dictionary <string, object>(),
                ToContacts     = new List <MpContact>()
            };

            foreach (var to in emailData.ToContactIds)
            {
                var contact = new MpContact {
                    ContactId = to, EmailAddress = _communicationService.GetEmailFromContactId(to)
                };
                comm.ToContacts.Add(contact);
            }
            _communicationService.SendMessage(comm);
        }
示例#2
0
        public void TestSendMessageWithoutDate()
        {
            MpCommunication comm = new MpCommunication()
            {
                AuthorUserId   = 1,
                DomainId       = 2,
                EmailBody      = "body",
                EmailSubject   = "subject",
                FromContact    = new MpContact(),
                MergeData      = new Dictionary <string, object>(),
                ReplyToContact = new MpContact(),
                TemplateId     = 123,
                ToContacts     = new List <MpContact>()
            };
            var spiedDict = new Dictionary <string, object>();

            _ministryPlatformService.Setup(mock => mock.CreateRecord(It.IsAny <int>(), It.IsAny <Dictionary <string, object> >(), It.IsAny <string>(), false))
            .Callback <int, Dictionary <string, object>, string, bool>((id, dict, token, bl) => spiedDict = dict);
            _ministryPlatformService.Setup(mock => mock.CreateSubRecord(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <Dictionary <string, object> >(), It.IsAny <string>(), false))
            .Returns(1);
            _fixture.SendMessage(comm);

            // Verify that the dictionary contains a Start_Date, that it is a DateTime,
            // and that is reasonably close to DateTime.Now
            Assert.IsTrue(spiedDict.ContainsKey("Start_Date"));
            Assert.IsInstanceOf <DateTime>(spiedDict["Start_Date"]);
            Assert.IsTrue(DateTime.Now.Subtract((DateTime)spiedDict["Start_Date"]).TotalSeconds < 30);
        }
示例#3
0
        private static MpCommunication FormatCommunication(int authorUserId,
                                                           int domainId,
                                                           MpMessageTemplate template,
                                                           MpMyContact fromContact,
                                                           MpMyContact replyToContact,
                                                           int participantContactId,
                                                           string participantEmail,
                                                           Dictionary <string, object> mergeData)
        {
            var communication = new MpCommunication
            {
                AuthorUserId = authorUserId,
                DomainId     = domainId,
                EmailBody    = template.Body,
                EmailSubject = template.Subject,
                FromContact  = new MpContact {
                    ContactId = fromContact.Contact_ID, EmailAddress = fromContact.Email_Address
                },
                ReplyToContact = new MpContact {
                    ContactId = replyToContact.Contact_ID, EmailAddress = replyToContact.Email_Address
                },
                ToContacts = new List <MpContact> {
                    new MpContact {
                        ContactId = participantContactId, EmailAddress = participantEmail
                    }
                },
                MergeData = mergeData
            };

            return(communication);
        }
示例#4
0
        public void SendParticipantsEmail(string token, List <GroupParticipantDTO> participants, string subject, string body)
        {
            var senderRecord = _participantService.GetParticipantRecord(token);

            var fromContact = new MpContact
            {
                ContactId    = 1519180,
                EmailAddress = "*****@*****.**"
            };

            var replyToContact = new MpContact
            {
                ContactId    = senderRecord.ContactId,
                EmailAddress = senderRecord.EmailAddress
            };

            var toContacts = participants.Select(p => new MpContact
            {
                ContactId    = p.ContactId,
                EmailAddress = p.Email
            }).ToList();

            var email = new MpCommunication
            {
                EmailBody      = body,
                EmailSubject   = subject,
                AuthorUserId   = 5,
                DomainId       = _domainId,
                FromContact    = fromContact,
                ReplyToContact = replyToContact,
                ToContacts     = toContacts
            };

            _communicationService.SendMessage(email);
        }
        public void ShouldSendTripEmail()
        {
            const int formResponseId   = 12345;
            const int contactId        = 1234;
            const int pledgeCampaignId = 9876;

            var mycontact = new MpMyContact
            {
                Contact_ID    = 7,
                Email_Address = "*****@*****.**"
            };


            var to = new MpContact
            {
                ContactId    = 8,
                EmailAddress = "*****@*****.**"
            };

            var tolist = new List <MpContact> {
                to
            };

            var mpc = new MpCommunication
            {
                AuthorUserId   = 1,
                DomainId       = 1,
                EmailBody      = "body",
                EmailSubject   = "subject",
                FromContact    = to,
                MergeData      = new Dictionary <string, object>(),
                ReplyToContact = to,
                StartDate      = new DateTime(2011, 10, 11),
                TemplateId     = 444,
                ToContacts     = tolist
            };

            _campaignService.Setup(m => m.GetPledgeCampaign(pledgeCampaignId)).Returns(mockPledgeCampaign());
            _donationService.Setup(m => m.GetMyTripDistributions(contactId)).Returns(MockTripScholarshipDonationsResponse());
            _formSubmissionService.Setup(f => f.SubmitFormResponse(It.IsAny <MpFormResponse>())).Returns(formResponseId);
            _communicationService.Setup(
                s =>
                s.GetTemplateAsCommunication(It.IsAny <int>(),
                                             It.IsAny <int>(),
                                             It.IsAny <string>(),
                                             It.IsAny <int>(),
                                             It.IsAny <string>(),
                                             It.IsAny <int>(),
                                             It.IsAny <string>(),
                                             It.IsAny <Dictionary <string, object> >())).Returns(mpc);

            _communicationService.Setup(s => s.SendMessage(mpc, false)).Returns(9999);
            _contactService.Setup(s => s.GetContactById(It.IsAny <int>())).Returns(mycontact);

            var result = _fixture.SaveApplication(mockTripApplication(contactId, pledgeCampaignId));

            Assert.IsTrue(result == formResponseId);

            _configurationWrapper.Verify(v => v.GetConfigIntValue("TripApplicantSuccessTemplate"), Times.Exactly(1));
        }
示例#6
0
        private void SendChildcareRequestDecisionNotification(int requestId, List <MpChildcareRequestDate> childcareRequestDates, ChildcareRequestDto childcareRequest, int templateId, String token)
        {
            var childcareRequestEmail = _childcareRequestService.GetChildcareRequest(requestId, token);;
            var template = _communicationService.GetTemplate(templateId);

            var decisionNotes = childcareRequest.DecisionNotes ?? "N/A";


            var authorUserId = _configurationWrapper.GetConfigIntValue("DefaultUserAuthorId");
            var datesList    = childcareRequestDates.Select(dateRec => dateRec.RequestDate).Select(requestDate => BuildParagraph("", requestDate.ToShortDateString())).ToList();
            var styles       = Styles();
            var htmlCell     = new HtmlElement("td", styles).Append(datesList);
            var htmlRow      = new HtmlElement("tr", styles).Append(htmlCell);
            var htmlTBody    = new HtmlElement("tbody", styles).Append(htmlRow);
            var htmlTable    = new HtmlElement("table", styles).Append(htmlTBody);

            var mergeData = new Dictionary <string, object>
            {
                { "Group", childcareRequestEmail.GroupName },
                { "ChildcareSession", childcareRequestEmail.ChildcareSession },
                { "DecisionNotes", decisionNotes },
                { "Frequency", childcareRequest.Frequency },
                { "Dates", htmlTable.Build() },
                { "RequestId", childcareRequestEmail.RequestId },
                { "Base_Url", _configurationWrapper.GetConfigValue("BaseMPUrl") },
                { "Congregation", childcareRequestEmail.CongregationName }
            };
            var toContactsList = new List <MpContact> {
                new MpContact {
                    ContactId = childcareRequestEmail.RequesterId, EmailAddress = childcareRequestEmail.RequesterEmail
                }
            };


            var communication = new MpCommunication
            {
                AuthorUserId = authorUserId,
                EmailBody    = template.Body,
                EmailSubject = template.Subject,
                FromContact  = new MpContact {
                    ContactId = childcareRequestEmail.ChildcareContactId, EmailAddress = childcareRequestEmail.ChildcareContactEmail
                },
                ReplyToContact = new MpContact {
                    ContactId = childcareRequestEmail.ChildcareContactId, EmailAddress = childcareRequestEmail.ChildcareContactEmail
                },
                ToContacts = toContactsList,
                MergeData  = mergeData
            };

            try
            {
                _communicationService.SendMessage(communication);
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Send Childcare request approval notification email failed"), ex);
            }
        }
示例#7
0
        /// <summary>
        /// Creates the correct record in MP so that the mail service can pick it up and send
        /// it during the scheduled run
        /// </summary>
        /// <param name="communication">The message properties </param>
        /// <param name="isDraft"> Is this message a draft? Defaults to false </param>
        public int SendMessage(MpCommunication communication, bool isDraft = false)
        {
            var token = ApiLogin();
            var communicationStatus = isDraft ? _communicationDraftStatus : _communicationStatusId;
            var communicationId     = AddCommunication(communication, token, communicationStatus);

            AddCommunicationMessages(communication, communicationId, token);
            return(communicationId);
        }
        public void SendAllGroupLeadersEmail(string token, int groupId, GroupMessageDTO message)
        {
            var requestor        = _participantRepository.GetParticipantRecord(token);
            var requestorContact = _contactRepository.GetContactById(requestor.ContactId);
            var group            = _groupService.GetGroupDetails(groupId);

            var fromContact = new MpContact
            {
                ContactId    = _defaultGroupContactEmailId,
                EmailAddress = "*****@*****.**"
            };

            var replyToContact = new MpContact
            {
                ContactId    = requestor.ContactId,
                EmailAddress = requestor.EmailAddress
            };

            var leaders = @group.Participants.
                          Where(groupParticipant => groupParticipant.GroupRoleId == _groupRoleLeaderId).
                          Select(groupParticipant => new MpContact
            {
                ContactId    = groupParticipant.ContactId,
                EmailAddress = groupParticipant.Email,
                LastName     = groupParticipant.LastName,
                Nickname     = groupParticipant.NickName
            }).ToList();

            var fromString = "<p><i>This email was sent from: " + requestorContact.Nickname + " " + requestorContact.Last_Name + " (" + requestor.EmailAddress + ")</i></p>";

            var toString = "<p><i>This email was sent to: ";

            foreach (var item in leaders)
            {
                toString += item.Nickname + " " + item.LastName + " (" + item.EmailAddress + "), ";
            }

            char[] trailingChars = { ',', ' ' };
            toString  = toString.TrimEnd(trailingChars);
            toString += "</i></p>";

            var email = new MpCommunication
            {
                EmailBody      = fromString + "<p>" + message.Body + "</p>" + toString,
                EmailSubject   = $"Crossroads Group {@group.GroupName}: {message.Subject}",
                AuthorUserId   = _defaultAuthorUserId,
                DomainId       = _domainId,
                FromContact    = fromContact,
                ReplyToContact = replyToContact,
                ToContacts     = leaders
            };

            _communicationRepository.SendMessage(email);
        }
示例#9
0
        public void SendChildcareCancellationNotification()
        {
            var templateId   = _configurationWrapper.GetConfigIntValue("ChildcareCancelledTemplate");
            var template     = _communicationService.GetTemplate(templateId);
            var authorUserId = _configurationWrapper.GetConfigIntValue("DefaultUserAuthorId");

            var notificationData = _childcareRepository.GetChildcareCancellations();

            foreach (var participant in notificationData.DistinctBy(p => p.EnrollerContactId))
            {
                var kiddos    = notificationData.Where(k => k.EnrollerContactId == participant.EnrollerContactId).Aggregate("", (current, kid) => current + (kid.ChildNickname + " " + kid.ChildLastname + "<br>"));
                var mergeData = new Dictionary <string, object>
                {
                    { "Group_Name", participant.EnrollerGroupName },
                    { "Childcare_Date", participant.ChildcareEventDate.ToString("MM/dd/yyyy") },
                    { "Group_Member_Nickname", participant.EnrollerNickname },
                    { "Childcare_Day", participant.ChildcareEventDate.ToString("dddd, MMMM dd") },
                    { "Child_List", kiddos }
                };
                var comm = new MpCommunication
                {
                    AuthorUserId = authorUserId,
                    DomainId     = 1,
                    EmailBody    = template.Body,
                    EmailSubject = template.Subject,
                    FromContact  = new MpContact {
                        ContactId = participant.ChildcareContactId, EmailAddress = participant.ChildcareContactEmail
                    },
                    ReplyToContact = new MpContact {
                        ContactId = participant.ChildcareContactId, EmailAddress = participant.ChildcareContactEmail
                    },
                    ToContacts = new List <MpContact> {
                        new MpContact {
                            ContactId = participant.EnrollerContactId, EmailAddress = participant.EnrollerEmail
                        }
                    },
                    MergeData = mergeData
                };
                _communicationService.SendMessage(comm);
            }

            foreach (var participant in notificationData)
            {
                _groupService.endDateGroupParticipant(participant.ChildGroupId, participant.ChildGroupParticipantId);
            }

            foreach (var group in notificationData.DistinctBy(g => g.ChildGroupId))
            {
                _groupService.EndDateGroup(group.ChildGroupId);
            }
        }
示例#10
0
        public void SendChildcareRequestNotification(MpChildcareRequestEmail request)
        {
            var templateId   = _configurationWrapper.GetConfigIntValue("ChildcareRequestNotificationTemplate");
            var authorUserId = _configurationWrapper.GetConfigIntValue("DefaultUserAuthorId");
            var template     = _communicationService.GetTemplate(templateId);

            var mergeData = new Dictionary <string, object>
            {
                { "Requester", request.Requester },
                { "Nickname", request.RequesterNickname },
                { "LastName", request.RequesterLastName },
                { "Group", request.GroupName },
                { "Site", request.CongregationName },
                { "StartDate", (request.StartDate).ToShortDateString() },
                { "EndDate", (request.EndDate).ToShortDateString() },
                { "ChildcareSession", request.ChildcareSession },
                { "RequestId", request.RequestId },
                { "Base_Url", _configurationWrapper.GetConfigValue("BaseMPUrl") }
            };

            var communication = new MpCommunication
            {
                AuthorUserId = authorUserId,
                EmailBody    = template.Body,
                EmailSubject = template.Subject,
                FromContact  = new MpContact {
                    ContactId = request.RequesterId, EmailAddress = request.RequesterEmail
                },
                ReplyToContact = new MpContact {
                    ContactId = request.RequesterId, EmailAddress = request.RequesterEmail
                },
                ToContacts = new List <MpContact> {
                    new MpContact {
                        ContactId = request.ChildcareContactId, EmailAddress = request.ChildcareContactEmail
                    }
                },
                MergeData = mergeData
            };

            try
            {
                _communicationService.SendMessage(communication);
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Send Childcare request notification email failed"), ex);
            }
        }
        public void ShouldGetReminderCommunication()
        {
            const int childcareTemplateId = 56345;
            var       threeDaysOut        = DateTime.Now.AddDays(3);
            var       email1 = new MpContact()
            {
                EmailAddress = "*****@*****.**", ContactId = 2186211
            };
            var mergeData = new Dictionary <string, object>()
            {
                { "Nickname", "Matt" },
                { "Childcare_Date", threeDaysOut.ToString("d") },
                { "Childcare_Day", threeDaysOut.ToString("dddd M") }
            };

            _configurationWrapper.Setup(m => m.GetConfigIntValue("DefaultContactEmailId")).Returns(12);
            _configurationWrapper.Setup(m => m.GetConfigIntValue("ChildcareReminderTemplateId")).Returns(childcareTemplateId);

            var expectedCommunication = new MpCommunication()
            {
                AuthorUserId = 5,
                DomainId     = 1,
                EmailBody    = "<html> whatever </html>",
                EmailSubject = "subject",
                FromContact  = new MpContact()
                {
                    ContactId = 12, EmailAddress = "*****@*****.**"
                },
                ReplyToContact = new MpContact()
                {
                    ContactId = 12, EmailAddress = "*****@*****.**"
                },
                TemplateId = childcareTemplateId,
                ToContacts = new List <MpContact> {
                    email1
                },
                MergeData = mergeData
            };

            _communicationService.Setup(
                m => m.GetTemplateAsCommunication(childcareTemplateId, 12, "*****@*****.**", 12, "*****@*****.**", email1.ContactId, email1.EmailAddress, mergeData)
                ).Returns(expectedCommunication);

            _fixture.SetupChilcareReminderCommunication(email1, mergeData);

            _communicationService.Verify();
            _configurationWrapper.VerifyAll();
        }
示例#12
0
        public void SendNewStudentMinistryGroupAlertEmail(List <MpGroupParticipant> leaders)
        {
            var          emailTemplate = _communicationService.GetTemplate(NewStudentMinistryGroupAlertEmailTemplate);
            const string toEmail       = "*****@*****.**";

            string formattedData = "<ul> ";

            foreach (var participant in leaders)
            {
                formattedData += $"<li>Name: {participant.NickName} {participant.LastName}  Email: {participant.Email} </li>";
            }

            var mergeData = new Dictionary <string, object>
            {
                { "Leaders", formattedData + "</ul>" }
            };

            var domainId = Convert.ToInt32(AppSettings("DomainId"));
            var from     = new MpContact()
            {
                ContactId    = DefaultEmailContactId,
                EmailAddress = _communicationService.GetEmailFromContactId(DefaultEmailContactId)
            };

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

            var newStudentMinistryGroup = new MpCommunication
            {
                EmailBody      = emailTemplate.Body,
                EmailSubject   = emailTemplate.Subject,
                AuthorUserId   = 5,
                DomainId       = domainId,
                FromContact    = from,
                MergeData      = mergeData,
                ReplyToContact = from,
                TemplateId     = NewStudentMinistryGroupAlertEmailTemplate,
                ToContacts     = to
            };

            _communicationService.SendMessage(newStudentMinistryGroup);
        }
示例#13
0
        public void SendCommunityGroupConfirmationEmail(int participantId, int groupId, bool waitlist, bool childcareNeeded)
        {
            var emailTemplate = _communicationService.GetTemplate(waitlist ? CommunityGroupWaitListConfirmationTemplateId : CommunityGroupConfirmationTemplateId);
            var toContact     = _contactService.GetContactIdByParticipantId(participantId);
            var toContactInfo = _contactService.GetContactById(toContact);
            var groupInfo     = getGroupDetails(groupId);

            var mergeData = new Dictionary <string, object>
            {
                { "Nickname", toContactInfo.Nickname },
                { "Group_Name", groupInfo.Name },
                { "Congregation_Name", groupInfo.Congregation },
                { "Childcare_Needed", (childcareNeeded) ? _contentBlockService["communityGroupChildcare"].Content : "" },
                { "Base_Url", _configurationWrapper.GetConfigValue("BaseUrl") }
            };

            var domainId = Convert.ToInt32(AppSettings("DomainId"));
            var from     = new MpContact()
            {
                ContactId    = DefaultEmailContactId,
                EmailAddress = _communicationService.GetEmailFromContactId(DefaultEmailContactId)
            };

            var to = new List <MpContact>
            {
                new MpContact
                {
                    ContactId    = toContact,
                    EmailAddress = toContactInfo.Email_Address
                }
            };

            var confirmation = new MpCommunication
            {
                EmailBody      = emailTemplate.Body,
                EmailSubject   = emailTemplate.Subject,
                AuthorUserId   = 5,
                DomainId       = domainId,
                FromContact    = from,
                MergeData      = mergeData,
                ReplyToContact = from,
                TemplateId     = CommunityGroupConfirmationTemplateId,
                ToContacts     = to
            };

            _communicationService.SendMessage(confirmation);
        }
示例#14
0
        public void SendAllGroupParticipantsEmail(string token, int groupId, int groupTypeId, string subject, string body)
        {
            var leaderRecord = _participantRepository.GetParticipantRecord(token);
            var groups       = _groupService.GetGroupByIdForAuthenticatedUser(token, groupId);

            if (groups == null || !groups.Any())
            {
                throw new GroupNotFoundForParticipantException($"Could not find group {groupId} for groupParticipant {leaderRecord.ParticipantId}");
            }

            if (!ValidateUserAsLeader(token, groupTypeId, groupId, leaderRecord.ParticipantId, groups.First()))
            {
                throw new NotGroupLeaderException($"Group participant ID {leaderRecord.ParticipantId} is not a leader of group {groupId}");
            }

            var fromContact = new MpContact
            {
                ContactId    = 1519180,
                EmailAddress = "*****@*****.**"
            };

            var replyToContact = new MpContact
            {
                ContactId    = leaderRecord.ContactId,
                EmailAddress = leaderRecord.EmailAddress
            };

            var toContacts = groups.First().Participants.Select(groupParticipant => new MpContact
            {
                ContactId    = groupParticipant.ContactId,
                EmailAddress = groupParticipant.Email
            }).DistinctBy(c => c.EmailAddress).ToList();

            var email = new MpCommunication
            {
                EmailBody      = body,
                EmailSubject   = subject,
                AuthorUserId   = 5,
                DomainId       = _domainId,
                FromContact    = fromContact,
                ReplyToContact = replyToContact,
                ToContacts     = toContacts
            };

            _communicationRepository.SendMessage(email);
        }
示例#15
0
        public void SendEmail(EmailCommunicationDTO email, string token)
        {
            var template = _communicationService.GetTemplate(email.TemplateId);

            if (token == null && email.FromUserId == null && template.FromContactId == 0)
            {
                throw (new InvalidOperationException("Must provide either email.FromUserId from  or an authentication token."));
            }

            var replyToContactId = email.ReplyToContactId ?? template.ReplyToContactId;
            var replyTo          = new MpContact {
                ContactId = replyToContactId, EmailAddress = _communicationService.GetEmailFromContactId(replyToContactId)
            };

            var fromContactId = email.FromContactId ?? template.FromContactId;
            var from          = new MpContact {
                ContactId = fromContactId, EmailAddress = _communicationService.GetEmailFromContactId(fromContactId)
            };

            MpContact to = GetMpContactFromEmailCommunicationDto(email);

            var communication = new MpCommunication
            {
                DomainId       = DomainID,
                AuthorUserId   = email.FromUserId ?? DefaultAuthorUserId,
                TemplateId     = email.TemplateId,
                EmailBody      = template.Body,
                EmailSubject   = template.Subject,
                ReplyToContact = replyTo,
                FromContact    = from,
                StartDate      = email.StartDate ?? DateTime.Now,
                MergeData      = email.MergeData,
                ToContacts     = new List <MpContact>()
            };

            communication.ToContacts.Add(to);

            if (!communication.MergeData.ContainsKey("BaseUrl"))
            {
                communication.MergeData.Add("BaseUrl", _configurationWrapper.GetConfigValue("BaseUrl"));
            }

            _communicationService.SendMessage(communication);
        }
示例#16
0
        public void TestSendEmailWithContactId()
        {
            EmailCommunicationDTO emailData = new EmailCommunicationDTO
            {
                TemplateId  = 264567,
                MergeData   = new Dictionary <string, object>(),
                ToContactId = 10,
                StartDate   = DateTime.Now
            };

            MpMessageTemplate template = new MpMessageTemplate()
            {
                Body                = "body",
                Subject             = "subject",
                FromContactId       = 5,
                FromEmailAddress    = "*****@*****.**",
                ReplyToContactId    = 5,
                ReplyToEmailAddress = "[email protected]."
            };

            MpContact expectedContact = new MpContact()
            {
                ContactId    = emailData.ToContactId.Value,
                EmailAddress = "*****@*****.**"
            };

            _communicationService.Setup(mocked => mocked.GetTemplate(emailData.TemplateId)).Returns(template);
            _communicationService.Setup(mocked => mocked.GetEmailFromContactId(template.ReplyToContactId)).Returns(template.ReplyToEmailAddress);
            _communicationService.Setup(mocked => mocked.GetEmailFromContactId(emailData.ToContactId.Value)).Returns("*****@*****.**");
            _communicationService.Setup(mocked => mocked.GetEmailFromContactId(template.FromContactId)).Returns(template.FromEmailAddress);
            _communicationService.Setup(mocked => mocked.GetTemplate(emailData.TemplateId)).Returns(template);
            _contactService.Setup(mocked => mocked.GetContactIdByEmail(emailData.emailAddress)).Returns(0);

            var spiedComm = new MpCommunication();

            _communicationService.Setup(m => m.SendMessage(It.IsAny <MpCommunication>(), false))
            .Callback <MpCommunication, bool>((comm, token) => spiedComm = comm);


            fixture.SendEmail(emailData, null);
            _communicationService.Verify(m => m.SendMessage(It.IsAny <MpCommunication>(), false), Times.Once);
            Assert.AreEqual(JsonConvert.SerializeObject(expectedContact), JsonConvert.SerializeObject(spiedComm.ToContacts[0]));
        }
示例#17
0
        private int AddCommunication(MpCommunication communication, string token, int communicationStatus)
        {
            if (communication.StartDate == default(DateTime))
            {
                communication.StartDate = DateTime.Now;
            }

            var dictionary = new Dictionary <string, object>
            {
                { "Subject", communication.EmailSubject },
                { "Body", communication.EmailBody },
                { "Author_User_Id", communication.AuthorUserId },
                { "Start_Date", communication.StartDate },
                { "From_Contact", communication.FromContact.ContactId },
                { "Reply_to_Contact", communication.ReplyToContact.ContactId },
                { "Communication_Status_ID", communicationStatus }
            };
            var communicationId = _ministryPlatformService.CreateRecord(_messagePageId, dictionary, token);

            return(communicationId);
        }
示例#18
0
 private void AddCommunicationMessages(MpCommunication communication, int communicationId, string token)
 {
     foreach (MpContact contact in communication.ToContacts)
     {
         var dictionary = new Dictionary <string, object>
         {
             { "Action_Status_ID", _actionStatusId },
             { "Action_Status_Time", DateTime.Now },
             { "Contact_ID", contact.ContactId },
             { "From", communication.FromContact.EmailAddress },
             { "To", contact.EmailAddress },
             { "Reply_To", communication.ReplyToContact.EmailAddress },
             { "Subject", ParseTemplateBody(communication.EmailSubject, communication.MergeData) },
             { "Body", ParseTemplateBody(communication.EmailBody, communication.MergeData) }
         };
         if (contact.EmailAddress != "" && contact.EmailAddress != null)
         {
             _ministryPlatformService.CreateSubRecord(_recipientsSubPageId, communicationId, dictionary, token);
         }
     }
 }
示例#19
0
        /// <summary>
        /// Sends a participant and email based off of a template ID and any merge data you need for that template.
        /// </summary>
        /// <param name="participant"></param>
        /// <param name="templateId"></param>
        /// <param name="mergeData"></param>
        public int SendSingleGroupParticipantEmail(GroupParticipantDTO participant, int templateId, Dictionary <string, object> mergeData)
        {
            var emailTemplate = _communicationRepository.GetTemplate(templateId);

            var domainId = Convert.ToInt32(_domainId);
            var from     = new MpContact
            {
                ContactId    = emailTemplate.FromContactId,
                EmailAddress = emailTemplate.FromEmailAddress
            };

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

            var message = new MpCommunication
            {
                EmailBody      = emailTemplate.Body,
                EmailSubject   = emailTemplate.Subject,
                AuthorUserId   = 5,
                DomainId       = domainId,
                FromContact    = from,
                MergeData      = mergeData,
                ReplyToContact = from,
                TemplateId     = templateId,
                ToContacts     = to,
                StartDate      = DateTime.Now
            };

            // ReSharper disable once RedundantArgumentDefaultValue
            return(_communicationRepository.SendMessage(message, false));
        }
示例#20
0
        public void TestSendMessageWithDate()
        {
            MpCommunication comm = new MpCommunication()
            {
                AuthorUserId   = 1,
                DomainId       = 2,
                EmailBody      = "body",
                EmailSubject   = "subject",
                FromContact    = new MpContact(),
                MergeData      = new Dictionary <string, object>(),
                ReplyToContact = new MpContact(),
                StartDate      = new DateTime(2017, 1, 1),
                TemplateId     = 123,
                ToContacts     = new List <MpContact>()
            };
            var spiedDict = new Dictionary <string, object>();

            _ministryPlatformService.Setup(mock => mock.CreateRecord(It.IsAny <int>(), It.IsAny <Dictionary <string, object> >(), It.IsAny <string>(), false))
            .Callback <int, Dictionary <string, object>, string, bool>((id, dict, token, bl) => spiedDict = dict);
            _ministryPlatformService.Setup(mock => mock.CreateSubRecord(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <Dictionary <string, object> >(), It.IsAny <string>(), false))
            .Returns(1);
            _fixture.SendMessage(comm);
            Assert.AreEqual(comm.StartDate, spiedDict["Start_Date"]);
        }
示例#21
0
        private void SendEmail(MpInvitation invitation, MpParticipant leader, MpGroup group)
        {
            var leaderContact = _contactRepository.GetContactById(leader.ContactId);

            // basic merge data here
            var mergeData = new Dictionary <string, object>
            {
                { "Invitation_GUID", invitation.InvitationGuid },
                { "Recipient_Name", invitation.RecipientName },
            };

            int emailTemplateId;

            if (invitation.InvitationType == _groupInvitationType)
            {
                if (invitation.CustomMessage != null)
                {
                    emailTemplateId = _groupInvitationEmailTemplateCustom;
                    mergeData.Add("Leader_Message", invitation.CustomMessage);
                }
                else
                {
                    emailTemplateId = _groupInvitationEmailTemplate;
                }
                mergeData.Add("Leader_Name", leaderContact.Nickname + " " + leaderContact.Last_Name);
                mergeData.Add("Group_Name", group.Name);
            }
            else if (invitation.InvitationType == _tripInvitationType)
            {
                emailTemplateId = _tripInvitationEmailTemplate;
            }
            else if (invitation.InvitationType == _anywhereGatheringInvitationTypeId)
            {
                mergeData["Recipient_Name"] = invitation.RecipientName.Substring(0, 1).ToUpper() + invitation.RecipientName.Substring(1).ToLower();
                mergeData.Add("Leader_Name", leaderContact.Nickname.Substring(0, 1).ToUpper() + leaderContact.Nickname.Substring(1).ToLower() + " " + leaderContact.Last_Name.Substring(0, 1).ToUpper() + ".");
                mergeData.Add("City", group.Address.City);
                mergeData.Add("State", group.Address.State);
                mergeData.Add("Description", group.GroupDescription);
                mergeData.Add("Group_ID", group.GroupId);
                emailTemplateId = _anywhereGatheringInvitationEmailTemplate;
            }
            else
            {
                emailTemplateId = _defaultInvitationEmailTemplate;
            }
            var emailTemplate = _communicationService.GetTemplate(emailTemplateId);
            var fromContact   = new MpContact
            {
                ContactId    = emailTemplate.FromContactId,
                EmailAddress = emailTemplate.FromEmailAddress
            };
            var replyTo = new MpContact
            {
                ContactId    = leader.ContactId,
                EmailAddress = leader.EmailAddress
            };

            var to = new List <MpContact>
            {
                new MpContact
                {
                    // Just need a contact ID here, doesn't have to be for the recipient
                    ContactId    = emailTemplate.FromContactId,
                    EmailAddress = invitation.EmailAddress
                }
            };



            var confirmation = new MpCommunication
            {
                EmailBody      = emailTemplate.Body,
                EmailSubject   = emailTemplate.Subject,
                AuthorUserId   = 5,
                DomainId       = _domainId,
                FromContact    = fromContact,
                ReplyToContact = replyTo,
                TemplateId     = emailTemplateId,
                ToContacts     = to,
                MergeData      = mergeData
            };

            _communicationService.SendMessage(confirmation);
        }
示例#22
0
        public void SendGroupParticipantEmail(int groupId,
                                              GroupDTO group,
                                              int emailTemplateId,
                                              MpParticipant toParticipant,
                                              string subjectTemplateContentBlockTitle = null,
                                              string emailTemplateContentBlockTitle   = null,
                                              string message = null,
                                              MpParticipant fromParticipant = null)
        {
            var participant = new GroupParticipantDTO
            {
                ContactId     = toParticipant.ContactId,
                Email         = toParticipant.EmailAddress,
                NickName      = toParticipant.PreferredName,
                ParticipantId = toParticipant.ParticipantId
            };

            var emailTemplate = _communicationRepository.GetTemplate(emailTemplateId);

            var fromContact = new MpContact
            {
                ContactId    = emailTemplate.FromContactId,
                EmailAddress = emailTemplate.FromEmailAddress
            };

            var replyTo = new MpContact
            {
                ContactId    = fromParticipant?.ContactId ?? emailTemplate.ReplyToContactId,
                EmailAddress = fromParticipant == null ? emailTemplate.ReplyToEmailAddress : fromParticipant.EmailAddress
            };

            var leader = _contactRepository.GetContactById(replyTo.ContactId);

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

            var subjectTemplateText = string.IsNullOrWhiteSpace(subjectTemplateContentBlockTitle)
                ? string.Empty
                : _contentBlockService[subjectTemplateContentBlockTitle].Content ?? string.Empty;

            var emailTemplateText = string.IsNullOrWhiteSpace(emailTemplateContentBlockTitle) ? string.Empty : _contentBlockService[emailTemplateContentBlockTitle].Content;

            var mergeData = getDictionary(participant);

            mergeData["Email_Custom_Message"] = string.IsNullOrWhiteSpace(message) ? string.Empty : message;
            mergeData["Group_Name"]           = group.GroupName;
            mergeData["Group_Description"]    = group.GroupDescription;
            mergeData["Leader_Name"]          = leader.Nickname != null && leader.Last_Name != null ? leader.Nickname + " " + leader.Last_Name : replyTo.EmailAddress;
            mergeData["City"]  = group.Address.City;
            mergeData["State"] = group.Address.State;
            if (fromParticipant != null)
            {
                mergeData["From_Display_Name"]   = fromParticipant.DisplayName;
                mergeData["From_Preferred_Name"] = fromParticipant.PreferredName;
            }

            // Since the templates are coming from content blocks, they may have replacement tokens in them as well.
            // These will not get replaced with merge data in _communicationRepository.SendMessage(), (it doesn't doubly
            // replace) so we'll parse them here before adding them to the merge data.
            mergeData["Subject_Template_Text"] = _communicationRepository.ParseTemplateBody(Regex.Replace(subjectTemplateText, "<.*?>", string.Empty), mergeData);
            mergeData["Email_Template_Text"]   = _communicationRepository.ParseTemplateBody(emailTemplateText, mergeData);

            var email = new MpCommunication
            {
                EmailBody      = emailTemplate.Body,
                EmailSubject   = emailTemplate.Subject,
                AuthorUserId   = _emailAuthorId,
                DomainId       = _domainId,
                FromContact    = fromContact,
                ReplyToContact = replyTo,
                TemplateId     = emailTemplateId,
                ToContacts     = to,
                MergeData      = mergeData
            };

            _communicationRepository.SendMessage(email);
        }
        public void ShouldSendChildcareRequestNotification()
        {
            var startDate = new DateTime(2016, 5, 26);
            var endDate   = new DateTime(2016, 7, 2);

            var notificationTemplateId = 0985627;
            var defaultAuthorId        = 9087345;

            var template = new MpMessageTemplate()
            {
                Body    = "Ok long string of text",
                Subject = "A subject"
            };

            var request = new MpChildcareRequestEmail()
            {
                RequestId             = 1,
                RequesterEmail        = "*****@*****.**",
                ChildcareContactEmail = "*****@*****.**",
                ChildcareContactId    = 12,
                ChildcareSession      = "Monday, 9am - 12pm",
                CongregationName      = "Florence",
                EndDate           = endDate,
                StartDate         = startDate,
                EstimatedChildren = 2,
                Frequency         = "once",
                RequesterLastName = "Nair",
                RequesterNickname = "Lak",
                Requester         = "Nair, Lak",
                RequesterId       = 432,
                GroupName         = "FI 101"
            };

            var mergeData = new Dictionary <string, object>
            {
                { "Requester", request.Requester },
                { "Nickname", request.RequesterNickname },
                { "LastName", request.RequesterLastName },
                { "Group", request.GroupName },
                { "Site", request.CongregationName },
                { "StartDate", (request.StartDate).ToShortDateString() },
                { "EndDate", (request.EndDate).ToShortDateString() },
                { "ChildcareSession", request.ChildcareSession },
                { "RequestId", request.RequestId },
                { "Base_Url", "https://localhost:3000" }
            };

            var communication = new MpCommunication
            {
                TemplateId   = 0,
                DomainId     = 0,
                AuthorUserId = defaultAuthorId,
                EmailBody    = template.Body,
                EmailSubject = template.Subject,
                FromContact  = new MpContact {
                    ContactId = request.RequesterId, EmailAddress = request.RequesterEmail
                },
                ReplyToContact = new MpContact {
                    ContactId = request.RequesterId, EmailAddress = request.RequesterEmail
                },
                ToContacts = new List <MpContact> {
                    new MpContact {
                        ContactId = request.ChildcareContactId, EmailAddress = request.ChildcareContactEmail
                    }
                },
                MergeData = mergeData
            };

            _configurationWrapper.Setup(m => m.GetConfigIntValue("ChildcareRequestNotificationTemplate")).Returns(notificationTemplateId);
            _configurationWrapper.Setup(m => m.GetConfigIntValue("DefaultUserAuthorId")).Returns(defaultAuthorId);
            _communicationService.Setup(m => m.GetTemplate(notificationTemplateId)).Returns(template);
            _configurationWrapper.Setup(m => m.GetConfigValue("BaseMPUrl")).Returns("https://localhost:3000");
            _communicationService.Setup(m => m.SendMessage(It.IsAny <MpCommunication>(), false)).Verifiable();

            _fixture.SendChildcareRequestNotification(request);


            _communicationService.VerifyAll();
        }
        public void ShouldSendPrimaryContactReminderEmails()
        {
            const string search         = "";
            const string apiToken       = "qwerty1234";
            var          defaultContact = new MpMyContact()
            {
                Contact_ID    = 321,
                Email_Address = "*****@*****.**"
            };

            var testEvent = new MpEvent()
            {
                EventId        = 32,
                EventStartDate = new DateTime(),
                EventEndDate   = new DateTime().AddHours(2),
                PrimaryContact = new MpContact()
                {
                    EmailAddress = "*****@*****.**",
                    ContactId    = 4321
                }
            };

            var testEventList = new List <MpEvent>()
            {
                testEvent
            };

            _apiUserService.Setup(m => m.GetToken()).Returns(apiToken);
            _eventService.Setup(m => m.EventsByPageViewId(apiToken, 2205, search)).Returns(testEventList);
            var eventList = testEventList.Select(evt => new crds_angular.Models.Crossroads.Events.Event()
            {
                name      = evt.EventTitle,
                EventId   = evt.EventId,
                EndDate   = evt.EventEndDate,
                StartDate = evt.EventStartDate,
                EventType = evt.EventType,
                location  = evt.Congregation,
                PrimaryContactEmailAddress = evt.PrimaryContact.EmailAddress,
                PrimaryContactId           = evt.PrimaryContact.ContactId
            });

            eventList.ForEach(evt =>
            {
                var mergeData = new Dictionary <string, object>
                {
                    { "Event_ID", evt.EventId },
                    { "Event_Title", evt.name },
                    { "Event_Start_Date", evt.StartDate.ToShortDateString() },
                    { "Event_Start_Time", evt.StartDate.ToShortTimeString() }
                };

                var contact = new MpContact()
                {
                    ContactId = defaultContact.Contact_ID, EmailAddress = defaultContact.Email_Address
                };
                var fakeCommunication = new MpCommunication()
                {
                    AuthorUserId   = defaultContact.Contact_ID,
                    DomainId       = 1,
                    EmailBody      = "Test event email stuff",
                    EmailSubject   = "Test Event Reminder",
                    FromContact    = contact,
                    MergeData      = mergeData,
                    ReplyToContact = contact,
                    TemplateId     = 14909,
                    ToContacts     = new List <MpContact>()
                    {
                        contact
                    }
                };

                var testContact = new MpMyContact()
                {
                    Contact_ID    = 9876,
                    Email_Address = "*****@*****.**"
                };

                _contactService.Setup(m => m.GetContactById(9876)).Returns(testContact);
                _communicationService.Setup(m => m.GetTemplateAsCommunication(14909,
                                                                              testContact.Contact_ID,
                                                                              testContact.Email_Address,
                                                                              evt.PrimaryContactId,
                                                                              evt.PrimaryContactEmailAddress,
                                                                              evt.PrimaryContactId,
                                                                              evt.PrimaryContactEmailAddress,
                                                                              mergeData)).Returns(fakeCommunication);
                _communicationService.Setup(m => m.SendMessage(fakeCommunication, false));
                _communicationService.Verify();
            });
            _fixture.EventsReadyForPrimaryContactReminder(apiToken);
            _eventService.Verify();
        }
示例#25
0
        public void ShouldSendTripFullConfirmation()
        {
            const int    pledgeCampaignId = 09786834;
            const string token            = "asdfasdf";
            const int    templateId       = 7878;

            var campaign = mockPledgeCampaign(pledgeCampaignId);

            var pledges = mockPledges(campaign);

            pledges.Add(
                new MpPledge()
            {
                CampaignName      = campaign.Name,
                CampaignStartDate = campaign.StartDate,
                CampaignEndDate   = campaign.EndDate,
                CampaignTypeId    = 1,
                CampaignTypeName  = campaign.Type,
                DonorId           = 3,
                PledgeCampaignId  = campaign.Id,
                PledgeDonations   = 1,
                PledgeId          = 4,
                PledgeStatus      = "active",
                PledgeStatusId    = 1,
                PledgeTotal       = 100
            }
                );

            var mergeData = new Dictionary <string, object>
            {
                { "Pledge_Campaign", campaign.Name }
            };

            var communication = new MpCommunication()
            {
                TemplateId   = templateId,
                AuthorUserId = 1,
                DomainId     = 1,
                EmailBody    = "<p> Ok random body of text </p>",
                EmailSubject = "more randomness",
                FromContact  = new MpContact()
                {
                    ContactId = 5, EmailAddress = "*****@*****.**"
                },
                MergeData      = mergeData,
                ReplyToContact = new MpContact {
                    ContactId = 5, EmailAddress = "*****@*****.**"
                },
                StartDate  = DateTime.Now,
                ToContacts = new List <MpContact> {
                    new MpContact {
                        ContactId = 45, EmailAddress = "*****@*****.**"
                    }
                }
            };

            var eventDetails = EventDetails(campaign.EventId);

            _apiUserReposity.Setup(m => m.GetToken()).Returns(token);
            _campaignService.Setup(m => m.GetPledgeCampaign(pledgeCampaignId, token)).Returns(campaign);
            _pledgeService.Setup(m => m.GetPledgesByCampaign(pledgeCampaignId, token)).Returns(pledges);

            _configurationWrapper.Setup(m => m.GetConfigIntValue("TripIsFullTemplateId")).Returns(templateId);
            _configurationWrapper.Setup(m => m.GetConfigIntValue("TripIsFullFromContactId")).Returns(5);
            _configurationWrapper.Setup(m => m.GetConfigValue("TripIsFullFromEmailAddress")).Returns("*****@*****.**");

            _eventService.Setup(m => m.GetEvent(campaign.EventId)).Returns(eventDetails);

            _communicationService.Setup(
                m => m.GetTemplateAsCommunication(templateId,
                                                  communication.FromContact.ContactId,
                                                  communication.FromContact.EmailAddress,
                                                  communication.FromContact.ContactId,
                                                  communication.FromContact.EmailAddress,
                                                  eventDetails.PrimaryContact.ContactId,
                                                  eventDetails.PrimaryContact.EmailAddress,
                                                  mergeData)).Returns(communication);


            _communicationService.Setup(m => m.SendMessage(communication, false)).Returns(1);

            _fixture.SendTripIsFullMessage(pledgeCampaignId);

            _apiUserReposity.VerifyAll();
            _tripRepository.VerifyAll();
            _configurationWrapper.VerifyAll();
            _communicationService.VerifyAll();
            _eventService.VerifyAll();
        }