/
Operator.cs
90 lines (69 loc) · 2.22 KB
/
Operator.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
using LoanApplication.TacticalDdd.DomainModel.Ddd;
namespace LoanApplication.TacticalDdd.DomainModel;
public class Operator : Entity<OperatorId>
{
public Login Login { get; private set; }
public Password Password { get; private set; }
public Name Name { get; private set; }
public MonetaryAmount CompetenceLevel { get; private set; }
public Operator(Login login, Password password, Name name, MonetaryAmount competenceLevel)
{
Id = new OperatorId(Guid.NewGuid());
Login = login;
Password = password;
Name = name;
CompetenceLevel = competenceLevel;
}
//To satisfy EF Core
protected Operator()
{
}
public bool CanAccept(MonetaryAmount loanLoanAmount) => loanLoanAmount <= CompetenceLevel;
}
public class OperatorId : ValueObject<OperatorId>
{
public Guid Value { get; }
public OperatorId(Guid value)
{
Value = value;
}
protected override IEnumerable<object> GetAttributesToIncludeInEqualityCheck()
{
yield return Value;
}
protected OperatorId()
{
}
}
public class Login : ValueObject<Login>
{
public string Value { get; }
public Login(string value)
{
if (string.IsNullOrWhiteSpace(value))
throw new ArgumentException("Login cannot be null or empty string");
Value = value;
}
public static Login Of(string login) => new Login(login);
public static implicit operator string(Login login) => login.Value;
protected override IEnumerable<object> GetAttributesToIncludeInEqualityCheck()
{
yield return Value;
}
}
public class Password : ValueObject<Password>
{
public string Value { get; }
public Password(string value)
{
if (string.IsNullOrWhiteSpace(value))
throw new ArgumentException("Password cannot be null or empty string");
Value = value;
}
public static Password Of(string value) => new Password(value);
public static implicit operator string(Password password) => password.Value;
protected override IEnumerable<object> GetAttributesToIncludeInEqualityCheck()
{
yield return Value;
}
}