public void SetUp()
        {
            _ministryPlatformService = new Mock<IMinistryPlatformService>();
            _authService = new Mock<IAuthenticationService>();
            _configWrapper = new Mock<IConfigurationWrapper>();
            _dbConnection = new Mock<IDbConnection>();

            _configWrapper.Setup(m => m.GetEnvironmentVarAsString("API_USER")).Returns("uid");
            _configWrapper.Setup(m => m.GetEnvironmentVarAsString("API_PASSWORD")).Returns("pwd");
            _authService.Setup(m => m.Authenticate(It.IsAny<string>(), It.IsAny<string>())).Returns(new Dictionary<string, object> { { "token", "ABC" }, { "exp", "123" } });

            _fixture = new FormSubmissionService(_ministryPlatformService.Object, _dbConnection.Object, _authService.Object, _configWrapper.Object);

            _mockAnswer1 = new FormAnswer
            {
                FieldId = 375,
                FormResponseId = responseId,
                OpportunityResponseId = 7329,
                Response = "Test Last Name"
            };

            _mockAnswer2 = new FormAnswer
            {
                FieldId = 376,
                FormResponseId = responseId,
                OpportunityResponseId = 7329,
                Response = "Test First Name"
            };

            _mockAnswer3 = new FormAnswer
            {
                FieldId = 377,
                FormResponseId = responseId,
                OpportunityResponseId = 7329,
                Response = "Test Middle Initial"
            };

            _mockForm = new FormResponse
            {
                FormId = 17,
                ContactId = 2389887,
                OpportunityId = 313,
                OpportunityResponseId = 7329,
                FormAnswers = new List<FormAnswer>
                {
                    _mockAnswer1,
                    _mockAnswer2,
                    _mockAnswer3
                }
            };
        }
        private int CreateFormResponse(FormResponse formResponse, string token)
        {
            var record = new Dictionary<string, object>
            {
                {"Form_ID", formResponse.FormId},
                {"Response_Date", DateTime.Today},
                {"Contact_ID", formResponse.ContactId},
                {"Opportunity_ID",  formResponse.OpportunityId },
                {"Opportunity_Response", formResponse.OpportunityResponseId},
                {"Pledge_Campaign_ID", formResponse.PledgeCampaignId}
            };

            var responseId = _ministryPlatformService.CreateRecord(_formResponsePageId, record, token, true);
            return responseId;
        }
 public int SubmitFormResponse(FormResponse form)
 {
     var token = ApiLogin();
     var responseId = CreateFormResponse(form, token);
     foreach (var answer in form.FormAnswers)
     {
         if (answer.Response != null)
         {
             answer.FormResponseId = responseId;
             CreateFormAnswer(answer, token);
         }
     }
     return responseId;
 }
        public bool SaveAdult(AdultApplicationDto application)
        {
            var formId = _configurationWrapper.GetConfigIntValue("KidsClubAdultApplicant");
            var opportunityResponseId = application.ResponseOpportunityId;
            _formFields = _formSubmissionService.GetFieldsForForm(formId);

            var formResponse = new FormResponse();
            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;
        }
        public bool SaveStudent(StudentApplicationDto application)
        {
            var formId = _configurationWrapper.GetConfigIntValue("KidsClubStudentApplicant");
            var opportunityResponseId = application.ResponseOpportunityId;
            _formFields = _formSubmissionService.GetFieldsForForm(formId);

            var formResponse = new FormResponse();
            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(TranslateGender(application.Gender), opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.NameForNameTag, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.School, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.HowLongAttending, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.ServiceAttend, 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.HomePhone, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.MobilePhone, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.Grade, 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.ExplainFaith, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.WhyServe, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.SpecialTalents, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.AvailabilityDuringWeek, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.AvailabilityDuringWeekend, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.AvailabilityWeekendSite, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.ServeAgeKids1To2, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.ServeAgeKids3ToPreK, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.ServeAgeKidsKto5Grade, 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.ParentLastName, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.ParentFirstName, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.ParentHomePhone, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.ParentMobilePhone, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.ParentEmail, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.ParentSignature, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.ParentSignatureDate, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.StudentSignature, opportunityResponseId));
            formResponse.FormAnswers.Add(SetCustomField(application.StudentSignatureDate, opportunityResponseId));

            var response = _formSubmissionService.SubmitFormResponse(formResponse);
            return response != 0;
        }
示例#6
0
        public int SaveApplication(TripApplicationDto dto)
        {
            try
            {
                UpdateChildSponsorship(dto);
                var formResponse = new FormResponse();
                formResponse.ContactId = dto.ContactId; //contact id of the person the application is for
                formResponse.FormId = _configurationWrapper.GetConfigIntValue("TripApplicationFormId");
                formResponse.PledgeCampaignId = dto.PledgeCampaignId;

                formResponse.FormAnswers = new List<FormAnswer>(FormatFormAnswers(dto));

                var formResponseId = _formSubmissionService.SubmitFormResponse(formResponse);

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

                SendTripApplicantSuccessMessage(dto.ContactId);

                return formResponseId;
            }
            catch (Exception ex)
            {
                // send applicant message
                SendApplicantErrorMessage(dto.ContactId);

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

                //then re-throw or eat it?
                return 0;
            }
        }