-
Notifications
You must be signed in to change notification settings - Fork 2
/
RegisterNewUserCommandHandler.cs
50 lines (43 loc) · 2.26 KB
/
RegisterNewUserCommandHandler.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Threading;
using System.Threading.Tasks;
using MediatR;
using Oeuvre.Modules.IdentityAccess.Application.Authentication;
using Domaina.CQRS;
using Oeuvre.Modules.IdentityAccess.Domain.UserRegistrations;
using Serilog;
using Domaina.CQRS.Command;
namespace Oeuvre.Modules.IdentityAccess.Application.UserRegistrations.RegisterNewUser
{
public class RegisterNewUserCommandHandler : ICommandHandler<RegisterNewUserCommand, Guid>
{
private readonly IUserRegistrationRepository userRegistrationRepository;
private readonly IUsersCounter usersCounter;
private readonly ILogger logger;
public RegisterNewUserCommandHandler(IUserRegistrationRepository userRegistrationRepository
,IUsersCounter usersCounter
,ILogger logger
)
{
this.userRegistrationRepository = userRegistrationRepository;
this.usersCounter = usersCounter;
this.logger = logger;
}
public async Task<Guid> Handle(RegisterNewUserCommand request, CancellationToken cancellationToken)
{
logger.Information("Command - Register New User");
string hashedPassword = PasswordManager.HashPassword(request.Password);
var userRegistration = Registration.RegisterNewUser(new Guid(request.TenantId),
request.FirstName,
request.LastName,
hashedPassword,
request.MobileNoCountryCode,
request.MobileNumber,
request.Email,
request.TermsAndConditionsAccepted,
usersCounter);
await userRegistrationRepository.AddAsync(userRegistration);
return userRegistration.Id.Value;
}
}
}