Setup Missionary Form Email

master
dan 2019-07-23 22:04:29 -06:00
parent b32d6d54cc
commit bafd61b48f
14 changed files with 256 additions and 1 deletions

View File

@ -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<string, string> 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;
}
}

View File

@ -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<string,string> 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}";
}
}
}

View File

@ -0,0 +1,2 @@

<p>This is a test missionary form</p>

View File

@ -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);
}
}
}

View File

@ -1,4 +1,5 @@
using OFBButte.Application.Database;
using OFBButte.Application.Email;
using OFBButte.Entities;
using System;
using System.Collections.Generic;

View File

@ -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);
}
}
}

View File

@ -12,4 +12,13 @@
<ProjectReference Include="..\OFBButte.Entities\OFBButte.Entities.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="Email\Templates\base.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Email\Templates\MissionarySupportForm.html">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -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<MissionaryChild>()
{
new MissionaryChild()
{
Name = "Katie Smith"
},
new MissionaryChild()
{
Name = "Brandon Smith"
}
},
ChildrenSchool = ChildrenSchool.Home,
CollegeRecommendations = new List<MissionaryCollegeRecommendation>()
{
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);
}
}
}

View File

@ -15,4 +15,18 @@
<ProjectReference Include="..\OFBButte.Infrastructure\OFBButte.Infrastructure.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.Development.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="appsettings.json">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>appsettings.Designer.cs</LastGenOutput>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="appsettings.Production.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -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();

View File

@ -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"
}
}

View File

@ -0,0 +1,8 @@
{
"App": {
"Environment": "Prod"
},
"ConnectionStrings": {
"OFBContext": "server=localhost;database=ofb2;user=ofbapi2;password={{db_pass}};"
}
}

View File

@ -0,0 +1,8 @@
{
"App": {
"Environment": "Local"
},
"ConnectionStrings": {
"OFBContext": ""
}
}

View File

@ -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<string, string> ToDictionary()
{
var props = GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public).ToDictionary(p => p.Name, p => p.GetValue(this)?.ToString() ?? "");
return props;
}
}
}