From bafd61b48f3782cec7b549ac6fd5d8602224a12a Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 23 Jul 2019 22:04:29 -0600 Subject: [PATCH] Setup Missionary Form Email --- OFBButte.Application/Email/EmailMessage.cs | 8 ++ .../Email/MissionarySupportFormEmail.cs | 28 +++++ .../Templates/MissionarySupportForm.html | 2 + .../Missionary/AddAndSendMissionaryForm.cs | 28 +++++ .../Missionary/AddMissionarySupportForm.cs | 1 + .../Missionary/SendMissionaryFormEmail.cs | 33 ++++++ .../OFBButte.Application.csproj | 9 ++ OFBButte.Console/App.cs | 102 +++++++++++++++++- OFBButte.Console/OFBButte.Console.csproj | 14 +++ OFBButte.Console/Program.cs | 1 + OFBButte.Console/appsettings.Development.json | 8 ++ OFBButte.Console/appsettings.Production.json | 8 ++ OFBButte.Console/appsettings.json | 8 ++ OFBButte.Entities/MissionarySupport.cs | 7 ++ 14 files changed, 256 insertions(+), 1 deletion(-) create mode 100644 OFBButte.Application/Email/MissionarySupportFormEmail.cs create mode 100644 OFBButte.Application/Email/Templates/MissionarySupportForm.html create mode 100644 OFBButte.Application/Missionary/AddAndSendMissionaryForm.cs create mode 100644 OFBButte.Application/Missionary/SendMissionaryFormEmail.cs create mode 100644 OFBButte.Console/appsettings.Development.json create mode 100644 OFBButte.Console/appsettings.Production.json create mode 100644 OFBButte.Console/appsettings.json diff --git a/OFBButte.Application/Email/EmailMessage.cs b/OFBButte.Application/Email/EmailMessage.cs index 3cef1a0..34d10c1 100644 --- a/OFBButte.Application/Email/EmailMessage.cs +++ b/OFBButte.Application/Email/EmailMessage.cs @@ -11,6 +11,7 @@ namespace OFBButte.Application.Email public virtual string From { get; set; } = "donotreply@ofbbutte.com"; public virtual string Subject { get; set; } public virtual string Body { get; set; } + public virtual Dictionary AdditionalValues { get; set; } public abstract string TemplateName { get; set; } public void SetBodyFromTemplate(bool isTest = true) @@ -24,6 +25,13 @@ namespace OFBButte.Application.Email { template = template.Replace($"{{{{{property.Key}}}}}", property.Value); } + if (AdditionalValues != null) + { + foreach(var kvp in AdditionalValues) + { + template = template.Replace($"{{{{{kvp.Key}}}}}", kvp.Value); + } + } Body = template; } } diff --git a/OFBButte.Application/Email/MissionarySupportFormEmail.cs b/OFBButte.Application/Email/MissionarySupportFormEmail.cs new file mode 100644 index 0000000..c87c681 --- /dev/null +++ b/OFBButte.Application/Email/MissionarySupportFormEmail.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace OFBButte.Application.Email +{ + public class MissionarySupportFormEmail : EmailMessage + { + public override string TemplateName { get; set; } = "MissionarySupportForm"; + public override string From { get; set; } = "donotreply@ofbbutte.com"; + public override string Subject { get; set; } = "OFB Missionary Questionnaire"; + + public MissionarySupportFormEmail(Dictionary values) + { + if (values == null) return; + AdditionalValues = values; + string name = ""; + var kvp = values.Where(m => m.Key.ToLower() == "name").ToList(); + if (kvp.Count > 0) + { + name = kvp.First().Value; + } + Subject = $"{Subject} : {name}"; + + } + } +} diff --git a/OFBButte.Application/Email/Templates/MissionarySupportForm.html b/OFBButte.Application/Email/Templates/MissionarySupportForm.html new file mode 100644 index 0000000..7117b89 --- /dev/null +++ b/OFBButte.Application/Email/Templates/MissionarySupportForm.html @@ -0,0 +1,2 @@ + +

This is a test missionary form

\ No newline at end of file diff --git a/OFBButte.Application/Missionary/AddAndSendMissionaryForm.cs b/OFBButte.Application/Missionary/AddAndSendMissionaryForm.cs new file mode 100644 index 0000000..3bc7aba --- /dev/null +++ b/OFBButte.Application/Missionary/AddAndSendMissionaryForm.cs @@ -0,0 +1,28 @@ +using OFBButte.Application.Database; +using OFBButte.Application.Email; +using OFBButte.Entities; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace OFBButte.Application.Missionary +{ + public class AddAndSendMissionaryForm + { + private readonly AddMissionarySupportForm add; + private readonly SendMissionaryFormEmail send; + + public AddAndSendMissionaryForm(IOFBContext context, IEmailSender emailSender) + { + add = new AddMissionarySupportForm(context); + send = new SendMissionaryFormEmail(context, emailSender); + } + + public async Task Handle(MissionarySupport form, string emailAddress) + { + var added = add.Handle(form); + await send.Handle(added.Id, emailAddress); + } + } +} diff --git a/OFBButte.Application/Missionary/AddMissionarySupportForm.cs b/OFBButte.Application/Missionary/AddMissionarySupportForm.cs index 3de630a..e31074f 100644 --- a/OFBButte.Application/Missionary/AddMissionarySupportForm.cs +++ b/OFBButte.Application/Missionary/AddMissionarySupportForm.cs @@ -1,4 +1,5 @@ using OFBButte.Application.Database; +using OFBButte.Application.Email; using OFBButte.Entities; using System; using System.Collections.Generic; diff --git a/OFBButte.Application/Missionary/SendMissionaryFormEmail.cs b/OFBButte.Application/Missionary/SendMissionaryFormEmail.cs new file mode 100644 index 0000000..1269323 --- /dev/null +++ b/OFBButte.Application/Missionary/SendMissionaryFormEmail.cs @@ -0,0 +1,33 @@ +using OFBButte.Application.Database; +using OFBButte.Application.Email; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace OFBButte.Application.Missionary +{ + public class SendMissionaryFormEmail + { + private readonly IOFBContext context; + private readonly IEmailSender emailSender; + public SendMissionaryFormEmail(IOFBContext context, IEmailSender emailSender) + { + this.context = context; + this.emailSender = emailSender; + } + + public async Task Handle(int missionaryFormId, string emailAddress) + { + var form = context.MissionarySupportForms.FirstOrDefault(m => m.Id == missionaryFormId); + if (form == null) + throw new Exception($"Form with id {missionaryFormId} not found"); + + var email = new Email.MissionarySupportFormEmail(form.ToDictionary()); + email.To = emailAddress; + + await emailSender.Send(email); + } + } +} diff --git a/OFBButte.Application/OFBButte.Application.csproj b/OFBButte.Application/OFBButte.Application.csproj index cada972..59ece21 100644 --- a/OFBButte.Application/OFBButte.Application.csproj +++ b/OFBButte.Application/OFBButte.Application.csproj @@ -12,4 +12,13 @@ + + + PreserveNewest + + + PreserveNewest + + + diff --git a/OFBButte.Console/App.cs b/OFBButte.Console/App.cs index 4c93fe2..8cfbe03 100644 --- a/OFBButte.Console/App.cs +++ b/OFBButte.Console/App.cs @@ -3,11 +3,13 @@ using OFBButte.Application.Configuration; using OFBButte.Application.Database; using OFBButte.Application.Email; using OFBButte.Application.Users; +using OFBButte.Application.Missionary; using OFBButte.Infrastructure.Hashing; using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; +using OFBButte.Entities; namespace OFBButte.Console { @@ -31,7 +33,7 @@ namespace OFBButte.Console var env = appSettings.Environment; try { - await SendVerificationEmail(); + await SendMissionarySupportForm(); } catch (Exception ex) { @@ -52,10 +54,108 @@ namespace OFBButte.Console await adder.Handle(user); } + private async Task SendMissionarySupportForm() + { + var send = new SendMissionaryFormEmail(context, emailSender); + await send.Handle(1, "djabsher@gmail.com"); + } + private void LoginUser() { var login = new LoginUser(context, new PasswordHasher()); var result = login.Handle(user, pass); } + + private void AddMissionarySupportForm() + { + var form = new MissionarySupport() + { + Name = "John Smith", + WifesName = "Sarah Smith", + AdmittedWrong = "Yesterday", + Alcohol = false, + AloneOrTeam = "Alone", + CorrectWrongOfAnotherMissionary = "Prayer and support", + FellowshipAssociation = "No fellowship", + LateBillActionTaken = "Never late", + MarryADivorcee = false, + RestAndRelaxation = "Rest all the time", + BibleVersionOpinion = "Only KJV", + BibleVersionsUsed = "KJV", + BillsOnTime = "very important", + CallToField = "Called by God", + CellPhone = "222-555-9899", + HomePhone = "111-555-3343", + FieldOfService = "Malaysia", + FieldPhone = "333-555-8787", + Charasmaticism = "Do not agree with it", + Children = new List() + { + new MissionaryChild() + { + Name = "Katie Smith" + }, + new MissionaryChild() + { + Name = "Brandon Smith" + } + }, + ChildrenSchool = ChildrenSchool.Home, + CollegeRecommendations = new List() + { + new MissionaryCollegeRecommendation() + { + Name = "PCC", + City = "Somewhere", + State = "Florida" + }, + new MissionaryCollegeRecommendation() + { + Name = "Bible School", + City = "Butte", + State = "Montana" + } + }, + ContemporaryMusic = false, + CurrentMonthlySupport = "1000", + DailyBible = BibleReading.Always, + Dance = false, + Divorced = false, + EvaluationOfNationals = "They need Christ", + FemaleDressStandard = true, + FemaleShorts = FemaleShorts.Never, + FemaleSlacks = FemaleSlacks.Never, + FinancialStatementPrevYear = "Yes", + Fundamentalist = true, + GroundsForRemarry = false, + HoneyPot = ".", + Id = 0, + LateBills = "Never", + MaleHair = true, + MasonicLodge = false, + MonthlySupportNeeded = "2000", + MovieTheaters = false, + NumberLedToChrist = 100, + NumberWeeklyTracts = 1000, + NumberWitnessedTo = 10000, + Plans = "Start churches", + PotentialHarvest = "Great potential", + Predestination = "Everyone has a free will", + RateOfSuccess = "Fairly Successful", + RepentanceDefinition = "Agree with God", + RepentanceNecessary = true, + SendingChurch = "Old Fashion Baptist", + Smoking = false, + SwimmingClothing = "Do not swim", + Television = "Do not watch tv", + Testimony = "Saved by Grace", + TimeInCountry = "4 years", + Tongues = false, + WorldlyMusic = false + }; + + var adder = new AddMissionarySupportForm(context); + adder.Handle(form); + } } } diff --git a/OFBButte.Console/OFBButte.Console.csproj b/OFBButte.Console/OFBButte.Console.csproj index 792922e..ad5f629 100644 --- a/OFBButte.Console/OFBButte.Console.csproj +++ b/OFBButte.Console/OFBButte.Console.csproj @@ -15,4 +15,18 @@ + + + PreserveNewest + + + SettingsSingleFileGenerator + appsettings.Designer.cs + PreserveNewest + + + PreserveNewest + + + diff --git a/OFBButte.Console/Program.cs b/OFBButte.Console/Program.cs index 8615ae5..6bbfe37 100644 --- a/OFBButte.Console/Program.cs +++ b/OFBButte.Console/Program.cs @@ -26,6 +26,7 @@ namespace OFBButte.Console { var builder = new ConfigurationBuilder(); builder.AddJsonFile("appsettings.json", false, true); + builder.AddJsonFile("appsettings.Development.json", true, true); var config = builder.Build(); diff --git a/OFBButte.Console/appsettings.Development.json b/OFBButte.Console/appsettings.Development.json new file mode 100644 index 0000000..f20ed06 --- /dev/null +++ b/OFBButte.Console/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "App": { + "Environment": "Dev" + }, + "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.Console/appsettings.Production.json b/OFBButte.Console/appsettings.Production.json new file mode 100644 index 0000000..427d4c5 --- /dev/null +++ b/OFBButte.Console/appsettings.Production.json @@ -0,0 +1,8 @@ +{ + "App": { + "Environment": "Prod" + }, + "ConnectionStrings": { + "OFBContext": "server=localhost;database=ofb2;user=ofbapi2;password={{db_pass}};" + } +} diff --git a/OFBButte.Console/appsettings.json b/OFBButte.Console/appsettings.json new file mode 100644 index 0000000..4fe7500 --- /dev/null +++ b/OFBButte.Console/appsettings.json @@ -0,0 +1,8 @@ +{ + "App": { + "Environment": "Local" + }, + "ConnectionStrings": { + "OFBContext": "" + } +} diff --git a/OFBButte.Entities/MissionarySupport.cs b/OFBButte.Entities/MissionarySupport.cs index 4cdc532..cfe2e23 100644 --- a/OFBButte.Entities/MissionarySupport.cs +++ b/OFBButte.Entities/MissionarySupport.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Text; namespace OFBButte.Entities @@ -66,5 +67,11 @@ namespace OFBButte.Entities public string HoneyPot { get; set; } + public Dictionary ToDictionary() + { + var props = GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public).ToDictionary(p => p.Name, p => p.GetValue(this)?.ToString() ?? ""); + return props; + } + } }