more asynchrous stuff

This commit is contained in:
Michael 2017-04-04 19:48:14 -04:00
parent ad575bcd38
commit 6a9ce408d8

View file

@ -18,7 +18,7 @@ namespace Project_Unite
{
public class EmailService : IIdentityMessageService
{
public Task SendAsync(IdentityMessage message)
public async Task SendAsync(IdentityMessage message)
{
try
{
@ -41,7 +41,7 @@ public Task SendAsync(IdentityMessage message)
var db = new ApplicationDbContext();
db.AuditLogs.Add(new AuditLog("system", AuditLogLevel.Admin, $"Email sending...<br/><br/><strong>To:</strong> {sMsg.To}<br/><strong>Subject:</strong><br/>{sMsg.Subject}"));
db.SaveChanges();
smtp.SendCompleted += (o, a) =>
smtp.SendCompleted += async (o, a) =>
{
var alog = new AuditLog("system", AuditLogLevel.Admin, "");
if (a.Cancelled == true)
@ -52,7 +52,7 @@ public Task SendAsync(IdentityMessage message)
alog.Description += $"Error:<br/><pre><code class=\"language-csharp\">{a.Error}</code></pre>";
var ndb = new ApplicationDbContext();
ndb.AuditLogs.Add(alog);
ndb.SaveChanges();
await ndb.SaveChangesAsync();
};
smtp.SendAsync(sMsg, null);
}
@ -64,7 +64,7 @@ public Task SendAsync(IdentityMessage message)
{ex}"));
db.SaveChanges();
}
return Task.FromResult(0);
return;
}