Exemplo n.º 1
0
        public Participant GetParticipant(int contactId)
        {
            Participant participant;
            //var records = new List<Dictionary<string, object>>();
            try
            {
                var searchStr = contactId.ToString() + ",";
                var records =
                    WithApiLogin<List<Dictionary<string, object>>>(
                        apiToken =>
                            (_ministryPlatformService.GetPageViewRecords("ParticipantByContactId", apiToken, searchStr,
                                "")));
                var record = records.Single();
                participant = new Participant
                {
                    ContactId = record.ToInt("Contact ID"),
                    ParticipantId = record.ToInt("dp_RecordID"),
                    EmailAddress = record.ToString("Email Address"),
                    PreferredName = record.ToString("Nickname"), 
                    DisplayName =  record.ToString("Display Name"), 
                    Age = record.ToInt("Age")
                };
            }
            catch (Exception ex)
            {
                throw new ApplicationException(
                    string.Format("GetParticipant failed.  Contact Id: {0}", contactId), ex);
            }


            return participant;
        }
Exemplo n.º 2
0
        //Get Participant IDs of a contact
        public Participant GetParticipantRecord(string token)
        {
            var results = _ministryPlatformService.GetRecordsDict("MyParticipantRecords", token);
            Dictionary<string, object> result = null;
            try
            {
                result = results.SingleOrDefault();
            }
            catch (InvalidOperationException ex)
            {
                if (ex.Message == "Sequence contains more than one element")
                {
                    throw new MultipleRecordsException("Multiple Participant records found! Only one participant allowed per Contact.");
                }
            }

            if (result == null)
            {
                return null;
            }
            var participant = new Participant
            {
                ContactId = result.ToInt("Contact_ID"),
                ParticipantId = result.ToInt("dp_RecordID"),
                EmailAddress = result.ToString("Email_Address"),
                PreferredName = result.ToString("Nickname"),
                DisplayName = result.ToString("Display_Name")
            };

            return participant;
        }
Exemplo n.º 3
0
        public GroupDTO getGroupDetails(int groupId, int contactId, Participant participant, string authUserToken)
        {
            int participantId = participant.ParticipantId;
            Group g = _mpGroupService.getGroupDetails(groupId);

            var signupRelations = _mpGroupService.GetGroupSignupRelations(g.GroupType);

            var currRelationships = _contactRelationshipService.GetMyCurrentRelationships(contactId, authUserToken);

            var events = _mpGroupService.getAllEventsForGroup(groupId);

            ContactRelationship[] familyToReturn = null;

            if (currRelationships != null)
            {
                familyToReturn = currRelationships.Where(
                    c => signupRelations.Select(s => s.RelationshipId).Contains(c.Relationship_Id)).ToArray();
            }

            var detail = new GroupDTO();
            {
                detail.GroupName = g.Name;
                detail.GroupId = g.GroupId;
                detail.GroupFullInd = g.Full;
                detail.WaitListInd = g.WaitList;
                detail.ChildCareAvailable = g.ChildCareAvailable;
                detail.WaitListGroupId = g.WaitListGroupId;
                detail.OnlineRsvpMinimumAge = g.MinimumAge;
                if (events != null)
                {
                    detail.Events = events.Select(Mapper.Map<MinistryPlatform.Models.Event, crds_angular.Models.Crossroads.Events.Event>).ToList();
                }
                //the first instance of family must always be the logged in user
                var fam = new SignUpFamilyMembers
                {
                    EmailAddress = participant.EmailAddress,
                    PreferredName = participant.PreferredName,
                    UserInGroup = _mpGroupService.checkIfUserInGroup(participantId, g.Participants),
                    ParticpantId = participantId,
                    ChildCareNeeded = false
                };
                detail.SignUpFamilyMembers = new List<SignUpFamilyMembers> {fam};

                if (familyToReturn != null)
                {
                    foreach (var f in familyToReturn)
                    {
                        var fm = new SignUpFamilyMembers
                        {
                            EmailAddress = f.Email_Address,
                            PreferredName = f.Preferred_Name,
                            UserInGroup = _mpGroupService.checkIfUserInGroup(f.Participant_Id, g.Participants),
                            ParticpantId = f.Participant_Id,
                        };
                        detail.SignUpFamilyMembers.Add(fm);
                    }
                }
            }

            return (detail);
        }
Exemplo n.º 4
0
        private Dictionary<string, object> HandleYesRsvp(Participant participant,
                                                         Event e,
                                                         int opportunityId,
                                                         IReadOnlyCollection<int> opportunityIds,
                                                         String token)
        {
            var templateId = AppSetting("RsvpYesTemplate");
            var deletedRSVPS = new List<int>();
            Opportunity 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}
            };
        }
Exemplo n.º 5
0
        private Dictionary<string, object> HandleNoRsvp(Participant participant,
                                                        Event e,
                                                        List<int> opportunityIds,
                                                        string token,
                                                        MyContact groupLeader)
        {
            int templateId;
            Opportunity 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}
            };
        }
        public void GetOpportunityResponseNoExistingRsvpTest()
        {
            //ARRANGE
            const int opportunityId = 8;
            const int eventId = 3;
            var participant = new Participant {ParticipantId = 5};

            // mock _ministryPlatformService.GetPageViewRecords
            const string viewKey = "ResponseByOpportunityAndEvent";
            var searchString = string.Format(",{0},{1},{2}", opportunityId, eventId, participant.ParticipantId);
            const string sortString = "";
            var mockResult = MockDictionaryGetOpportunityResponseNoExistingRsvpTest();
            _ministryPlatformService.Setup(
                m => m.GetPageViewRecords(viewKey, It.IsAny<string>(), searchString, sortString, 0)).Returns(mockResult);

            //ACT
            var response = _fixture.GetOpportunityResponse(opportunityId, eventId, participant);

            //ASSERT
            _ministryPlatformService.VerifyAll();

            Assert.IsNotNull(response);
            Assert.AreEqual(0, response.Opportunity_ID);
            Assert.AreEqual(0, response.Participant_ID);
            Assert.AreEqual(null, response.Response_Result_ID);
        }
Exemplo n.º 7
0
 private Dictionary<string, object> CreateRsvp(string token,
                                               int opportunityId,
                                               List<int> opportunityIds,
                                               bool signUp,
                                               Participant participant,
                                               Event @event,
                                               MyContact groupLeader)
 {
     var response = signUp
         ? HandleYesRsvp(participant, @event, opportunityId, opportunityIds, token)
         : HandleNoRsvp(participant, @event, opportunityIds, token, groupLeader);
     return response;
 }
Exemplo n.º 8
0
        private void SetUpRSVPMocks(int contactId, int eventTypeId, int opportunityId, bool signUp,
            List<Event> mockEvents)
        {
            var mockParticipant = new Participant
            {
                ParticipantId = 47
            };
            
            //mock it up
            _participantService.Setup(m => m.GetParticipant(contactId)).Returns(mockParticipant);
            _eventService.Setup(
                m =>
                    m.GetEventsByTypeForRange(eventTypeId, It.IsAny<DateTime>(), It.IsAny<DateTime>(),
                        It.IsAny<string>())).Returns(mockEvents);

            foreach (var mockEvent in mockEvents)
            {
                _eventService.Setup(m => m.RegisterParticipantForEvent(mockParticipant.ParticipantId, mockEvent.EventId, 0, 0));
                _opportunityService.Setup(
                    m =>
                        m.RespondToOpportunity(mockParticipant.ParticipantId, opportunityId, It.IsAny<string>(),
                            mockEvent.EventId, signUp));
            }
        }
Exemplo n.º 9
0
        private void SendConfirmation(int childcareEventId, Participant participant, IEnumerable<int> kids )
        {
            var templateId = _configurationWrapper.GetConfigIntValue("ChildcareConfirmationTemplate");
            var authorUserId = _configurationWrapper.GetConfigIntValue("DefaultUserAuthorId");
            var template = _communicationService.GetTemplate(templateId);
            var fromContact = _contactService.GetContactById(_configurationWrapper.GetConfigIntValue("DefaultContactEmailId"));
            const int domainId = 1;

            var childEvent = _eventService.GetEvent(childcareEventId);

            if (childEvent.ParentEventId == null)
            {
                throw new ApplicationException("SendConfirmation: Parent Event Not Found.");
            }
            var parentEventId = (int) childEvent.ParentEventId;

            var mergeData = SetConfirmationMergeData(parentEventId, kids);
            var replyToContact = ReplyToContact(childEvent);

            var communication = FormatCommunication(authorUserId, domainId, template, fromContact, replyToContact, participant.ContactId, participant.EmailAddress, mergeData);
            try
            {
                _communicationService.SendMessage(communication);
            }
            catch (Exception ex)
            {
                _logger.Error(string.Format("Send Childcare Confirmation email failed. Participant: {0}, Event: {1}", participant.ParticipantId, childcareEventId), ex);
            }
        }
        public int RespondToOpportunity(int participantId, int opportunityId, string comments, int eventId, bool response)
        {
            var participant = new Participant {ParticipantId = participantId};

            var values = new Dictionary<string, object>
            {
                {"Response_Date", DateTime.Now},
                {"Opportunity_ID", opportunityId},
                {"Participant_ID", participantId},
                {"Closed", false},
                {"Comments", comments},
                {"Event_ID", eventId},
                {"Response_Result_ID", (response) ? 1 : 2}
            };

            //Go see if there are existing responses for this opportunity that we are updating
            int recordId = 0;

            try
            {
                var prevResponse = GetOpportunityResponse(opportunityId, eventId, participant);
                if (prevResponse.Response_ID != 0)
                {
                    recordId = prevResponse.Response_ID;
                    values.Add("Response_ID", recordId);
                    _ministryPlatformService.UpdateRecord(_opportunityResponses, values, ApiLogin());
                }
                else
                {
                    WithApiLogin(apiToken => (_ministryPlatformService.CreateRecord("OpportunityResponses", values, apiToken, true)));
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(
                    string.Format("RespondToOpportunity failed.  Participant Id: {0}, Opportunity Id: {1}",
                                  participantId,
                                  opportunityId),
                    ex.InnerException);
            }
            return recordId;
        }
        public int DeleteResponseToOpportunities(int participantId, int opportunityId, int eventId)
        {
            var participant = new Participant {ParticipantId = participantId};

            try
            {
                var prevResponse = GetOpportunityResponse(opportunityId, eventId, participant);
                if (prevResponse.Response_ID != 0)
                {
                    _ministryPlatformService.DeleteRecord(_opportunityResponses, prevResponse.Response_ID, null, ApiLogin());
                    return prevResponse.Response_ID;
                }
                return 0;
            }
            catch (Exception ex)
            {
                throw new ApplicationException(
                    string.Format("Delete Response failed.  Participant Id: {0}, Opportunity Id: {1}",
                                  participantId,
                                  opportunityId),
                    ex.InnerException);
            }
        }
        public Response GetOpportunityResponse(int opportunityId, int eventId, Participant participant)
        {
            var searchString = string.Format(",{0},{1},{2}", opportunityId, eventId, participant.ParticipantId);
            List<Dictionary<string, object>> dictionaryList;
            try
            {
                dictionaryList =
                    WithApiLogin(
                        apiToken =>
                            (_ministryPlatformService.GetPageViewRecords("ResponseByOpportunityAndEvent",
                                                                         apiToken,
                                                                         searchString,
                                                                         "",
                                                                         0)));
            }
            catch (Exception ex)
            {
                throw new ApplicationException(
                    string.Format(
                        "GetOpportunityResponse failed.  Participant Id: {0}, Opportunity Id: {1}, Event Id: {2}",
                        participant,
                        opportunityId,
                        eventId),
                    ex.InnerException);
            }

            if (dictionaryList.Count == 0)
            {
                return new Response();
            }

            var response = new Response();
            try
            {
                var dictionary = dictionaryList.First();
                response.Response_ID = dictionary.ToInt("dp_RecordID");
                response.Opportunity_ID = dictionary.ToInt("Opportunity_ID");
                response.Participant_ID = dictionary.ToInt("Participant_ID");
                response.Response_Result_ID = dictionary.ToInt("Response_Result_ID");
            }
            catch (InvalidOperationException ex)
            {
                throw new ApplicationException(
                    string.Format("RespondToOpportunity failed.  Participant Id: {0}, Opportunity Id: {1}",
                                  participant,
                                  opportunityId),
                    ex.InnerException);
            }


            return response;
        }
Exemplo n.º 13
0
        public void testGetGroupDetails()
        {
            int groupId = 333;
            int contactId = 777;

            Group g = new Group();
            g.GroupId = 333;
            g.GroupType = 8;
            g.GroupRole = "Member";
            g.Name = "Test Me";
            g.GroupId = 123456;
            g.TargetSize = 5;
            g.WaitList = true;
            g.WaitListGroupId = 888;

            Participant participant = new Participant();
            participant.ParticipantId = 90210;
            participantServiceMock.Setup(
                mocked => mocked.GetParticipantRecord(fixture.Request.Headers.Authorization.ToString()))
                .Returns(participant);

            authenticationServiceMock.Setup(mocked => mocked.GetContactId(fixture.Request.Headers.Authorization.ToString())).Returns(contactId);

            var relationRecord = new GroupSignupRelationships
              {
                  RelationshipId = 1,
                  RelationshipMinAge = 00,
                  RelationshipMaxAge = 100
              };

            var groupDto = new GroupDTO
            {
            };

            groupServiceMock.Setup(mocked => mocked.getGroupDetails(groupId, contactId, participant, fixture.Request.Headers.Authorization.ToString())).Returns(groupDto);


            IHttpActionResult result = fixture.Get(groupId);
            Assert.IsNotNull(result);
            Assert.IsInstanceOf(typeof(OkNegotiatedContentResult<GroupDTO>), result);
            groupServiceMock.VerifyAll();

            var groupDtoResponse = ((OkNegotiatedContentResult<GroupDTO>)result).Content;

            Assert.NotNull(result);
            Assert.AreSame(groupDto, groupDtoResponse);
        }
Exemplo n.º 14
0
        public void testGetGroupDetails()
        {
            var g = new Group
            {
                TargetSize = 0,
                Full = true,
                Participants = new List<GroupParticipant>(),
                GroupType = 90210,
                WaitList = true,
                WaitListGroupId = 10101,
                GroupId = 98765
            };

            var eventList = new List<Event>()
            {
                EventHelpers.TranslationEvent()
            };

            groupService.Setup(mocked => mocked.getGroupDetails(456)).Returns(g);

            groupService.Setup(mocked => mocked.getAllEventsForGroup(456)).Returns(eventList);

            var relations = new List<GroupSignupRelationships>
            {
                new GroupSignupRelationships {RelationshipId = 111}
            };
            groupService.Setup(mocked => mocked.GetGroupSignupRelations(90210)).Returns(relations);

            var contactRelations = new List<ContactRelationship>
            {
                new ContactRelationship
                {
                    Contact_Id = 333,
                    Relationship_Id = 111,
                    Participant_Id = 222
                }
            };
            contactRelationshipService.Setup(mocked => mocked.GetMyCurrentRelationships(777, "auth token")).Returns(contactRelations);

            var participant = new Participant
            {
                ParticipantId = 555,
            };
            groupService.Setup(mocked => mocked.checkIfUserInGroup(555, It.IsAny<List<GroupParticipant>>())).Returns(false);
            groupService.Setup(mocked => mocked.checkIfUserInGroup(222, It.IsAny<List<GroupParticipant>>())).Returns(false);

            var response = fixture.getGroupDetails(456, 777, participant, "auth token");

            groupService.VerifyAll();
            contactRelationshipService.VerifyAll();

            Assert.IsNotNull(response);
            Assert.IsTrue(response.GroupFullInd);
            Assert.AreEqual(g.GroupId, response.GroupId);
            Assert.AreEqual(2, response.SignUpFamilyMembers.Count);
            Assert.AreEqual(g.WaitListGroupId, response.WaitListGroupId);
            Assert.AreEqual(g.WaitList, response.WaitListInd);
        }