예제 #1
0
        public void ShouldCreateAFormResponseWithAnEventId()
        {
            const int recordId     = 43;
            var       formResponse = new MpFormResponse
            {
                ContactId   = 123456,
                EventId     = 8976,
                FormAnswers = new List <MpFormAnswer>(),
                FormId      = 3333
            };

            var record = new Dictionary <string, object>
            {
                { "Form_ID", formResponse.FormId },
                { "Response_Date", DateTime.Now },
                { "Contact_ID", formResponse.ContactId },
                { "Opportunity_ID", formResponse.OpportunityId },
                { "Opportunity_Response", formResponse.OpportunityResponseId },
                { "Pledge_Campaign_ID", formResponse.PledgeCampaignId },
                { "Event_ID", formResponse.EventId }
            };

            var          searchString  = $"Contact_ID={formResponse.ContactId} AND Form_ID={formResponse.FormId} AND Event_ID={formResponse.EventId}";
            const string selectColumns = "Form_Response_ID";

            _ministryPlatformRestRepository.Setup(m => m.UsingAuthenticationToken(apiToken)).Returns(_ministryPlatformRestRepository.Object);
            _ministryPlatformRestRepository.Setup(m => m.Search <MpFormResponse>(It.IsAny <string>(), It.IsAny <string>(), null, true)).Returns((string filter, string column, string orderby, bool distinct) =>
            {
                Assert.AreEqual(searchString, filter);
                Assert.AreEqual(selectColumns, column);
                return(new List <MpFormResponse>());
            });
            _ministryPlatformService.Setup(m => m.CreateRecord(It.IsAny <int>(), It.IsAny <Dictionary <string, object> >(), apiToken, true))
            .Returns((int formRId, Dictionary <string, object> data, string token, bool quickAdd) =>
            {
                Assert.AreEqual(record["Event_ID"], data["Event_ID"]);
                return(recordId);
            });

            var result = _fixture.SubmitFormResponse(formResponse);

            _ministryPlatformService.VerifyAll();

            _authenticationRepository.VerifyAll();
            _ministryPlatformRestRepository.VerifyAll();

            Assert.AreEqual(recordId, result);
        }
예제 #2
0
        public IObservable <int> SaveReferences(GroupLeaderProfileDTO leader)
        {
            var form = new MpFormResponse
            {
                ContactId   = leader.ContactId,
                FormId      = _configWrapper.GetConfigIntValue("GroupLeaderFormId"),
                FormAnswers = new List <MpFormAnswer>
                {
                    new MpFormAnswer
                    {
                        FieldId  = _configWrapper.GetConfigIntValue("GroupLeaderReferenceFieldId"),
                        Response = leader.ReferenceContactId
                    },
                    new MpFormAnswer
                    {
                        FieldId  = _configWrapper.GetConfigIntValue("GroupLeaderReferenceNameFieldId"),
                        Response = leader.ReferenceDisplayName ?? ""
                    },
                    new MpFormAnswer
                    {
                        FieldId  = _configWrapper.GetConfigIntValue("GroupLeaderHuddleFieldId"),
                        Response = leader.HuddleResponse
                    },
                    new MpFormAnswer
                    {
                        FieldId  = _configWrapper.GetConfigIntValue("GroupLeaderStudentFieldId"),
                        Response = leader.LeadStudents
                    }
                }
            };

            return(Observable.Create <int>(observer =>
            {
                var responseId = _formSubmissionRepository.SubmitFormResponse(form);
                if (responseId == 0)
                {
                    observer.OnError(new ApplicationException("Unable to submit form response for Group Leader"));
                }
                observer.OnNext(responseId);
                observer.OnCompleted();
                return Disposable.Create(() => Console.WriteLine("Observable destroyed"));
            }));
        }
예제 #3
0
        public int SaveApplication(TripApplicationDto dto)
        {
            try
            {
                UpdateChildSponsorship(dto);
                var formResponse = new MpFormResponse
                {
                    ContactId        = dto.ContactId, //contact id of the person the application is for
                    FormId           = _configurationWrapper.GetConfigIntValue("TripApplicationFormId"),
                    PledgeCampaignId = dto.PledgeCampaignId,
                    FormAnswers      = new List <MpFormAnswer>(FormatFormAnswers(dto))
                };

                var formResponseId = _formSubmissionService.SubmitFormResponse(formResponse);

                if (dto.InviteGUID != null)
                {
                    _privateInviteService.MarkAsUsed(dto.PledgeCampaignId, dto.InviteGUID);
                }

                if (HasScholarship(dto.ContactId, dto.PledgeCampaignId))
                {
                    SendTripApplicantSuccessMessage(dto.ContactId);
                }
                else
                {
                    SendTripApplicantDonationComboMessage(dto);
                }

                _logger.Info($"SaveApplication success: ContactId = {dto.ContactId}, PledgeCampaignId = {dto.PledgeCampaignId}");

                return(formResponseId);
            }
            catch (Exception ex)
            {
                // add exception to error log
                _logger.Error($"SaveApplication exception: ContactId = {dto.ContactId}, PledgeCampaignId = {dto.PledgeCampaignId}", ex);

                // include form data in error log (serialized json); ignore exceptions during serialization
                JsonSerializerSettings settings = new JsonSerializerSettings();
                settings.Error = (serializer, err) => err.ErrorContext.Handled = true;
                string json = JsonConvert.SerializeObject(dto, settings);
                _logger.Error($"SaveApplication data {json}");

                // send applicant message
                SendApplicantErrorMessage(dto.ContactId);

                // send trip admin message
                SendTripAdminErrorMessage(dto.PledgeCampaignId);

                //then re-throw or eat it?
                return(0);
            }
        }
예제 #4
0
        public bool SaveAdult(AdultApplicationDto application)
        {
            var formId = _configurationWrapper.GetConfigIntValue("KidsClubAdultApplicant");
            var opportunityResponseId = application.ResponseOpportunityId;

            _formFields = _formSubmissionService.GetFieldsForForm(formId);

            var formResponse = new MpFormResponse();

            formResponse.ContactId             = application.ContactId;     //contact id of the person the application is for
            formResponse.FormId                = formId;
            formResponse.OpportunityId         = application.OpportunityId; // we know this from CMS
            formResponse.OpportunityResponseId = opportunityResponseId;

            formResponse.FormAnswers.Add(SetCustomField(application.FirstName, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.LastName, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.MiddleInitial, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Email, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.BirthDate, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.PreviousName, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.NameForNameTag, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(TranslateGender(application.Gender), opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(TranslateMaritalStatus(application.MaritalStatus),
                                                        opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.SpouseName, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.SpouseGender, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.HowLongAttending, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.WhatServiceDoYouAttend, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.StreetAddress, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.City, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.State, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Zip, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.MobilePhone, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.HomePhone, opportunityResponseId));

            formResponse.FormAnswers.Add(SetCustomField(application.CompanyName, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Position, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.WorkPhone, opportunityResponseId));

            formResponse.FormAnswers.Add(SetCustomField(application.Child1Name, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Child1Birthdate, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Child2Name, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Child2Birthdate, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Child3Name, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Child3Birthdate, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Child4Name, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Child4Birthdate, opportunityResponseId));

            formResponse.FormAnswers.Add(SetCustomField(application.EverBeenArrest, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.AddictionConcern, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.NeglectingChild, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.PsychiatricDisorder, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.SexuallyActiveOutsideMarriage, opportunityResponseId));

            formResponse.FormAnswers.Add(SetCustomField(application.ReligionSearchingForAnswers, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.ReligionReceivedJesus, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.ReligionFocusingOnObedience, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.ReligionReplicating, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.SpiritualOrientationExplain, opportunityResponseId));

            formResponse.FormAnswers.Add(SetCustomField(application.WhatPromptedApplication, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.SpecialTalents, opportunityResponseId));


            formResponse.FormAnswers.Add(SetCustomField(application.AvailabilityWeek, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.AvailabilityWeekend, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.AvailabilityWeekendSite, opportunityResponseId));

            formResponse.FormAnswers.Add(SetCustomField(application.AreaOfInterestServingInClassroom,
                                                        opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.AreaOfInterestWelcomingNewFamilies,
                                                        opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.AreaOfInterestHelpSpecialNeeds,
                                                        opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.AreaOfInterestTech, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.AreaOfInterestRoomPrep, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.AreaOfInterestAdminTasks, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.AreaOfInterestShoppingForSupplies,
                                                        opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.AreaOfInterestCreatingWeekendExperience,
                                                        opportunityResponseId));

            formResponse.FormAnswers.Add(SetCustomField(application.WhatAgeBirthToTwo, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.WhatAgeThreeToPreK, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.WhatAgeKToFifth, opportunityResponseId));

            formResponse.FormAnswers.Add(SetCustomField(application.Reference1Name, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Reference1TimeKnown, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Reference1HomePhone, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Reference1MobilePhone, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Reference1WorkPhone, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Reference1Email, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Reference1Association, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Reference1Occupation, opportunityResponseId));

            formResponse.FormAnswers.Add(SetCustomField(application.Reference2Name, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Reference2TimeKnown, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Reference2HomePhone, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Reference2MobilePhone, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Reference2WorkPhone, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Reference2Email, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Reference2Association, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Reference2Occupation, opportunityResponseId));

            formResponse.FormAnswers.Add(SetCustomField(application.Reference3Name, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Reference3TimeKnown, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Reference3HomePhone, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Reference3MobilePhone, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Reference3WorkPhone, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Reference3Email, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Reference3Association, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Reference3Occupation, opportunityResponseId));

            formResponse.FormAnswers.Add(SetCustomField(application.Agree, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.AgreeDate, opportunityResponseId));

            var response = _formSubmissionService.SubmitFormResponse(formResponse);

            return(response != 0);
        }
예제 #5
0
        public void SaveCamperEmergencyContactInfo(List <CampEmergencyContactDTO> emergencyContacts, int eventId, int contactId, string token)
        {
            var loggedInContact = _contactRepository.GetMyProfile(token);
            var family          = _contactRepository.GetHouseholdFamilyMembers(loggedInContact.Household_ID);

            family.AddRange(_contactRepository.GetOtherHouseholdMembers(loggedInContact.Household_ID));

            if (family.Where(f => f.ContactId == contactId).ToList().Count <= 0)
            {
                throw new ContactNotFoundException(contactId);
            }

            var participant        = _participantRepository.GetParticipant(contactId);
            var eventParticipantId = _eventRepository.SafeRegisterParticipant(eventId, participant.ParticipantId);
            var answers            = new List <MpFormAnswer>();

            if (emergencyContacts.Count == 1)
            {
                var existingEmergencyContacts = GetCamperEmergencyContactInfo(eventId, contactId, token);
                if (existingEmergencyContacts.Count > 1)
                {
                    emergencyContacts.Add(new CampEmergencyContactDTO
                    {
                        Email                   = "",
                        FirstName               = "",
                        LastName                = "",
                        MobileNumber            = "",
                        PrimaryEmergencyContact = false,
                        Relationship            = ""
                    });
                }
            }

            foreach (var emergencyContact in emergencyContacts)
            {
                answers.AddRange(new List <MpFormAnswer>
                {
                    new MpFormAnswer
                    {
                        Response           = emergencyContact.FirstName,
                        FieldId            = emergencyContact.PrimaryEmergencyContact ? _configurationWrapper.GetConfigIntValue("SummerCampForm.EmergencyContactFirstName") : _configurationWrapper.GetConfigIntValue("SummerCampForm.AdditionalEmergencyContactFirstName"),
                        EventParticipantId = eventParticipantId
                    },
                    new MpFormAnswer
                    {
                        Response           = emergencyContact.LastName,
                        FieldId            = emergencyContact.PrimaryEmergencyContact ? _configurationWrapper.GetConfigIntValue("SummerCampForm.EmergencyContactLastName") : _configurationWrapper.GetConfigIntValue("SummerCampForm.AdditionalEmergencyContactLastName"),
                        EventParticipantId = eventParticipantId
                    },
                    new MpFormAnswer
                    {
                        Response           = emergencyContact.MobileNumber,
                        FieldId            = emergencyContact.PrimaryEmergencyContact ? _configurationWrapper.GetConfigIntValue("SummerCampForm.EmergencyContactMobilePhone") : _configurationWrapper.GetConfigIntValue("SummerCampForm.AdditionalEmergencyContactMobilePhone"),
                        EventParticipantId = eventParticipantId
                    },
                    new MpFormAnswer
                    {
                        Response           = emergencyContact.Email,
                        FieldId            = emergencyContact.PrimaryEmergencyContact ? _configurationWrapper.GetConfigIntValue("SummerCampForm.EmergencyContactEmail") : _configurationWrapper.GetConfigIntValue("SummerCampForm.AdditionalEmergencyContactEmail"),
                        EventParticipantId = eventParticipantId
                    },
                    new MpFormAnswer
                    {
                        Response           = emergencyContact.Relationship,
                        FieldId            = emergencyContact.PrimaryEmergencyContact ? _configurationWrapper.GetConfigIntValue("SummerCampForm.EmergencyContactRelationship") : _configurationWrapper.GetConfigIntValue("SummerCampForm.AdditionalEmergencyContactRelationship"),
                        EventParticipantId = eventParticipantId
                    }
                });
            }

            var formId       = _configurationWrapper.GetConfigIntValue("SummerCampFormID");
            var formResponse = new MpFormResponse
            {
                ContactId   = contactId,
                FormId      = formId,
                FormAnswers = answers,
                EventId     = eventId
            };

            _formSubmissionRepository.SubmitFormResponse(formResponse);
        }