fixed Article View not adding Reviewer on Submit Review

This commit is contained in:
Mia Rose Winter 2024-01-24 11:30:51 +01:00
parent eb6a9ec88e
commit 1223b7f428
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E

View file

@ -4,8 +4,6 @@
@using Wave.Data @using Wave.Data
@using System.Security.Claims @using System.Security.Claims
@using System.Diagnostics.CodeAnalysis @using System.Diagnostics.CodeAnalysis
@using System.Net
@using System.Web
@using Microsoft.Extensions.Options @using Microsoft.Extensions.Options
@inject IDbContextFactory<ApplicationDbContext> ContextFactory @inject IDbContextFactory<ApplicationDbContext> ContextFactory
@ -96,6 +94,9 @@
#endregion #endregion
private Article? Article { get; set; } private Article? Article { get; set; }
[CascadingParameter]
public HttpContext HttpContext { get; set; } = default!;
private Article GetArticlePublic() { private Article GetArticlePublic() {
if (Article is null) throw new ApplicationException("Article not found."); if (Article is null) throw new ApplicationException("Article not found.");
if (Article.Status >= ArticleStatus.Published && Article.PublishDate <= DateTimeOffset.UtcNow) { if (Article.Status >= ArticleStatus.Published && Article.PublishDate <= DateTimeOffset.UtcNow) {
@ -160,6 +161,10 @@
private async Task SubmitForPublish() { private async Task SubmitForPublish() {
await using var context = await ContextFactory.CreateDbContextAsync(); await using var context = await ContextFactory.CreateDbContextAsync();
Article!.Status = ArticleStatus.Published; Article!.Status = ArticleStatus.Published;
string userId = HttpContext.User.FindFirst("Id")!.Value;
if (Article.Author.Id != userId) {
Article.Reviewer = await context.Users.FindAsync(userId);
}
context.Update(Article); context.Update(Article);
await context.SaveChangesAsync(); await context.SaveChangesAsync();
Navigation.NavigateTo("/"); Navigation.NavigateTo("/");