/// <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>        
        public void SendMessage(Communication communication)
        {
            var token = ApiLogin();

            var communicationId = AddCommunication(communication, token);
            AddCommunicationMessages(communication, communicationId, token);
        }
Пример #2
0
        public void SendEmail(EmailCommunicationDTO email, string token)
        {
            var communication = new Communication();
            communication.DomainId = 1;

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

            communication.AuthorUserId = email.FromUserId ?? _communicationService.GetUserIdFromContactId(token, email.FromContactId);

            var sender = _personService.GetPerson(DefaultContactEmailId);
            var from = new Contact { ContactId = sender.ContactId, EmailAddress = sender.EmailAddress };
            communication.FromContact = from;
            communication.ReplyToContact = from;

            var receiver = _personService.GetPerson(email.ToContactId);
            var recipient = new Contact {ContactId = receiver.ContactId, EmailAddress = receiver.EmailAddress};
            communication.ToContacts.Add(recipient);

            var template = _communicationService.GetTemplate(email.TemplateId);
            communication.TemplateId = email.TemplateId;
            communication.EmailBody = template.Body;
            communication.EmailSubject = template.Subject;

            communication.MergeData = email.MergeData;

            _communicationService.SendMessage(communication);
        }
Пример #3
0
 public void SendEmail(CommunicationDTO emailData)
 {
     var sender = _personService.GetPerson(DefaultContactEmailId);
     var from = new Contact {ContactId = DefaultContactEmailId, EmailAddress = sender.EmailAddress};
     var comm = new Communication
     {
         AuthorUserId = 1,
         DomainId = 1,
         EmailBody = emailData.Body,
         EmailSubject = emailData.Subject,
         FromContact = from,
         ReplyToContact = from,
         MergeData = new Dictionary<string, object>(),
         ToContacts = new List<Contact>()
     };
     foreach (var to in emailData.ToContactIds)
     {
         var contact = new Contact();
         contact.ContactId = to;
         contact.EmailAddress = _communicationService.GetEmailFromContactId(to);
         comm.ToContacts.Add(contact);
     }
     _communicationService.SendMessage(comm);
 }
Пример #4
0
        // TODO Made this virtual so could mock in a unit test.  Probably ought to refactor to a separate class - shouldn't have to mock the class we're testing...
        public virtual void SendEmail(int communicationTemplateId, int donorId, decimal donationAmount, string paymentType, DateTime setupDate, string program, string emailReason, string frequency = null)
        {
            var template = _communicationService.GetTemplate(communicationTemplateId);
            var defaultContact = _contactService.GetContactById(AppSetting("DefaultGivingContactEmailId"));
            var contact = GetEmailViaDonorId(donorId);

            var comm = new Communication
            {
                
                AuthorUserId = 5,
                DomainId = 1,
                EmailBody = template.Body,
                EmailSubject = template.Subject,
                FromContact =  new Contact { ContactId = defaultContact.Contact_ID, EmailAddress = defaultContact.Email_Address },
                ReplyToContact = new Contact { ContactId = defaultContact.Contact_ID, EmailAddress = defaultContact.Email_Address },
                ToContacts = new List<Contact> {new Contact{ContactId = contact.ContactId, EmailAddress = contact.Email}},
                MergeData = new Dictionary<string, object>
                {
                    {"Program_Name", program},
                    {"Donation_Amount", donationAmount.ToString("N2")},
                    {"Donation_Date", setupDate.ToString("MM/dd/yyyy h:mmtt", _dateTimeFormat)},
                    {"Payment_Method", paymentType},
                    {"Decline_Reason", emailReason}
                }
            };

            if (!string.IsNullOrWhiteSpace(frequency))
            {
                comm.MergeData["Frequency"] = frequency;
            }

            _communicationService.SendMessage(comm);
        }
Пример #5
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 : ""}
            };

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

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

            var confirmation = new Communication 
            { 
                EmailBody = emailTemplate.Body, 
                EmailSubject = emailTemplate.Subject,
                AuthorUserId = 5,
                DomainId = domainId,
                FromContact = from,
                MergeData = mergeData,
                ReplyToContact = from,
                TemplateId = CommunityGroupConfirmationTemplateId,
                ToContacts = to
            };
            _communicationService.SendMessage(confirmation);
        }
Пример #6
0
        public void TestSendEmailNoFrequency()
        {
            const string program = "Crossroads";
            const int declineEmailTemplate = 11940;
            var donationDate = DateTime.Now;
            const string emailReason = "rejected: lack of funds";
            const int donorId = 9876;
            const int donationAmt = 4343;
            const string paymentType = "Bank";

            var defaultContact = new MyContact()
            {
                Contact_ID = 1234556,
                Email_Address = "*****@*****.**"
            };

            var getTemplateResponse = new MessageTemplate()
            {
                Body = "Your payment was rejected.  Darn.",
                Subject = "Test Decline Email"
            };

            const string emailAddress = "*****@*****.**";
            const int contactId = 3;
            var contactList = new List<Dictionary<string, object>>
            {
                new Dictionary<string, object>
                {
                    {"Donor_ID", 1},
                    {"Processor_ID", 2},
                    {"Contact_ID", contactId},
                    {"Email", emailAddress},
                    {"Statement_Type", "Family"},
                    {"Statement_Type_ID", 2},
                    {"Statement_Frequency", "Quarterly"},
                    {"Statement_Method", "Online"},
                    {"Household_ID", 4},
                }
            };

            _ministryPlatformService.Setup(mocked => mocked.GetPageViewRecords("DonorByContactId", It.IsAny<string>(), It.IsAny<string>(), string.Empty, 0)).Returns(contactList);
            var expectedCommunication = new Communication
            {
                AuthorUserId = 5,
                DomainId = 1,
                EmailBody = getTemplateResponse.Body,
                EmailSubject = getTemplateResponse.Subject,
                FromContact = new Contact {ContactId = 5, EmailAddress = "*****@*****.**"},
                ReplyToContact = new Contact {ContactId = 5, EmailAddress = "*****@*****.**" },
                ToContacts = new List<Contact> {new Contact{ContactId = contactId, EmailAddress = emailAddress}},
                MergeData = new Dictionary<string, object>
                {
                    {"Program_Name", program},
                    {"Donation_Amount", donationAmt.ToString("N2")},
                    {"Donation_Date", donationDate.ToString("MM/dd/yyyy h:mmtt", new DateTimeFormatInfo
                    {
                        AMDesignator = "am",
                        PMDesignator = "pm"
                    })},
                    {"Payment_Method", paymentType},
                    {"Decline_Reason", emailReason},
                }
            };
            _contactService.Setup(mocked => mocked.GetContactById(Convert.ToInt32(ConfigurationManager.AppSettings["DefaultGivingContactEmailId"]))).Returns(defaultContact);
            _communicationService.Setup(mocked => mocked.GetTemplate(declineEmailTemplate)).Returns(getTemplateResponse);
            _communicationService.Setup(
                mocked =>
                    mocked.SendMessage(
                        It.Is<Communication>(
                            c =>
                                c.EmailBody.Equals(expectedCommunication.EmailBody) && c.EmailSubject.Equals(expectedCommunication.EmailSubject) &&
                                c.ToContacts[0].ContactId == expectedCommunication.ToContacts[0].ContactId && c.ToContacts[0].EmailAddress.Equals(expectedCommunication.ToContacts[0].EmailAddress) &&
                                c.MergeData["Program_Name"].Equals(expectedCommunication.MergeData["Program_Name"]) &&
                                c.MergeData["Donation_Amount"].Equals(expectedCommunication.MergeData["Donation_Amount"]) &&
                                c.MergeData["Donation_Date"].Equals(expectedCommunication.MergeData["Donation_Date"]) &&
                                c.MergeData["Payment_Method"].Equals(expectedCommunication.MergeData["Payment_Method"]) &&
                                c.MergeData["Decline_Reason"].Equals(expectedCommunication.MergeData["Decline_Reason"]) &&
                                !c.MergeData.ContainsKey("Frequency")
                            )));

            _fixture.SendEmail(declineEmailTemplate, donorId, donationAmt, paymentType, donationDate, program,
                emailReason, null);

            _ministryPlatformService.VerifyAll();
            _communicationService.VerifyAll();

        }
Пример #7
0
 private static Communication FormatCommunication(int authorUserId,
                                                  int domainId,
                                                  MessageTemplate template,
                                                  MyContact fromContact,
                                                  MyContact replyToContact,
                                                  int participantContactId,
                                                  string participantEmail,
                                                  Dictionary<string, object> mergeData)
 {
     var communication = new Communication
     {
         AuthorUserId = authorUserId,
         DomainId = domainId,
         EmailBody = template.Body,
         EmailSubject = template.Subject,
         FromContact = new Contact {ContactId = fromContact.Contact_ID, EmailAddress = fromContact.Email_Address},
         ReplyToContact = new Contact {ContactId = replyToContact.Contact_ID, EmailAddress = replyToContact.Email_Address},
         ToContacts = new List<Contact> {new Contact {ContactId = participantContactId, EmailAddress = participantEmail}},
         MergeData = mergeData
     };
     return communication;
 }
Пример #8
0
        public void ChangeResponseFromNoToYes()
        {
            int contactId = fakeMyContact.Contact_ID;
            int opportunityId = fakeOpportunity.OpportunityId;
            int eventTypeId = fakeOpportunity.EventTypeId;
            const bool signUp = true;
            const bool alternateWeeks = false;
            var oppIds = new List<int>() {1, 2, 3, 4, 5};

            SetUpRSVPMocks(contactId, eventTypeId, opportunityId, signUp, SetupMockEvents());

            // The current Opportunity
            _opportunityService.Setup(m => m.GetOpportunityById(opportunityId, It.IsAny<string>()))
                .Returns(fakeOpportunity);
            _opportunityService.Setup(m => m.DeleteResponseToOpportunities(47, 1, 1)).Returns(1);

            // The previous Opportunity
            _opportunityService.Setup(m => m.GetOpportunityById(1, It.IsAny<string>())).Returns(new Opportunity()
            {
                OpportunityId = 1,
                OpportunityName = "Previous Opportunity"
            });

            _configurationWrapper.Setup(m => m.GetConfigIntValue("DefaultContactEmailId")).Returns(1234);
            _contactService.Setup(m => m.GetContactById(1234)).Returns(new MyContact()
            {
                Email_Address = "*****@*****.**",
                Contact_ID = 1234567890
            });
            
            SaveRsvpDto dto = new SaveRsvpDto
            {
                ContactId = contactId,
                OpportunityId = opportunityId,
                OpportunityIds = oppIds,
                EventTypeId = eventTypeId,
                AlternateWeeks = alternateWeeks,
                StartDateUnix = new DateTime(2015, 1, 1).ToUnixTime(),
                EndDateUnix = new DateTime(2016, 1, 1).ToUnixTime(),
                SignUp = signUp
            };

            _fixture.SaveServeRsvp("1234567", dto);

            _participantService.VerifyAll();
            _eventService.Verify(
                m =>
                    m.GetEventsByTypeForRange(eventTypeId, It.IsAny<DateTime>(), It.IsAny<DateTime>(),
                        It.IsAny<string>()), Times.Exactly(1));
            _eventService.Verify(m => m.RegisterParticipantForEvent(47, It.IsAny<int>(), 0, 0), Times.Exactly(5));
            _opportunityService.Verify(
                (m => m.RespondToOpportunity(47, opportunityId, It.IsAny<string>(), It.IsAny<int>(), signUp)),
                Times.Exactly(5));

            _communicationService.Verify(m => m.GetTemplate(rsvpChangeId));

            var comm = new Communication
            {
                AuthorUserId = 5,
                DomainId = 1,
                EmailBody = mockRsvpChangedTemplate.Body,
                EmailSubject = mockRsvpChangedTemplate.Subject,
                FromContact = new Contact {ContactId = fakeGroupContact.Contact_ID, EmailAddress = fakeGroupContact.Email_Address},
                ReplyToContact = new Contact { ContactId = fakeGroupContact.Contact_ID, EmailAddress = fakeGroupContact.Email_Address },
                ToContacts = new List<Contact> {new Contact{ContactId = fakeGroupContact.Contact_ID, EmailAddress = fakeMyContact.Email_Address}}
            };

            var mergeData = new Dictionary<string, object>
            {
                {"Opportunity_Name", It.IsAny<string>()},
                {"Start_Date", It.IsAny<string>()},
                {"End_Date", It.IsAny<string>()},
                {"Shift_Start", It.IsAny<string>()},
                {"Shift_End", It.IsAny<string>()},
                {"Room", It.IsAny<string>()},
                {"Group_Contact", It.IsAny<string>()},
                {"Group_Name", It.IsAny<string>()},
                {"Volunteer_Name", It.IsAny<string>()},
                {"Previous_Opportunity_Name", It.IsAny<string>()}
            };

            _communicationService.Setup(
                m => m.SendMessage(It.IsAny<Communication>()))
                .Callback((Communication communication) => { }).Verifiable();
            _communicationService.Verify(
                m => m.SendMessage(It.IsAny<Communication>()));
        }
Пример #9
0
        public void ShouldSendReminderEmails()
        {
            const int pageId = 2203;
            const string apiToken = "1234";
            const int defaultEmailTemplate = 14567;

            var now = DateTime.Now;

            var fakeServeReminder = new ServeReminder()
            {
                OpportunityTitle = "Some Title",
                EventEndDate = now,
                EventStartDate = now,
                EventTitle = "Whatever",
                OpportunityContactId = fakeGroupContact.Contact_ID,
                OpportunityEmailAddress = fakeGroupContact.Email_Address,
                ShiftEnd = new TimeSpan(0, 7, 0, 0),
                ShiftStart = new TimeSpan(0, 9, 0, 0),
                SignedupContactId = fakeMyContact.Contact_ID,
                SignedupEmailAddress = fakeMyContact.Email_Address
            };

            var fakePageView = new MPServeReminders()
            {
                Opportunity_Title = fakeServeReminder.OpportunityTitle,               
                Opportunity_Contact_Id = fakeServeReminder.OpportunityContactId,
                Opportunity_Email_Address = fakeServeReminder.OpportunityEmailAddress,
                Event_End_Date = now,
                Event_Start_Date = now,
                Event_Title = fakeServeReminder.EventTitle,
                Signedup_Contact_Id = fakeMyContact.Contact_ID,
                Signedup_Email_Address = fakeMyContact.Email_Address,
                Template_Id = null,
                Shift_Start = fakeServeReminder.ShiftStart,
                Shift_End = fakeServeReminder.ShiftEnd
            };

            var fakeList = new List<MPServeReminders> ()
            {
                fakePageView
            };

            const int defaultContactEmailId = 1519180;
            

            var token = _apiUserService.Setup(m => m.GetToken()).Returns(apiToken);
            _responseService.Setup(m => m.GetServeReminders(apiToken)).Returns(fakeList);
            _contactService.Setup(m => m.GetContactById(defaultContactEmailId)).Returns(fakeGroupContact);

            fakeList.ForEach(f =>
            {
                var mergeData = new Dictionary<string, object>(){
                    {"Opportunity_Title", fakeServeReminder.OpportunityTitle},
                    {"Nickname", fakeMyContact.Nickname},
                    {"Event_Start_Date", fakeServeReminder.EventStartDate.ToShortDateString()},
                    {"Event_End_Date", fakeServeReminder.EventEndDate.ToShortDateString()},
                    {"Shift_Start", fakeServeReminder.ShiftStart},
                    {"Shift_End", fakeServeReminder.ShiftEnd}
                 };

                var contact = new Contact() {ContactId = fakeGroupContact.Contact_ID, EmailAddress = fakeGroupContact.Email_Address};
                var toContact = new Contact() {ContactId = fakeMyContact.Contact_ID, EmailAddress = fakeMyContact.Email_Address};
                var fakeCommunication = new Communication()
                {
                    AuthorUserId = fakeGroupContact.Contact_ID,
                    DomainId = 1,
                    EmailBody = "Some Email Body",
                    EmailSubject = "Whatever",
                    FromContact = contact,
                    MergeData = mergeData,
                    ReplyToContact = contact,
                    TemplateId = defaultEmailTemplate,
                    ToContacts = new List<Contact>() {toContact}
                };

                _contactService.Setup(m => m.GetContactById(fakeServeReminder.SignedupContactId)).Returns(fakeMyContact);
                _communicationService.Setup(m => m.GetTemplateAsCommunication(defaultEmailTemplate,
                                                                              fakeGroupContact.Contact_ID,
                                                                              fakeGroupContact.Email_Address,
                                                                              fakeServeReminder.OpportunityContactId,
                                                                              fakeServeReminder.OpportunityEmailAddress,
                                                                              fakeMyContact.Contact_ID,
                                                                              fakeMyContact.Email_Address,
                                                                              mergeData)).Returns(fakeCommunication);
                _communicationService.Setup(m => m.SendMessage(fakeCommunication));
                _communicationService.Verify();

            });
            _responseService.Verify();
        }
Пример #10
0
 private int AddCommunication(Communication communication, string token)
 {
     var dictionary = new Dictionary<string, object>
     {
         {"Subject", communication.EmailSubject},
         {"Body", communication.EmailBody},
         {"Author_User_Id", communication.AuthorUserId},
         {"Start_Date", DateTime.Now},
         {"From_Contact", communication.FromContact.ContactId},
         {"Reply_to_Contact", communication.ReplyToContact.ContactId},
         {"Communication_Status_ID", _communicationStatusId}
     };
     var communicationId = _ministryPlatformService.CreateRecord(_messagePageId, dictionary, token);
     return communicationId;
 }
Пример #11
0
 private void AddCommunicationMessages(Communication communication, int communicationId, string token)
 {
     foreach (Contact 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)}
         };
         _ministryPlatformService.CreateSubRecord(_recipientsSubPageId, communicationId, dictionary, token);
     }
 }
Пример #12
0
        public void SendMessageFromDonor(int pledgeId, string message)
        {
            var toDonor = _pledgeService.GetDonorForPledge(pledgeId);
            var donorContact = _donorService.GetEmailViaDonorId(toDonor);
            var template = _communicationService.GetTemplate(_tripDonationMessageTemplateId);

            var toContacts = new List<Contact> {new Contact {ContactId = donorContact.ContactId, EmailAddress = donorContact.Email}};

            var from = new Contact()
            {
                ContactId = 5,
                EmailAddress = "*****@*****.**"
            };

            var defaultContactId = AppSetting("DefaultContactEmailId");
            var defaultContactEmail = _communicationService.GetEmailFromContactId(defaultContactId);

            var comm = new Communication
            {
                AuthorUserId = 5,
                DomainId = 1,
                EmailBody = message,
                EmailSubject = template.Subject,
                FromContact = from,
                ReplyToContact = from,
                ToContacts = toContacts,
                MergeData = new Dictionary<string, object>()
            };
            _communicationService.SendMessage(comm);
        }
Пример #13
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<Contact>()
            {
                new Contact()
                {
                     ContactId = toEmail.ContactId,
                    EmailAddress = toEmail.Email
                }
            };

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

            var comm = new Communication
            {
                AuthorUserId = authorId,
                DomainId = 1,
                ToContacts = to,
                FromContact = new Contact(){ContactId = defaultContactId, EmailAddress = defaultContactEmail},
                ReplyToContact = new Contact(){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());
        }