コード例 #1
0
        public List<int> SaveServeRsvp(string token, SaveRsvpDto dto)
        {
            List<MailRow> mailRows = new List<MailRow>();

            var templateId = GetRsvpTemplate(dto.SignUp);
            var opportunity = GetOpportunity(token, dto.OpportunityId, dto.OpportunityIds);
            var groupContact = _contactService.GetContactById(opportunity.GroupContactId);

            var toContact = _contactService.GetContactById(dto.ContactId);
            Opportunity previousOpportunity = null;
            try
            {
                var updatedEvents = GetUpdatedOpportunities(token,
                                                            dto,
                                                            (participant, e) =>
                                                            {
                                                                DateTime from = DateTime.Today.Add(opportunity.ShiftStart);
                                                                DateTime to = DateTime.Today.Add(opportunity.ShiftEnd);
                                                                mailRows.Add(new MailRow()
                                                                {
                                                                    EventDate = e.EventStartDate.ToShortDateString(),
                                                                    Location = opportunity.Room,
                                                                    OpportunityName = opportunity.OpportunityName,
                                                                    ShiftTime = from.ToString("hh:mm tt") + " - " + to.ToString("hh:mm tt")
                                                                });
                                                                var response = CreateRsvp(token, dto.OpportunityId, dto.OpportunityIds, dto.SignUp, participant, e, groupContact);
                                                                previousOpportunity = PreviousOpportunity(response, previousOpportunity);
                                                                templateId = GetTemplateId(templateId, response);
                                                                return true;
                                                            });
                var table = SetupHTMLTable(mailRows).Build();
                var mergeData = SetupMergeData(dto.ContactId,
                                               dto.OpportunityId,
                                               previousOpportunity,
                                               opportunity,
                                               dto.StartDateUnix.FromUnixTime(),
                                               dto.EndDateUnix.FromUnixTime(),
                                               groupContact,
                                               table);

                var communication = SetupCommunication(templateId, groupContact, toContact, mergeData);
                _communicationService.SendMessage(communication);
                return updatedEvents;
            }
            catch (Exception e)
            {
                //var communication = SetupCommunication(templateId, groupContact, toContact);
                var table = SetupHTMLTable(mailRows).Build();
                var communication = SetupCommunication(AppSetting("SignupToServeFailedMessage"),
                                                       groupContact,
                                                       toContact,
                                                       new Dictionary<string, object>
                                                       {
                                                           {"Html_Table", table}
                                                       });
                _communicationService.SendMessage(communication);
                return new List<int>();
            }
        }
コード例 #2
0
        public List<int> GetUpdatedOpportunities(string token, SaveRsvpDto dto, Func<Participant, MinistryPlatform.Models.Event, bool> saveFunc = null)
        {
            var updatedEvents = new List<int>();

            //get participant id for Contact
            var participant = _participantService.GetParticipant(dto.ContactId);

            //get events in range
            var events = GetEventsInRange(token, dto.EventTypeId, dto.StartDateUnix.FromUnixTime(), dto.EndDateUnix.FromUnixTime());
            var increment = dto.AlternateWeeks ? 14 : 7;
            var sequenceDate = dto.StartDateUnix.FromUnixTime();
            for (var i = 0; i < events.Count(); i++)
            {
                var @event = events[i];
                sequenceDate = IncrementSequenceDate(@event, sequenceDate, increment);
                if (@event.EventStartDate.Date != sequenceDate.Date)
                {
                    continue;
                }
                updatedEvents.Add(@event.EventId);
                if (saveFunc != null)
                {
                    saveFunc(participant, @event);
                }
                sequenceDate = sequenceDate.AddDays(increment);
            }
            return updatedEvents;
        }
コード例 #3
0
        public void RespondToServeOpportunityYesEveryWeek()
        {
            const int contactId = 8;
            const int opportunityId = 12;
            const int eventTypeId = 3;
            const bool signUp = true;
            const bool alternateWeeks = false;
            var oppIds = new List<int>() {1, 2, 3, 4, 5};

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

            _configurationWrapper.Setup(m => m.GetConfigIntValue("DefaultContactEmailId")).Returns(1234);
            _contactService.Setup(m => m.GetContactById(1234)).Returns(new MyContact()
            {
                Email_Address = "*****@*****.**",
                Contact_ID = 1234567890
            });

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

            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));

            Opportunity o = new Opportunity();
            o.OpportunityName = "Whatever";
            o.OpportunityId = opportunityId;
            o.ShiftStart = new TimeSpan();
            o.ShiftEnd = new TimeSpan();
            o.Room = "123";

            _opportunityService.Setup(m => m.GetOpportunityById(opportunityId, It.IsAny<string>())).Returns(o);
        }
コード例 #4
0
        public void RespondToServeOpportunityYesForEveryOtherWeek(List<Event> mockEvents)
        {
            const int contactId = 8;
            const int opportunityId = 12;
            const int eventTypeId = 3;
            const bool signUp = true;
            const bool alternateWeeks = true;
            var expectedEventIds = new List<int> {1, 3, 5};
            var oppIds = new List<int>() {1, 2, 3, 4, 5};

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

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

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

            _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(It.IsAny<string>(), dto);

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

            _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.IsIn<int>(expectedEventIds), 0, 0),
                Times.Exactly(3));

            _opportunityService.Verify(
                (m =>
                    m.RespondToOpportunity(47, opportunityId, It.IsAny<string>(), It.IsIn<int>(expectedEventIds), signUp)),
                Times.Exactly(3));
        }
コード例 #5
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>()));
        }