public MpInvitation CreateInvitation(MpInvitation dto)
        {
            // override the user login to avoid granting rights to all users
            string token = ApiLogin();

            var invitationType = dto.InvitationType;

            var values = new Dictionary <string, object>
            {
                { "Source_ID", dto.SourceId },
                { "Email_Address", dto.EmailAddress },
                { "Recipient_Name", dto.RecipientName },
                { "Group_Role_ID", dto.GroupRoleId },
                { "Invitation_Type_ID", invitationType },
                { "Invitation_Date", dto.RequestDate }
            };

            try
            {
                var invitationId = _ministryPlatformService.CreateRecord(_invitationPageId, values, token, true);
                var invitation   = _ministryPlatformService.GetRecordDict(_invitationPageId, invitationId, token);

                dto.InvitationId   = invitationId;
                dto.InvitationGuid = invitation["Invitation_GUID"].ToString();
                return(dto);
            }
            catch (Exception e)
            {
                throw new ApplicationException(string.Format("Create Invitation failed.  Invitation Type: {0}, Source Id: {1}", dto.InvitationType, dto.SourceId), e);
            }
        }
        public MpInvitation GetOpenInvitation(string invitationGuid)
        {
            // override the user login to avoid granting rights to all users
            string token        = ApiLogin();
            var    mpInvitation = new MpInvitation();

            try
            {
                var searchString = string.Format(",,,,,\"{0}\",\"{1}\"", invitationGuid, false);
                var mpResults    = _ministryPlatformService.GetRecordsDict(_invitationPageId, token, searchString, string.Empty);
                var invitation   = (mpResults != null && mpResults.Count > 0) ? mpResults.FirstOrDefault() : null;

                if (invitation != null)
                {
                    mpInvitation = new MpInvitation
                    {
                        InvitationId   = invitation.ToInt("dp_RecordID"),
                        SourceId       = invitation.ToInt("Source_ID"),
                        EmailAddress   = invitation.ToString("Email_address"),
                        GroupRoleId    = invitation.ToInt("Group_Role_ID"),
                        InvitationType = invitation.ToInt("Invitation_Type_ID"),
                        RecipientName  = invitation.ToString("Recipient_Name"),
                        RequestDate    = invitation.ToDate("Invitation_Date")
                    };
                }
            }
            catch (Exception e)
            {
                throw new ApplicationException(string.Format("Get Invitation failed.  Invitation GUID: {0}, Invitation Used: {1}", invitationGuid, false), e);
            }

            return(mpInvitation);
        }
示例#3
0
        public IObservable <ContactInvitation> CreateWaiverInvitation(int waiverId, int eventParticipantId, string token)
        {
            var contactId = _authenticationRepository.GetContactId(token);

            return(_contactRepository.GetSimpleContact(contactId).SelectMany(con =>
            {
                return _waiverRepository.CreateEventParticipantWaiver(waiverId, eventParticipantId, contactId).SelectMany(eventParticipantWaiver =>
                {
                    // create private invite
                    var mpInvitation = new MpInvitation
                    {
                        SourceId = eventParticipantWaiver.EventParticipantWaiverId,
                        EmailAddress = con.EmailAddress,
                        InvitationType = _confiurationWrapper.GetConfigIntValue("WaiverInvitationType"),
                        RecipientName = $"{con.Nickname ?? con.FirstName} {con.LastName}",
                        RequestDate = DateTime.Now
                    };

                    return _invitationRepository.CreateInvitationAsync(mpInvitation).Select(invite => new ContactInvitation
                    {
                        Contact = con,
                        Invitation = invite
                    });
                });
            }));
        }
示例#4
0
 public IObservable <MpInvitation> CreateInvitationAsync(MpInvitation invite)
 {
     return(Observable.Start <MpInvitation>(() =>
     {
         var token = ApiLogin();
         return _ministryPlatformRestRepository.UsingAuthenticationToken(token).Create(invite);
     }));
 }
示例#5
0
        public void GetOpenInvitationTest()
        {
            var dto = new MpInvitation
            {
                SourceId       = 123123,
                EmailAddress   = "*****@*****.**",
                GroupRoleId    = 66,
                InvitationType = 1,
                RecipientName  = "Test User",
                RequestDate    = new DateTime(2004, 1, 13)
            };

            const string invitationGuid = "329129741-adsfads-3281234-asdfasdf";

            var returned = new List <Dictionary <string, object> >
            {
                new Dictionary <string, object>
                {
                    { "dp_RecordID", 178 },
                    { "Source_ID", 123123 },
                    { "Email_address", "*****@*****.**" },
                    { "Group_Role_ID", "66" },
                    { "Invitation_Type_ID", 1 },
                    { "Recipient_Name", "Test User" },
                    { "Invitation_Date", "1/13/2004" },
                }
            };

            _ministryPlatformService.Setup(mocked => mocked.GetRecordsDict(InvitationPageId, It.IsAny <string>(), It.IsAny <string>(), string.Empty)).Returns(returned);

            var result = _fixture.GetOpenInvitation(invitationGuid);

            _ministryPlatformService.VerifyAll();

            Assert.IsNotNull(result);
            Assert.AreEqual(dto.SourceId, result.SourceId);
            Assert.AreEqual(dto.EmailAddress, result.EmailAddress);
            Assert.AreEqual(dto.GroupRoleId, result.GroupRoleId);
            Assert.AreEqual(dto.InvitationType, result.InvitationType);
            Assert.AreEqual(dto.RecipientName, result.RecipientName);
            Assert.AreEqual(dto.RequestDate, result.RequestDate);
        }
示例#6
0
        public void TestCreateInvitation()
        {
            var dto = new MpInvitation
            {
                EmailAddress   = "*****@*****.**",
                GroupRoleId    = 11,
                RecipientName  = "James Howlett",
                InvitationType = 33,
                RequestDate    = DateTime.Now,
                SourceId       = 44
            };

            const int    invitationId   = 987;
            const string invitationGuid = "1020304050";

            var created = new Dictionary <string, object>
            {
                { "Invitation_GUID", invitationGuid }
            };

            _ministryPlatformService.Setup(
                mocked =>
                mocked.CreateRecord(InvitationPageId,
                                    It.Is <Dictionary <string, object> >(
                                        d =>
                                        d.ToInt("Source_ID", false) == dto.SourceId && d.ToString("Email_Address").Equals(dto.EmailAddress) &&
                                        d.ToString("Recipient_Name").Equals(dto.RecipientName) && d.ToInt("Group_Role_ID", false) == dto.GroupRoleId &&
                                        d.ToInt("Invitation_Type_ID", false) == dto.InvitationType /*&& d["Invitation_Date"].Equals(dto.RequestDate)*/),
                                    It.IsAny <string>(),
                                    true)).Returns(invitationId);
            _ministryPlatformService.Setup(mocked => mocked.GetRecordDict(InvitationPageId, invitationId, It.IsAny <string>(), false)).Returns(created);

            var result = _fixture.CreateInvitation(dto);

            _ministryPlatformService.VerifyAll();

            Assert.IsNotNull(result);
            Assert.AreSame(dto, result);
            Assert.AreEqual(invitationId, result.InvitationId);
            Assert.AreEqual(invitationGuid, result.InvitationGuid);
        }
示例#7
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);
        }
示例#8
0
        public void CanCreateInvitationsForGroups()
        {
            const string token = "dude";

            var invitation = new Invitation()
            {
                EmailAddress   = "*****@*****.**",
                GroupRoleId    = GroupRoleLeader,
                InvitationType = GroupInvitationType,
                RecipientName  = "Dudley Doright",
                RequestDate    = new DateTime(2016, 7, 6),
                SourceId       = 33
            };

            var mpInvitation = new MpInvitation
            {
                InvitationType = invitation.InvitationType,
                EmailAddress   = invitation.EmailAddress,
                GroupRoleId    = invitation.GroupRoleId,
                RecipientName  = invitation.RecipientName,
                RequestDate    = invitation.RequestDate,
                SourceId       = invitation.SourceId,
                InvitationGuid = "guid123",
                InvitationId   = 11
            };

            _invitationRepository.Setup(
                m =>
                m.CreateInvitation(
                    It.Is <MpInvitation>(
                        i =>
                        i.InvitationType == invitation.InvitationType && i.EmailAddress.Equals(invitation.EmailAddress) && i.GroupRoleId == invitation.GroupRoleId &&
                        i.RecipientName.Equals(invitation.RecipientName) && i.RequestDate.Equals(invitation.RequestDate) && i.SourceId == invitation.SourceId))).Returns(mpInvitation);

            var testGroup = new MpGroup
            {
                GroupId = 33,
                Name    = "TestGroup"
            };

            _groupRepository.Setup(mocked => mocked.getGroupDetails(invitation.SourceId)).Returns(testGroup);

            var testLeaderParticipant = new MpParticipant
            {
                DisplayName  = "TestLeaderName",
                ContactId    = 123,
                EmailAddress = "*****@*****.**"
            };

            var leaderContact = new MpMyContact
            {
                Last_Name = "TestLast",
                Nickname  = "TestNick"
            };

            _contactRespository.Setup(mocked => mocked.GetContactById(testLeaderParticipant.ContactId)).Returns(leaderContact);

            _participantRepository.Setup(mocked => mocked.GetParticipantRecord(token)).Returns(testLeaderParticipant);

            var template = new MpMessageTemplate
            {
                Body                = "body",
                FromContactId       = 12,
                FromEmailAddress    = "*****@*****.**",
                ReplyToContactId    = 34,
                ReplyToEmailAddress = "*****@*****.**",
                Subject             = "subject"
            };

            _communicationService.Setup(mocked => mocked.GetTemplate(GroupInvitationEmailTemplate)).Returns(template);

            //_communicationService.Setup(
            //    mocked =>
            //        mocked.SendMessage(
            //            It.Is<MpCommunication>(
            //                c =>
            //                    c.AuthorUserId == 5 && c.DomainId == DomainId && c.EmailBody.Equals(template.Body) && c.EmailSubject.Equals(template.Subject) &&
            //                    c.FromContact.ContactId == template.FromContactId && c.FromContact.EmailAddress.Equals(template.FromEmailAddress) &&
            //                    c.ReplyToContact.ContactId == template.ReplyToContactId && c.ReplyToContact.EmailAddress.Equals(template.ReplyToEmailAddress) &&
            //                    c.ToContacts.Count == 1 && c.ToContacts[0].EmailAddress.Equals(invitation.EmailAddress) &&
            //                    c.MergeData["Invitation_GUID"].ToString().Equals(mpInvitation.InvitationGuid) &&
            //                    c.MergeData["Recipient_Name"].ToString().Equals(mpInvitation.RecipientName) &&
            //                    c.MergeData["Leader_Name"].ToString().Equals(testLeaderParticipant.DisplayName) &&
            //                    c.MergeData["Group_Name"].ToString().Equals(testGroup.Name)),
            //            false)).Returns(77);

            _communicationService.Setup(
                mocked =>
                mocked.SendMessage(
                    It.Is <MpCommunication>(
                        c =>
                        c.AuthorUserId == 5 && c.DomainId == DomainId && c.EmailBody.Equals(template.Body) && c.EmailSubject.Equals(template.Subject) &&
                        c.FromContact.ContactId == template.FromContactId && c.FromContact.EmailAddress.Equals(template.FromEmailAddress) &&
                        c.ReplyToContact.ContactId == testLeaderParticipant.ContactId && c.ReplyToContact.EmailAddress.Equals(template.ReplyToEmailAddress) &&
                        c.ToContacts.Count == 1 && c.ToContacts[0].EmailAddress.Equals(invitation.EmailAddress) &&
                        c.MergeData["Invitation_GUID"].ToString().Equals(mpInvitation.InvitationGuid) &&
                        c.MergeData["Recipient_Name"].ToString().Equals(mpInvitation.RecipientName) &&
                        c.MergeData["Leader_Name"].ToString().Equals(leaderContact.Nickname + " " + leaderContact.Last_Name) &&
                        c.MergeData["Group_Name"].ToString().Equals(testGroup.Name)),
                    false)).Returns(77);

            var created = _fixture.CreateInvitation(invitation, token);

            _invitationRepository.VerifyAll();
            _communicationService.VerifyAll();
            Assert.AreSame(invitation, created);
            Assert.AreEqual(mpInvitation.InvitationId, created.InvitationId);
            Assert.AreEqual(mpInvitation.InvitationGuid, created.InvitationGuid);
        }
示例#9
0
        public void CanCreateInvitationsForAnywhereGroups()
        {
            const string token = "dude";

            string groupName              = "Dougs Anywhere Gathering";
            string recipientName          = "doug";
            string formattedRecipientName = "Doug";
            string leaderFName            = "xavier";
            string leaderLName            = "johnson";
            string formattedLeaderName    = "Xavier J.";

            string city        = "Lima";
            string state       = "Ohio";
            string description = "descriptive description";
            int    sourceId    = 12345;
            int    groupRoleId = 16;

            var invitation = new Invitation()
            {
                RecipientName  = recipientName,
                EmailAddress   = "*****@*****.**",
                SourceId       = sourceId,
                GroupRoleId    = groupRoleId,
                InvitationType = AnywhereGatheringInvitationTypeID
            };

            var mpInvitation = new MpInvitation
            {
                InvitationType = invitation.InvitationType,
                EmailAddress   = invitation.EmailAddress,
                GroupRoleId    = invitation.GroupRoleId,
                RecipientName  = invitation.RecipientName,
                RequestDate    = invitation.RequestDate,
                SourceId       = invitation.SourceId,
                InvitationGuid = "guid123",
                InvitationId   = 11
            };

            _invitationRepository.Setup(
                m =>
                m.CreateInvitation(
                    It.Is <MpInvitation>(
                        i =>
                        i.InvitationType == invitation.InvitationType && i.EmailAddress.Equals(invitation.EmailAddress) && i.GroupRoleId == invitation.GroupRoleId &&
                        i.RecipientName.Equals(invitation.RecipientName) && i.SourceId == invitation.SourceId))).Returns(mpInvitation);

            var testGroup = new MpGroup
            {
                GroupId = 33,
                Name    = groupName,
                Address = new MpAddress()
                {
                    City  = city,
                    State = state
                },
                GroupDescription = description
            };

            _groupRepository.Setup(mocked => mocked.getGroupDetails(invitation.SourceId)).Returns(testGroup);


            MpParticipant leader = new MpParticipant()
            {
                ContactId = 123456789
            };

            MpMessageTemplate template = new MpMessageTemplate()
            {
                Body                = "this is the template!",
                FromContactId       = 1,
                FromEmailAddress    = "*****@*****.**",
                ReplyToContactId    = leader.ContactId,
                ReplyToEmailAddress = "*****@*****.**",
                Subject             = "TheSubject!"
            };
            MpMyContact leaderContact = new MpMyContact()
            {
                Nickname  = leaderFName,
                Last_Name = leaderLName
            };

            _participantRepository.Setup(mocked => mocked.GetParticipantRecord(token)).Returns(leader);
            _contactRespository.Setup((c) => c.GetContactById(It.Is <int>((i) => i == leader.ContactId))).Returns(leaderContact);
            _communicationService.Setup((c) => c.GetTemplate(It.Is <int>((i) => i == AnywhereGatheringEmailTemplateID))).Returns(template);
            _communicationService.Setup((c) => c.SendMessage(It.Is <MpCommunication>(
                                                                 (confirmation) => confirmation.EmailBody == template.Body &&
                                                                 confirmation.EmailSubject == template.Subject &&
                                                                 confirmation.AuthorUserId == 5 &&
                                                                 confirmation.DomainId == DomainId &&
                                                                 confirmation.FromContact.ContactId == template.FromContactId &&
                                                                 confirmation.ReplyToContact.ContactId == template.ReplyToContactId &&
                                                                 confirmation.TemplateId == AnywhereGatheringEmailTemplateID &&
                                                                 confirmation.ToContacts[0].EmailAddress == invitation.EmailAddress &&
                                                                 (string)confirmation.MergeData["Invitation_GUID"] == mpInvitation.InvitationGuid &&
                                                                 (string)confirmation.MergeData["Recipient_Name"] == formattedRecipientName &&
                                                                 (string)confirmation.MergeData["Leader_Name"] == formattedLeaderName
                                                                 ),
                                                             false));


            var created = _fixture.CreateInvitation(invitation, token);

            _invitationRepository.VerifyAll();
            _communicationService.VerifyAll();
            Assert.AreSame(invitation, created);
            Assert.AreEqual(mpInvitation.InvitationId, created.InvitationId);
            Assert.AreEqual(mpInvitation.InvitationGuid, created.InvitationGuid);
        }