Skip to content

fix missing await on mediator in details razor page #355

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions CoreWiki/Pages/Details.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System;
using System.Security.Claims;
using System.Threading.Tasks;
using MediatR;
using AutoMapper;
Expand Down Expand Up @@ -48,17 +47,17 @@ public async Task<IActionResult> OnGetAsync(string slug)

Article = _mapper.Map<ArticleDetails>(article);

ManageViewCount(slug);
await ManageViewCount(slug);

return Page();
}

private void ManageViewCount(string slug)
private Task<Unit> ManageViewCount(string slug)
{
var incrementViewCount = (Request.Cookies[slug] == null);
if (!incrementViewCount)
{
return;
return Task.FromResult(Unit.Value);
}

Article.ViewCount++;
Expand All @@ -67,7 +66,7 @@ private void ManageViewCount(string slug)
Expires = DateTime.UtcNow.AddMinutes(5)
});

_mediator.Send(new IncrementViewCountCommand(slug));
return _mediator.Send(new IncrementViewCountCommand(slug));
}

public async Task<IActionResult> OnPostAsync(Comment model)
Expand Down