-
Notifications
You must be signed in to change notification settings - Fork 2
/
Registration.cs
122 lines (96 loc) · 5.01 KB
/
Registration.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using System;
using System.Net.Http.Headers;
using System.Runtime.CompilerServices;
using Domania.Domain;
using Oeuvre.Modules.IdentityAccess.Domain.Tenants;
using Oeuvre.Modules.IdentityAccess.Domain.UserRegistrations.Events;
using Oeuvre.Modules.IdentityAccess.Domain.UserRegistrations.Rules;
using Oeuvre.Modules.IdentityAccess.Domain.Users;
namespace Oeuvre.Modules.IdentityAccess.Domain.UserRegistrations
{
public class Registration : Entity, IAggregateRoot
{
public UserRegistrationId Id { get; private set; }
private TenantId tenantId;
private FullName fullName;
private string password;
private MobileNumber mobileNumber;
private string eMailId;
private DateTime registrationDate;
private UserRegistrationStatus status;
private DateTime? confirmedDate;
private bool termsAndConditionsAccepted;
private Registration()
{
// Only EF.
}
private Registration(TenantId tenantId,
FullName fullName,
string password,
MobileNumber mobileNumber,
string eMailId,
bool termsAndConditionsAccepted,
IUsersCounter usersCounter)
{
//Rules
Console.WriteLine("Business Rule Check - User EMail Id Must be Unique");
CheckRule(new UserMustAcceptTermsAndConditions(termsAndConditionsAccepted));
CheckRule(new UserEmailIdLoginMustBeUniqueRule(usersCounter, eMailId));
this.Id = new UserRegistrationId(Guid.NewGuid());
this.tenantId = tenantId;
this.fullName = fullName;
this.password = password;
this.mobileNumber = mobileNumber;
this.eMailId = eMailId;
this.termsAndConditionsAccepted = termsAndConditionsAccepted;
registrationDate = SystemClock.Now;
//this.status = 1;
status = UserRegistrationStatus.WaitingForConfirmation;
AddDomainEvent(new NewUserRegisteredDomainEvent(this.Id,
tenantId,
fullName.FirstName,
fullName.LastName,
mobileNumber.MobileNo,
eMailId,
registrationDate));
}
public static Registration RegisterNewUser(Guid tenantId,
string firstName,
string lastName,
string password,
string mobileNoCountryCode,
string mobileNumber,
string emailId,
bool termsAndConditionsAccepted,
IUsersCounter usersCounter)
{
return new Registration(new TenantId(tenantId),
new FullName(firstName, lastName),
password,
new MobileNumber(mobileNoCountryCode, mobileNumber),
emailId,
termsAndConditionsAccepted,
usersCounter);
}
public User CreateUser()
{
this.CheckRule(new UserCannotBeCreatedWhenRegistrationIsNotConfirmedRule(status));
return User.CreateFromUserRegistration(this.Id,
this.tenantId,
this.fullName.FirstName,
this.fullName.LastName,
this.mobileNumber.CountryCode,
this.mobileNumber.MobileNo,
this.eMailId,
this.password);
}
public void Confirm(IUserRegistrationConfirmationExpirationCalculator expirationCalculator)
{
CheckRule(new UserRegistrationCannotBeConfirmedMoreThanOnceRule(status));
CheckRule(new UserRegistrationCannotBeConfirmedAfterExpirationRule(expirationCalculator, registrationDate));
this.status = UserRegistrationStatus.Confirmed;
this.confirmedDate = DateTime.UtcNow;
this.AddDomainEvent(new UserRegistrationConfirmedDomainEvent(this.Id));
}
}
}