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); } }
private void SendTripApplicantDonationComboMessage(TripApplicationDto dto) { var pledgeCampaign = _campaignService.GetPledgeCampaign(dto.PledgeCampaignId); var program = _programRepository.GetProgramById(pledgeCampaign.ProgramId); var mergeData = new Dictionary <string, object> { { "Destination_Name", pledgeCampaign.Nickname }, { "Program_Name", program.Name }, { "Donation_Amount", dto.DepositInformation.DonationAmount ?? "" }, { "Donation_Date", dto.DepositInformation.DonationDate ?? "" }, { "Payment_Method", dto.DepositInformation.PaymentMethod } }; SendMessage("TripAppAndDonationComboMessageTemplateId", dto.ContactId, mergeData); }
public IHttpActionResult Save([FromBody] TripApplicationDto dto) { if (!ModelState.IsValid) { var errors = ModelState.Values.SelectMany(val => val.Errors).Aggregate("", (current, err) => current + err.Exception.Message); var dataError = new ApiErrorDto("Save Trip Application Data Invalid", new InvalidOperationException("Invalid Save Data" + errors)); throw new HttpResponseException(dataError.HttpResponseMessage); } TripApplicationResponseDto response; try { var participantPledgeInfo = _tripService.CreateTripParticipant(dto.ContactId, dto.PledgeCampaignId); var message = _messageFactory.CreateMessage(dto); _eventQueue.Send(message, MessageQueueTransactionType.None); response = new TripApplicationResponseDto { Message = "Queued event for asynchronous processing", DepositAmount = participantPledgeInfo.Deposit, DonorId = participantPledgeInfo.DonorId, ProgramId = participantPledgeInfo.ProgramId, ProgramName = participantPledgeInfo.ProgramName }; new Task(() => { _tripService.SendTripIsFullMessage(dto.PledgeCampaignId); }).Start(); } catch (TripFullException e) { var json = JsonConvert.SerializeObject(e.Message, Formatting.None); var message = new HttpResponseMessage(HttpStatusCode.Conflict); message.Content = new StringContent(json); throw new HttpResponseException(message); } catch (Exception e) { const string msg = "Unexpected error processing Trip Application Save"; var responseDto = new TripApplicationResponseDto() { Exception = new ApplicationException(msg, e), Message = msg }; return(RestHttpActionResult <TripApplicationResponseDto> .ServerError(responseDto)); } return((IHttpActionResult)RestHttpActionResult <TripApplicationResponseDto> .Ok(response)); }
private int GetChildId(TripApplicationDto dto, Func <SponsoredChild, int> createChild) { var child = _contactService.GetContactByIdCard(dto.PageFive.SponsorChildNumber); if (child != null) { return(child.Contact_ID); } var sponsoredChild = new SponsoredChild { FirstName = dto.PageFive.SponsorChildFirstName, LastName = dto.PageFive.SponsorChildLastName, IdNumber = dto.PageFive.SponsorChildNumber, Town = dto.PageFive.SponsorChildTown }; return(createChild(sponsoredChild)); }
private void UpdateChildSponsorship(TripApplicationDto dto) { if (!RequireSponsoredChild(dto.PageFive)) { return; } var childId = GetChildId(dto, (child) => { try { return(_contactService.CreateContactForSponsoredChild(child.FirstName, child.LastName, child.Town, child.IdNumber)); } catch (ApplicationException e) { _logger.Error("Unable to create the sponsored child: " + e.Message); return(-1); } }); if (childId == -1) { return; } // Check if relationship exists... var myRelationships = _contactRelationshipService.GetMyCurrentRelationships(dto.ContactId); var rel = myRelationships.Where(r => r.RelationshipID == _configurationWrapper.GetConfigIntValue("SponsoredChild") && r.RelatedContactID == childId); if (rel.Any()) { return; } // Update the relationship var relationship = new MpRelationship { RelationshipID = _configurationWrapper.GetConfigIntValue("SponsoredChild"), RelatedContactID = childId, StartDate = DateTime.Today }; _contactRelationshipService.AddRelationship(relationship, dto.ContactId); }
private IEnumerable <MpFormAnswer> FormatFormAnswers(TripApplicationDto applicationData) { var answers = new List <MpFormAnswer>(); var page2 = applicationData.PageTwo; answers.Add(new MpFormAnswer { Response = page2.Allergies, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.Allergies") }); answers.Add(new MpFormAnswer { Response = page2.GuardianFirstName, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.GuardianFirstName") }); answers.Add(new MpFormAnswer { Response = page2.GuardianLastName, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.GuardianLastName") }); answers.Add(new MpFormAnswer { Response = page2.Referral, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.Referral") }); answers.Add(new MpFormAnswer { Response = page2.Why, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.Why") }); var page3 = applicationData.PageThree; answers.Add(new MpFormAnswer { Response = page3.Conditions, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.Conditions") }); answers.Add(new MpFormAnswer { Response = page3.EmergencyContactEmail, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.EmergencyContactEmail") }); answers.Add(new MpFormAnswer { Response = page3.EmergencyContactFirstName, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.EmergencyContactFirstName") }); answers.Add(new MpFormAnswer { Response = page3.EmergencyContactLastName, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.EmergencyContactLastName") }); answers.Add(new MpFormAnswer { Response = page3.EmergencyContactPrimaryPhone, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.EmergencyContactPrimaryPhone") }); answers.Add(new MpFormAnswer { Response = page3.EmergencyContactRelationship, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.EmergencyContactRelationship") }); answers.Add(new MpFormAnswer { Response = page3.EmergencyContactSecondaryPhone, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.EmergencyContactSecondaryPhone") }); var page4 = applicationData.PageFour; answers.Add(new MpFormAnswer { Response = page4.GroupCommonName, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.GroupCommonName") }); answers.Add(new MpFormAnswer { Response = page4.InterestedInGroupLeader, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.InterestedInGroupLeader") }); answers.Add(new MpFormAnswer { Response = page4.RoommateFirstChoice, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.RoommateFirstChoice") }); answers.Add(new MpFormAnswer { Response = page4.RoommateSecondChoice, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.RoommateSecondChoice") }); answers.Add(new MpFormAnswer { Response = page4.SupportPersonEmail, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.SupportPersonEmail") }); answers.Add(new MpFormAnswer { Response = page4.WhyGroupLeader, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.WhyGroupLeader") }); var page5 = applicationData.PageFive; answers.Add(new MpFormAnswer { Response = page5.NolaFirstChoiceWorkTeam, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.FirstChoiceWorkTeam") }); answers.Add(new MpFormAnswer { Response = page5.NolaFirstChoiceExperience, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.FirstChoiceWorkTeamExperience") }); answers.Add(new MpFormAnswer { Response = page5.NolaSecondChoiceWorkTeam, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.SecondChoiceWorkTeam") }); var page6 = applicationData.PageSix; answers.Add(new MpFormAnswer { Response = page6.DescribeExperienceAbroad, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.DescribeExperienceAbroad") }); answers.Add(new MpFormAnswer { Response = page6.ExperienceAbroad, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.ExperienceAbroad") }); answers.Add(new MpFormAnswer { Response = page6.InternationalTravelExpericence, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.InternationalTravelExpericence") }); answers.Add(new MpFormAnswer { Response = page6.PassportNumber, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.PassportNumber") }); answers.Add(new MpFormAnswer { Response = page6.PassportCountry, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.PassportCountry") }); answers.Add(new MpFormAnswer { Response = page6.PassportExpirationDate, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.PassportExpirationDate") }); answers.Add(new MpFormAnswer { Response = page6.PassportFirstName, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.PassportFirstName") }); answers.Add(new MpFormAnswer { Response = page6.PassportLastName, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.PassportLastName") }); answers.Add(new MpFormAnswer { Response = page6.PassportMiddleName, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.PassportMiddleName") }); answers.Add(new MpFormAnswer { Response = page6.PastAbuseHistory, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.PastAbuseHistory") }); answers.Add(new MpFormAnswer { Response = page6.ValidPassport, FieldId = _configurationWrapper.GetConfigIntValue("TripForm.ValidPassport") }); return(answers); }
private TripApplicationDto mockTripApplication(int contactid, int pledgeid) { var depositInfo = new TripApplicationDto.ApplicationDepositInformation(); depositInfo.DonationAmount = "300"; depositInfo.DonationDate = "1/1/2011"; depositInfo.PaymentMethod = "Bank"; var pageTwo = new TripApplicationDto.ApplicationPageTwo(); pageTwo.Allergies = ""; pageTwo.GuardianFirstName = "Bob"; pageTwo.GuardianLastName = "Smith"; pageTwo.Referral = ""; pageTwo.ScrubSizeBottom = "S"; pageTwo.ScrubSizeTop = "S"; pageTwo.SpiritualLife = new string[] { "" }; pageTwo.Why = ""; var pageThree = new TripApplicationDto.ApplicationPageThree(); pageThree.EmergencyContactEmail = "*****@*****.**"; pageThree.EmergencyContactFirstName = "bob"; pageThree.EmergencyContactLastName = "roberts"; pageThree.EmergencyContactPrimaryPhone = "888-888-8888"; pageThree.EmergencyContactSecondaryPhone = "555-555-5555"; pageThree.Conditions = ""; var pageFour = new TripApplicationDto.ApplicationPageFour(); pageFour.GroupCommonName = "group name"; pageFour.InterestedInGroupLeader = "No"; pageFour.RoommateFirstChoice = "Pete Rose"; pageFour.RoommateSecondChoice = "Bill Clinton"; pageFour.SupportPersonEmail = "*****@*****.**"; pageFour.WhyGroupLeader = ""; var pageFive = new TripApplicationDto.ApplicationPageFive(); pageFive.NolaFirstChoiceExperience = "first choice"; pageFive.NolaFirstChoiceWorkTeam = "first work team"; pageFive.NolaSecondChoiceWorkTeam = "second work team"; pageFive.SponsorChildFirstName = "Suzy"; pageFive.SponsorChildLastName = "Sponserchild"; pageFive.SponsorChildNumber = "99"; pageFive.SponsorChildTown = "Townville"; var pageSix = new TripApplicationDto.ApplicationPageSix(); pageSix.DescribeExperienceAbroad = "None"; pageSix.ExperienceAbroad = "None"; pageSix.FrequentFlyers = new string[] { "" }; pageSix.InternationalTravelExpericence = "NA"; pageSix.PassportCountry = ""; pageSix.PassportExpirationDate = ""; pageSix.PassportFirstName = ""; pageSix.PassportLastName = ""; pageSix.PassportMiddleName = ""; pageSix.PassportNumber = ""; pageSix.PastAbuseHistory = "None"; var dto = new TripApplicationDto(); dto.ContactId = contactid; dto.PledgeCampaignId = pledgeid; dto.InviteGUID = ""; dto.DepositInformation = depositInfo; dto.PageTwo = pageTwo; dto.PageThree = pageThree; dto.PageFour = pageFour; dto.PageFive = pageFive; dto.PageSix = pageSix; return(dto); }