From ac04fa1419e0cef305b7fa4bbf6bf6c64d8051a0 Mon Sep 17 00:00:00 2001 From: dan Date: Wed, 24 Jul 2019 22:41:46 -0600 Subject: [PATCH] Send missionary form after adding --- .../Controllers/MissionaryController.cs | 11 +- OFBButte.Api/appsettings.Development.json | 3 +- OFBButte.Api/appsettings.Production.json | 3 +- OFBButte.Api/appsettings.json | 3 +- .../Configuration/AppSettings.cs | 1 + .../Templates/MissionarySupportForm.html | 360 +++++++++++++++++- .../Email/Templates/base.html | 5 + .../Missionary/AddAndSendMissionaryForm.cs | 7 +- .../Missionary/SendMissionaryFormEmail.cs | 5 +- OFBButte.Entities/MissionarySupport.cs | 42 +- 10 files changed, 428 insertions(+), 12 deletions(-) diff --git a/OFBButte.Api/Controllers/MissionaryController.cs b/OFBButte.Api/Controllers/MissionaryController.cs index 2a9322c..494ee3d 100644 --- a/OFBButte.Api/Controllers/MissionaryController.cs +++ b/OFBButte.Api/Controllers/MissionaryController.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Options; using OFBButte.Application.Configuration; using OFBButte.Application.Database; +using OFBButte.Application.Email; using OFBButte.Application.Missionary; using OFBButte.Entities; @@ -18,17 +19,19 @@ namespace OFBButte.Api.Controllers { private readonly AppSettings appSettings; private readonly IOFBContext context; - public MissionaryController(IOptions options, IOFBContext context) + private readonly IEmailSender emailSender; + public MissionaryController(IOptions options, IOFBContext context, IEmailSender emailSender) { this.appSettings = options.Value; this.context = context; + this.emailSender = emailSender; } [HttpPost] - public ActionResult Post([FromBody] MissionarySupport value) + public async Task> Post([FromBody] MissionarySupport value) { - var adder = new AddMissionarySupportForm(context); - var result = adder.Handle(value); + var adder = new AddAndSendMissionaryForm(context, emailSender); + var result = await adder.Handle(value, appSettings.MissionaryEmailAddress); return result; } diff --git a/OFBButte.Api/appsettings.Development.json b/OFBButte.Api/appsettings.Development.json index f67631e..617f38a 100644 --- a/OFBButte.Api/appsettings.Development.json +++ b/OFBButte.Api/appsettings.Development.json @@ -7,7 +7,8 @@ } }, "App": { - "Environment": "Dev" + "Environment": "Dev", + "MissionaryEmailAddress": "admin@oldfashionbaptistbutte.com" }, "ConnectionStrings": { "OFBContext": "server=localhost;database=ofb2_test;user=ofbapi2_test;password=Look to the LORD and his strength seek his face always" diff --git a/OFBButte.Api/appsettings.Production.json b/OFBButte.Api/appsettings.Production.json index 427d4c5..44616e1 100644 --- a/OFBButte.Api/appsettings.Production.json +++ b/OFBButte.Api/appsettings.Production.json @@ -1,6 +1,7 @@ { "App": { - "Environment": "Prod" + "Environment": "Prod", + "MissionaryEmailAddress": "admin@oldfashionbaptistbutte.com" }, "ConnectionStrings": { "OFBContext": "server=localhost;database=ofb2;user=ofbapi2;password={{db_pass}};" diff --git a/OFBButte.Api/appsettings.json b/OFBButte.Api/appsettings.json index f0df150..3e63b15 100644 --- a/OFBButte.Api/appsettings.json +++ b/OFBButte.Api/appsettings.json @@ -8,7 +8,8 @@ }, "AllowedHosts": "*", "App": { - "Environment": "Local" + "Environment": "Local", + "MissionaryEmailAddress": "admin@oldfashionbaptistbutte.com" }, "ConnectionStrings": { "OFBContext": "" diff --git a/OFBButte.Application/Configuration/AppSettings.cs b/OFBButte.Application/Configuration/AppSettings.cs index 515f98c..2d42fee 100644 --- a/OFBButte.Application/Configuration/AppSettings.cs +++ b/OFBButte.Application/Configuration/AppSettings.cs @@ -7,5 +7,6 @@ namespace OFBButte.Application.Configuration public class AppSettings { public string Environment { get; set; } + public string MissionaryEmailAddress { get; set; } } } diff --git a/OFBButte.Application/Email/Templates/MissionarySupportForm.html b/OFBButte.Application/Email/Templates/MissionarySupportForm.html index 7117b89..fe1ddf2 100644 --- a/OFBButte.Application/Email/Templates/MissionarySupportForm.html +++ b/OFBButte.Application/Email/Templates/MissionarySupportForm.html @@ -1,2 +1,360 @@  -

This is a test missionary form

\ No newline at end of file + + +

Old Fashion Baptist Church Missionary Questionnaire

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Name
{{Name}}
Wifes Name
{{WifesName}}
Home Phone
{{HomePhone}}
Cell Phone
{{CellPhone}}
Field Phone
{{FieldPhone}}
Child Names
{{ChildNames}}
Testimony
{{Testimony}}
Call to Field
{{CallToField}}
Sending Church
{{SendingChurch}}
Planned Field of Service
{{FieldOfService}}
What do your plans include?
{{Plans}}
What is your evaluation of the nationals you are trying to reach, spiritually and culturally?
{{EvaluationOfNationals}}
How long have you been in this country?
{{TimeInCountry}}
If you knew that a fellow missionary was doing wrong or something quesstionable, what would be your course of action?
{{CorrectWrongOfAnotherMissionary}}
Would you submit a general financial statement for the past year?
{{FinancialStatementPrevYear}}
What is your total monthly support (peronal, work fund, etc)?
{{CurrentMonthlySupport}}
How much monthly support do you calculate you will need?
{{MonthlySupportNeeded}}
Are you diligent to have "Rest and Relaxation" during your stay on the field? Do you have a set time and plan for such necessary refreshing?
{{RestAndRelaxation}}
Do you plan to work alone or as a team? What are your feelings about the team concept?
{{AloneOrTeam}}
Type of School for Children
{{ChildrenSchool}}
Do you or any of your family ever dance?
{{Dance}}
Do you or any of your family ever listen to worldly music in your home?
{{WorldlyMusic}}
Do you or any of your family ever attend public movie theaters?
{{MovieTheaters}}
Do you or any of your family ever use any type of alcoholic beverage?
{{Alcohol}}
Do you or any of your family ever engage in any unclean habit such as smoking?
{{Smoking}}
If there are boys in your home, do they follow the same hair standard you follow?
{{MaleHair}}
Does your wife wear slacks in public?
{{FemaleSlacks}}
Does your wife wear shorts in public?
{{FemaleShorts}}
Do the girls in your family follow the same dress standard your wife does?
{{FemaleDressStandard}}
What do you do for clothing when you go swimming?
{{SwimmingClothing}}
How do you feel about having a television in the home?
{{Television}}
Do you MAKE time daily for Bible Reading and Prayer?
{{DailyBible}}
Outside of the church services where you have ministered, estimate how many people you have personally won to Christ in the last six months.
{{NumberLedToChrist}}
How many people have you personally witnessed to?
{{NumberWitnessedTo}}
On average, how many tracts do you pass out in a week?
{{NumberWeeklyTracts}}
What is your rate of success in fulfilling the great commission, getting your converts baptized and active in the local church where they may be taught?
{{RateOfSuccess}}
Explain your position briefly concerning predestination and election.
{{Predestination}}
Do you claim identity with any group or fellowship such as BBF, GARB, FBF, Other?
{{FellowshipAssociation}}
To a young person asking you to recommend a Christian College, list two or three Christian Colleges, in order of preference, which you would recommend?
{{Colleges}}
When was the last time you admitted you were wrong about something and apologized?
{{AdmittedWrong}}
Have you or your wife ever been divorced?
{{Divorced}}
Do you believe there are grounds whereby a man or women may remarry with a previous spouse still living?
{{GroundsForRemarry}}
Have you married a divorced couple or would you?
{{MarryADivorcee}}
Do you believe that being a member of a masonic lodge conflicts with Biblical separation?
{{MasonicLodge}}
Please list the English version(s) of the Bible you use and approve for preaching and teaching.
{{BibleVersionsUsed}}
Please give your opinion of all English versions of the Bible you use and approve for preaching and teaching.
{{BibleVersionOpinion}}
Do you listen to or approve of either "Contemporary Christian Music" or "Gospel rock" music?
{{ContemporaryMusic}}
What is your position in relation to the modern day Charismatic movement?
{{Charasmaticism}}
Do you or any member of your family speak in tongues?
{{Tongues}}
Is Repentance a necessary part of salvation?
{{RepentanceNecessary}}
One definition of repentance is: "Repentance means changing your mind about whatever is keeping you from turning to Jesus."
{{RepentanceDefinition}}
Do you consider yourself a fundamentalist?
{{Fundamentalist}}
Do you believe it is important to pay your bills on time?
{{BillsOnTime}}
How many times in the last 12 months have you been late paying a bill?
{{LateBills}}
What do you do to "make things right" when you are late paying a bill?
{{LateBillActionTaken}}
Though we support Missions and Missionaries doing many things and serving on many fields, we look primarily for Missionaries going to the ripe Harvest fields to begin Churches which will eventually become indigenous Churches. Please evaluate for us the potential of the Harvest field to which you have been called by telling the response of the people at large to Tract or Bible Distribution, Door-to-Door Visitation, and Gospel Preaching.
{{PotentialHarvest}}
+ + diff --git a/OFBButte.Application/Email/Templates/base.html b/OFBButte.Application/Email/Templates/base.html index 6ba6e5d..e01fe67 100644 --- a/OFBButte.Application/Email/Templates/base.html +++ b/OFBButte.Application/Email/Templates/base.html @@ -4,6 +4,11 @@ + {{TEST}} diff --git a/OFBButte.Application/Missionary/AddAndSendMissionaryForm.cs b/OFBButte.Application/Missionary/AddAndSendMissionaryForm.cs index 3bc7aba..49b3b5e 100644 --- a/OFBButte.Application/Missionary/AddAndSendMissionaryForm.cs +++ b/OFBButte.Application/Missionary/AddAndSendMissionaryForm.cs @@ -19,10 +19,15 @@ namespace OFBButte.Application.Missionary send = new SendMissionaryFormEmail(context, emailSender); } - public async Task Handle(MissionarySupport form, string emailAddress) + public async Task Handle(MissionarySupport form, string emailAddress) { var added = add.Handle(form); + if (added == null) + { + return null; + } await send.Handle(added.Id, emailAddress); + return added; } } } diff --git a/OFBButte.Application/Missionary/SendMissionaryFormEmail.cs b/OFBButte.Application/Missionary/SendMissionaryFormEmail.cs index 1269323..e7f5ef2 100644 --- a/OFBButte.Application/Missionary/SendMissionaryFormEmail.cs +++ b/OFBButte.Application/Missionary/SendMissionaryFormEmail.cs @@ -1,4 +1,5 @@ -using OFBButte.Application.Database; +using Microsoft.EntityFrameworkCore; +using OFBButte.Application.Database; using OFBButte.Application.Email; using System; using System.Collections.Generic; @@ -20,7 +21,7 @@ namespace OFBButte.Application.Missionary public async Task Handle(int missionaryFormId, string emailAddress) { - var form = context.MissionarySupportForms.FirstOrDefault(m => m.Id == missionaryFormId); + var form = context.MissionarySupportForms.Include(m => m.Children).Include(m => m.CollegeRecommendations).FirstOrDefault(m => m.Id == missionaryFormId); if (form == null) throw new Exception($"Form with id {missionaryFormId} not found"); diff --git a/OFBButte.Entities/MissionarySupport.cs b/OFBButte.Entities/MissionarySupport.cs index cfe2e23..133f30e 100644 --- a/OFBButte.Entities/MissionarySupport.cs +++ b/OFBButte.Entities/MissionarySupport.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection; using System.Text; namespace OFBButte.Entities @@ -69,9 +70,48 @@ namespace OFBButte.Entities public Dictionary ToDictionary() { - var props = GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public).ToDictionary(p => p.Name, p => p.GetValue(this)?.ToString() ?? ""); + var properties = GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public).ToDictionary(p => p.Name, p => p); + var props = properties.ToDictionary(p => p.Key, p => p.Value.GetValue(this)?.ToString() ?? ""); + props.Add("ChildNames", string.Join("
", Children.Select(c => c.Name))); + StringBuilder colleges = new StringBuilder(""); + foreach (var college in CollegeRecommendations) + { + colleges.Append($""); + } + colleges.Append("
{college.Name}    {college.City}, {college.State}
"); + props.Add("Colleges", colleges.ToString()); + foreach(var prop in properties) + { + if (prop.Value.PropertyType == typeof(bool) && props.ContainsKey(prop.Key)) + { + props[prop.Key] = (bool)prop.Value.GetValue(this) == true ? "Yes" : "No"; + } + } return props; } + private void GenerateHtml() + { + var props = GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public).ToDictionary(p => p.Name, p => p.GetValue(this)?.ToString() ?? ""); + StringBuilder sb = new StringBuilder(); + sb.AppendLine(""); + sb.AppendLine(" "); + foreach (var p in props) + { + if (p.Key == "Id" || p.Key == "HoneyPot") + continue; + + sb.AppendLine(" "); + sb.AppendLine($" "); + sb.AppendLine(" "); + sb.AppendLine(" "); + sb.AppendLine($" "); + sb.AppendLine(" "); + } + sb.AppendLine(" "); + sb.AppendLine("
{p.Key}
{{{{{p.Key}}}}}
"); + string str = sb.ToString(); + } + } }