Added automatic newsletter distribution to articles on publish
This commit is contained in:
parent
9cf97fbef7
commit
a94852298d
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
@rendermode InteractiveServer
|
@rendermode InteractiveServer
|
||||||
@attribute [Authorize(Policy = "ArticleEditOrReviewPermissions")]
|
@attribute [Authorize(Policy = "ArticleEditOrReviewPermissions")]
|
||||||
|
@inject ILogger<ArticleEditor> Logger
|
||||||
@inject IDbContextFactory<ApplicationDbContext> ContextFactory
|
@inject IDbContextFactory<ApplicationDbContext> ContextFactory
|
||||||
@inject NavigationManager Navigation
|
@inject NavigationManager Navigation
|
||||||
@inject UserManager<ApplicationUser> UserManager
|
@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();
|
await context.SaveChangesAsync();
|
||||||
|
|
||||||
Navigation.NavigateTo($"/article/{article.Id}");
|
Navigation.NavigateTo($"/article/{article.Id}");
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
// TODO toast
|
// TODO toast
|
||||||
|
Logger.LogError(ex, "Failed to save article.");
|
||||||
} finally {
|
} finally {
|
||||||
Busy = false;
|
Busy = false;
|
||||||
await InvokeAsync(StateHasChanged);
|
await InvokeAsync(StateHasChanged);
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
@using System.Diagnostics.CodeAnalysis
|
@using System.Diagnostics.CodeAnalysis
|
||||||
@using Microsoft.Extensions.Options
|
@using Microsoft.Extensions.Options
|
||||||
|
|
||||||
|
@inject ILogger<ArticleView> Logger
|
||||||
@inject IDbContextFactory<ApplicationDbContext> ContextFactory
|
@inject IDbContextFactory<ApplicationDbContext> ContextFactory
|
||||||
@inject NavigationManager Navigation
|
@inject NavigationManager Navigation
|
||||||
@inject IOptions<Customization> Customizations
|
@inject IOptions<Customization> Customizations
|
||||||
|
@ -181,6 +182,20 @@
|
||||||
}
|
}
|
||||||
context.Update(Article);
|
context.Update(Article);
|
||||||
await context.SaveChangesAsync();
|
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("/");
|
Navigation.NavigateTo("/");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue