-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAccountCoding.cs
More file actions
75 lines (66 loc) · 2.48 KB
/
AccountCoding.cs
File metadata and controls
75 lines (66 loc) · 2.48 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
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
using Unity.Payments.Domain.Exceptions;
using Volo.Abp;
using System;
using Volo.Abp.Domain.Entities.Auditing;
using System.Linq;
using Volo.Abp.MultiTenancy;
namespace Unity.Payments.Domain.AccountCodings
{
public class AccountCoding : AuditedAggregateRoot<Guid>, IMultiTenant
{
public Guid? TenantId { get; set; }
public string MinistryClient { get; private set; }
public string Responsibility { get; private set; }
public string ServiceLine { get; private set; }
public string Stob { get; private set; }
public string ProjectNumber { get; private set; }
public AccountCoding()
{
MinistryClient = string.Empty;
Responsibility = string.Empty;
ServiceLine = string.Empty;
Stob = string.Empty;
ProjectNumber = string.Empty;
}
private AccountCoding(string ministryClient,
string responsibility,
string serviceLine,
string stob,
string projectNumber)
{
MinistryClient = ministryClient;
Responsibility = responsibility;
ServiceLine = serviceLine;
Stob = stob;
ProjectNumber = projectNumber;
}
public static AccountCoding Create(
string ministryClient,
string responsibility,
string serviceLine,
string stob,
string projectNumber)
{
ValidateField(ministryClient, 3, nameof(MinistryClient), false);
ValidateField(responsibility, 5, nameof(Responsibility), false);
ValidateField(serviceLine, 5, nameof(serviceLine), true);
ValidateField(stob, 4, nameof(stob), true);
ValidateField(projectNumber, 7, nameof(projectNumber), true);
return new AccountCoding(ministryClient, responsibility, serviceLine, stob, projectNumber);
}
private static void ValidateField(string field, uint length, string fieldName, bool validateAlphanumeric)
{
bool validAlphanumeric = true;
if (validateAlphanumeric)
{
validAlphanumeric = field.All(char.IsLetterOrDigit);
}
if (field.Length != length || !validAlphanumeric)
{
throw new BusinessException(ErrorConsts.InvalidAccountCodingField)
.WithData("field", fieldName)
.WithData("length", length);
}
}
}
}