Added automatic newsletter distribution to articles on publish
This commit is contained in:
parent
9cf97fbef7
commit
a94852298d
|
@ -8,6 +8,7 @@
|
|||
|
||||
@rendermode InteractiveServer
|
||||
@attribute [Authorize(Policy = "ArticleEditOrReviewPermissions")]
|
||||
@inject ILogger<ArticleEditor> Logger
|
||||
@inject IDbContextFactory<ApplicationDbContext> ContextFactory
|
||||
@inject NavigationManager Navigation
|
||||
@inject UserManager<ApplicationUser> UserManager
|
||||
|
@ -313,10 +314,17 @@
|
|||
}
|
||||
}
|
||||
|
||||
var newsletter = await context.Set<EmailNewsletter>().FirstOrDefaultAsync(n => n.Article == article);
|
||||
if (newsletter is not null) {
|
||||
newsletter.DistributionDateTime = article.PublishDate;
|
||||
}
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
Navigation.NavigateTo($"/article/{article.Id}");
|
||||
} catch (Exception ex) {
|
||||
// TODO toast
|
||||
Logger.LogError(ex, "Failed to save article.");
|
||||
} finally {
|
||||
Busy = false;
|
||||
await InvokeAsync(StateHasChanged);
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
@using System.Diagnostics.CodeAnalysis
|
||||
@using Microsoft.Extensions.Options
|
||||
|
||||
@inject ILogger<ArticleView> Logger
|
||||
@inject IDbContextFactory<ApplicationDbContext> ContextFactory
|
||||
@inject NavigationManager Navigation
|
||||
@inject IOptions<Customization> Customizations
|
||||
|
@ -181,6 +182,20 @@
|
|||
}
|
||||
context.Update(Article);
|
||||
await context.SaveChangesAsync();
|
||||
|
||||
if (Features.Value.EmailSubscriptions) {
|
||||
try {
|
||||
var newsletter = new EmailNewsletter {
|
||||
Article = Article,
|
||||
DistributionDateTime = Article.PublishDate
|
||||
};
|
||||
context.Add(newsletter);
|
||||
await context.SaveChangesAsync();
|
||||
} catch (Exception ex) {
|
||||
Logger.LogError(ex, "Failed to schedule article {name} for E-Mail distribution.", Article.Title);
|
||||
}
|
||||
}
|
||||
|
||||
Navigation.NavigateTo("/");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue