/
PolicyCreatedHandler.cs
36 lines (31 loc) · 1.07 KB
/
PolicyCreatedHandler.cs
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
using System.Threading;
using System.Threading.Tasks;
using DashboardService.Domain;
using MediatR;
using PolicyService.Api.Events;
namespace DashboardService.Listeners
{
public class PolicyCreatedHandler : INotificationHandler<PolicyCreated>
{
private readonly IPolicyRepository policyRepository;
public PolicyCreatedHandler(IPolicyRepository policyRepository)
{
this.policyRepository = policyRepository;
}
public Task Handle(PolicyCreated notification, CancellationToken cancellationToken)
{
var policy = new PolicyDocument
(
notification.PolicyNumber,
notification.PolicyFrom,
notification.PolicyTo,
$"{notification.PolicyHolder.FirstName} {notification.PolicyHolder.LastName}",
notification.ProductCode,
notification.TotalPremium,
notification.AgentLogin
);
policyRepository.Save(policy);
return Task.CompletedTask;
}
}
}