Esempio n. 1
0
 private static DateTime IncrementSequenceDate(MpEvent @event, DateTime sequenceDate, int increment)
 {
     if (@event.EventStartDate.Date > sequenceDate.Date)
     {
         sequenceDate = sequenceDate.AddDays(increment);
     }
     return(sequenceDate);
 }
Esempio n. 2
0
        private static MpMyContact ReplyToContact(MpEvent childEvent)
        {
            var contact        = childEvent.PrimaryContact;
            var replyToContact = new MpMyContact
            {
                Contact_ID    = contact.ContactId,
                Email_Address = contact.EmailAddress
            };

            return(replyToContact);
        }
Esempio n. 3
0
        private Dictionary <string, object> HandleNoRsvp(MpParticipant participant,
                                                         MpEvent e,
                                                         List <int> opportunityIds,
                                                         string token,
                                                         MpMyContact groupLeader)
        {
            int           templateId;
            MpOpportunity previousOpportunity = null;

            try
            {
                templateId = AppSetting("RsvpNoTemplate");
                //opportunityId = opportunityIds.First();
                _eventService.UnregisterParticipantForEvent(participant.ParticipantId, e.EventId);
            }
            catch (ApplicationException ex)
            {
                logger.Debug(ex.Message + ": There is no need to remove the event participant because there is not one.");
                templateId = AppSetting("RsvpNoTemplate");
            }

            // Responding no means that we are saying no to all opportunities for this group for this event
            foreach (var oid in opportunityIds)
            {
                var comments   = string.Empty; //anything of value to put in comments?
                var updatedOpp = _opportunityService.RespondToOpportunity(participant.ParticipantId,
                                                                          oid,
                                                                          comments,
                                                                          e.EventId,
                                                                          false);
                if (updatedOpp > 0)
                {
                    previousOpportunity = _opportunityService.GetOpportunityById(oid, token);
                }
            }

            if (previousOpportunity != null)
            {
                var emailName            = participant.DisplayName;
                var emailEmail           = participant.EmailAddress;
                var emailTeamName        = previousOpportunity.GroupName;
                var emailOpportunityName = previousOpportunity.OpportunityName;
                var emailEventDateTime   = e.EventStartDate.ToString();

                SendCancellationMessage(groupLeader, emailName, emailEmail, emailTeamName, emailOpportunityName, emailEventDateTime);
            }

            return(new Dictionary <string, object>()
            {
                { "templateId", templateId },
                { "previousOpportunity", previousOpportunity },
                { "rsvp", false }
            });
        }
Esempio n. 4
0
        private Dictionary <string, object> CreateRsvp(string token,
                                                       int opportunityId,
                                                       List <int> opportunityIds,
                                                       bool signUp,
                                                       MpParticipant participant,
                                                       MpEvent @event,
                                                       MpMyContact groupLeader)
        {
            var response = signUp
                ? HandleYesRsvp(participant, @event, opportunityId, opportunityIds, token)
                : HandleNoRsvp(participant, @event, opportunityIds, token, groupLeader);

            return(response);
        }
Esempio n. 5
0
        private Dictionary <string, object> HandleYesRsvp(MpParticipant participant,
                                                          MpEvent e,
                                                          int opportunityId,
                                                          IReadOnlyCollection <int> opportunityIds,
                                                          String token)
        {
            var           templateId          = AppSetting("RsvpYesTemplate");
            var           deletedRSVPS        = new List <int>();
            MpOpportunity previousOpportunity = null;

            var opportunity = _opportunityService.GetOpportunityById(opportunityId, token);

            //Try to register this user for the event
            _eventService.RegisterParticipantForEvent(participant.ParticipantId, e.EventId, opportunity.GroupId);

            // Make sure we are only rsvping for 1 opportunity by removing all existing responses
            deletedRSVPS.AddRange(from oid in opportunityIds
                                  let deletedResponse =
                                      _opportunityService.DeleteResponseToOpportunities(participant.ParticipantId, oid, e.EventId)
                                      where deletedResponse != 0
                                      select oid);

            if (deletedRSVPS.Count > 0)
            {
                templateId = AppSetting("RsvpChangeTemplate");
                if (opportunityIds.Count != deletedRSVPS.Count)
                {
                    //Changed yes to yes
                    //prevOppId = deletedRSVPS.First();
                    previousOpportunity = _opportunityService.GetOpportunityById(deletedRSVPS.First(), token);
                }
            }
            var comments = string.Empty; //anything of value to put in comments?

            _opportunityService.RespondToOpportunity(participant.ParticipantId,
                                                     opportunityId,
                                                     comments,
                                                     e.EventId,
                                                     true);
            return(new Dictionary <string, object>()
            {
                { "templateId", templateId },
                { "previousOpportunity", previousOpportunity },
                { "rsvp", true }
            });
        }
Esempio n. 6
0
        public void TestGetAllEventsForGroup()
        {
            const int groupId = 987654;

            var mockEvent1 = new MpEvent()
            {
                EventId        = 123,
                Congregation   = "Katrina's House",
                EventStartDate = new DateTime(2014, 3, 4),
                EventTitle     = "Katrina's House Party",
                EventEndDate   = new DateTime(2014, 4, 4),
                EventType      = "Childcare"
            };
            var mockEvent2 = new MpEvent()
            {
                EventId        = 456,
                Congregation   = "Andy's House",
                EventStartDate = new DateTime(2014, 4, 4),
                EventTitle     = "Andy's House Party",
                EventEndDate   = new DateTime(2014, 4, 4),
                EventType      = "Childcare"
            };
            var mockResultSet = new List <List <MpEvent> >()
            {
                new List <MpEvent> {
                    mockEvent1, mockEvent2
                }
            };

            _ministryPlatformRestService.Setup(m => m.UsingAuthenticationToken(ApiToken)).Returns(_ministryPlatformRestService.Object);
            _ministryPlatformRestService.Setup(m => m.GetFromStoredProc <MpEvent>("api_crds_Get_Events_For_Group", It.IsAny <Dictionary <string, object> >())).Returns(mockResultSet);

            var events = _fixture.getAllEventsForGroup(groupId);

            _ministryPlatformService.VerifyAll();

            Assert.IsNotNull(events);
            Assert.AreEqual(2, events.Count);
            Assert.AreEqual(123, events[0].EventId);
            Assert.AreEqual(456, events[1].EventId);
        }
Esempio n. 7
0
        public void GetEvent()
        {
            //Arrange
            const int eventId = 999;
            var       mpevent = new MpEvent {
                EventId        = 999,
                EventTitle     = "event-title-100",
                EventType      = "event-type-100",
                EventStartDate = new DateTime(2015, 3, 28, 8, 30, 0),
                EventEndDate   = new DateTime(2015, 3, 28, 8, 30, 0),
                PrimaryContact = new MpContact {
                    ContactId = 12345, EmailAddress = "*****@*****.**"
                },
                ParentEventId       = 6543219,
                CongregationId      = 2,
                ReminderDaysPriorId = 2,
                Cancelled           = false
            };

            _ministryPlatformRestService.Setup(m => m.UsingAuthenticationToken(It.IsAny <string>())).Returns(_ministryPlatformRestService.Object);
            _ministryPlatformRestService.Setup(m => m.Get <MpEvent>(eventId, (string)null)).Returns(mpevent);
            _ministryPlatformRestService.Setup(m => m.Get <MpContact>(It.IsAny <int>(), It.IsAny <string>())).Returns(new MpContact {
                ContactId = 12345, EmailAddress = "*****@*****.**"
            });

            //Act
            var theEvent = _fixture.GetEvent(eventId);

            //Assert
            _ministryPlatformService.VerifyAll();

            Assert.AreEqual(eventId, theEvent.EventId);
            Assert.AreEqual("event-title-100", theEvent.EventTitle);
            Assert.AreEqual(12345, theEvent.PrimaryContact.ContactId);
            Assert.AreEqual("*****@*****.**", theEvent.PrimaryContact.EmailAddress);
        }
Esempio n. 8
0
        public void SendTwoRsvpEmails()
        {
            const int daysBefore      = 999;
            const int emailTemplateId = 77;
            var       participants    = new List <MpEventParticipant>
            {
                new MpEventParticipant
                {
                    ParticipantId = 1,
                    EventId       = 123,
                    ContactId     = 987654
                },
                new MpEventParticipant
                {
                    ParticipantId = 2,
                    EventId       = 456,
                    ContactId     = 456123
                }
            };

            var mockPrimaryContact = new MpContact
            {
                ContactId    = 98765,
                EmailAddress = "*****@*****.**"
            };

            var defaultContact = new MpMyContact
            {
                Contact_ID    = 123456,
                Email_Address = "*****@*****.**"
            };

            var mockEvent1 = new MpEvent {
                EventType = "Childcare", PrimaryContact = mockPrimaryContact
            };
            var mockEvent2 = new MpEvent {
                EventType = "DoggieDaycare", PrimaryContact = mockPrimaryContact
            };
            var mockEvents = new List <MpEvent> {
                mockEvent1, mockEvent2
            };

            _configurationWrapper.Setup(m => m.GetConfigIntValue("NumberOfDaysBeforeEventToSend")).Returns(daysBefore);
            _configurationWrapper.Setup(m => m.GetConfigIntValue("ChildcareRequestTemplate")).Returns(emailTemplateId);
            _communicationService.Setup(m => m.GetTemplate(emailTemplateId)).Returns(new MpMessageTemplate());
            _eventParticipantService.Setup(m => m.GetChildCareParticipants(daysBefore)).Returns(participants);
            _communicationService.Setup(m => m.SendMessage(It.IsAny <MpCommunication>(), false)).Verifiable();

            var kids = new List <Participant> {
                new Participant {
                    ContactId = 456321987
                }
            };

            _crdsEventService.Setup(m => m.EventParticpants(987654321, It.IsAny <string>())).Returns(kids);
            var mockChildcareEvent = new MpEvent {
                EventId = 987654321
            };
            var mockContact = new MpContact
            {
                ContactId    = 8888888,
                EmailAddress = "*****@*****.**"
            };

            mockChildcareEvent.PrimaryContact = mockContact;
            _crdsEventService.Setup(m => m.GetChildcareEvent(participants[0].EventId)).Returns(mockChildcareEvent);
            _crdsEventService.Setup(m => m.GetChildcareEvent(participants[1].EventId)).Returns(mockChildcareEvent);
            _configurationWrapper.Setup(m => m.GetConfigIntValue("DefaultContactEmailId")).Returns(1234);
            _contactService.Setup(mocked => mocked.GetContactById(1234)).Returns(defaultContact);
            var myKids = new List <Participant>();

            _crdsEventService.Setup(m => m.MyChildrenParticipants(987654, kids, It.IsAny <string>())).Returns(myKids);

            _fixture.SendRequestForRsvp();

            _configurationWrapper.VerifyAll();
            _communicationService.VerifyAll();
            _contactService.VerifyAll();
            _eventParticipantService.VerifyAll();
            _communicationService.VerifyAll();
            _communicationService.Verify(m => m.SendMessage(It.IsAny <MpCommunication>(), false), Times.Exactly(2));
            _eventService.VerifyAll();
        }