-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathEntityViewedHandler.cs
More file actions
39 lines (35 loc) · 1.31 KB
/
EntityViewedHandler.cs
File metadata and controls
39 lines (35 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Threading;
using System.Threading.Tasks;
using MediatR;
using SimplCommerce.Infrastructure.Data;
using SimplCommerce.Module.ActivityLog.Models;
using SimplCommerce.Module.Core.Events;
using SimplCommerce.Module.Core.Extensions;
namespace SimplCommerce.Module.ActivityLog.Events
{
public class EntityViewedHandler : INotificationHandler<EntityViewed>
{
private readonly IRepository<Activity> _activityRepository;
private readonly IWorkContext _workContext;
private const long EntityViewedActivityTypeId = 1;
public EntityViewedHandler(IRepository<Activity> activityRepository, IWorkContext workcontext)
{
_activityRepository = activityRepository;
_workContext = workcontext;
}
public async Task Handle(EntityViewed notification, CancellationToken cancellationToken)
{
var user = await _workContext.GetCurrentUser();
var activity = new Activity
{
ActivityTypeId = EntityViewedActivityTypeId,
EntityId = notification.EntityId,
EntityTypeId = notification.EntityTypeId,
UserId = user.Id,
CreatedOn = DateTimeOffset.UtcNow
};
_activityRepository.Add(activity);
}
}
}