Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
Add new event notification - insert news item comment
Browse files Browse the repository at this point in the history
  • Loading branch information
KrzysztofPajak committed Jun 9, 2020
1 parent 43147ef commit 0dff3c0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Grand.Web/Controllers/NewsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Grand.Services.Seo;
using Grand.Services.Stores;
using Grand.Web.Commands.Models.News;
using Grand.Web.Events;
using Grand.Web.Features.Models.News;
using Grand.Web.Models.News;
using MediatR;
Expand Down Expand Up @@ -154,11 +155,13 @@ public virtual async Task<IActionResult> NewsCommentAdd(string newsItemId, NewsI
{
await _mediator.Send(new InsertNewsCommentCommand() { NewsItem = newsItem, Model = model });

//notification
await _mediator.Publish(new NewsCommentEvent(newsItem, model.AddNewComment));

//activity log
await _customerActivityService.InsertActivity("PublicStore.AddNewsComment", newsItem.Id, _localizationService.GetResource("ActivityLog.PublicStore.AddNewsComment"));

//The text boxes should be cleared after a comment has been posted
//That' why we reload the page
TempData["Grand.news.addcomment.result"] = _localizationService.GetResource("News.Comments.SuccessfullyAdded");
return RedirectToRoute("NewsItem", new { SeName = newsItem.GetSeName(_workContext.WorkingLanguage.Id) });
}
Expand Down
17 changes: 17 additions & 0 deletions Grand.Web/Events/NewsCommentEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Grand.Core.Domain.News;
using Grand.Web.Models.News;
using MediatR;

namespace Grand.Web.Events
{
public class NewsCommentEvent : INotification
{
public NewsItem News { get; private set; }
public AddNewsCommentModel NewsComment { get; private set; }
public NewsCommentEvent(NewsItem news, AddNewsCommentModel newsComment)
{
News = news;
NewsComment = newsComment;
}
}
}

0 comments on commit 0dff3c0

Please sign in to comment.