Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
LegalIdentityExtensions.cs
3
5{
9 public static class LegalIdentityExtensions
10 {
16 public static bool IsDiscarded(this LegalIdentity Identity)
17 {
18 return Identity is null ||
19 Identity.State == IdentityState.Compromised ||
20 Identity.State == IdentityState.Obsoleted ||
21 Identity.State == IdentityState.Rejected;
22 }
23
29 public static bool IsApproved(this LegalIdentity Identity)
30 {
31 return Identity is not null && Identity.State == IdentityState.Approved;
32 }
33
39 public static bool HasApprovedPersonalInformation(this LegalIdentity? Identity)
40 {
41 if (Identity is null)
42 return false;
43
44 if (Identity?.Attachments is null)
45 return false;
46
47 if (!Identity.IsApproved())
48 return false;
49
50 bool HasFullName = false;
51 bool HasFirstName = false;
52 bool HasLastName = false;
53 bool HasPersonalNumber = false;
54
55 foreach (Property P in Identity.Properties)
56 {
57 switch (P.Name)
58 {
60 HasFirstName = true;
61 break;
62
64 HasLastName = true;
65 break;
66
68 HasPersonalNumber = true;
69 break;
70
72 HasFullName = true;
73 break;
74 }
75 }
76
77 if (!(((HasFirstName && HasLastName) || HasFullName) && HasPersonalNumber))
78 return false;
79
80 Attachment? Photo = Identity.Attachments.GetFirstImageAttachment();
81 if (Photo is null)
82 return false;
83
84 return true;
85 }
86
93 public static string GetJid(this LegalIdentity legalIdentity, string defaultValueIfNotFound = "")
94 {
95 string? Jid = null;
96
97 if (legalIdentity is not null && legalIdentity.Properties?.Length > 0)
98 Jid = legalIdentity.Properties.FirstOrDefault(x => x.Name == Constants.XmppProperties.Jid)?.Value;
99
100 return !string.IsNullOrWhiteSpace(Jid) ? Jid : defaultValueIfNotFound;
101 }
102
107 internal static PersonalInformation GetPersonalInfo(this LegalIdentity legalIdentity)
108 {
110
111 foreach (Property P in legalIdentity.Properties)
112 {
113 switch (P.Name)
114 {
115 case "FIRST":
116 Result.FirstName = P.Value;
117 break;
118
119 case "MIDDLE":
120 Result.MiddleNames = P.Value;
121 break;
122
123 case "LAST":
124 Result.LastNames = P.Value;
125 break;
126
127 case "FULLNAME":
128 Result.FullName = P.Value;
129 break;
130
131 case "ADDR":
132 Result.Address = P.Value;
133 break;
134
135 case "ADDR2":
136 Result.Address2 = P.Value;
137 break;
138
139 case "ZIP":
140 Result.PostalCode = P.Value;
141 break;
142
143 case "AREA":
144 Result.Area = P.Value;
145 break;
146
147 case "CITY":
148 Result.City = P.Value;
149 break;
150
151 case "REGION":
152 Result.Region = P.Value;
153 break;
154
155 case "COUNTRY":
156 Result.Country = P.Value;
157 break;
158
159 case "NATIONALITY":
160 Result.Nationality = P.Value;
161 break;
162
163 case "GENDER":
164 switch (P.Value.ToLower())
165 {
166 case "m":
167 Result.Gender = Gender.Male;
168 break;
169
170 case "f":
171 Result.Gender = Gender.Female;
172 break;
173
174 case "x":
175 Result.Gender = Gender.Other;
176 break;
177 }
178 break;
179
180 case "BDAY":
181 if (int.TryParse(P.Value, out int i) && i >= 1 && i <= 31)
182 Result.BirthDay = i;
183 break;
184
185 case "BMONTH":
186 if (int.TryParse(P.Value, out i) && i >= 1 && i <= 12)
187 Result.BirthMonth = i;
188 break;
189
190 case "BYEAR":
191 if (int.TryParse(P.Value, out i) && i >= 1900 && i <= 2100)
192 Result.BirthYear = i;
193 break;
194
195 case "PNR":
196 Result.PersonalNumber = P.Value;
197 break;
198
199 case "ORGNAME":
200 Result.OrgName = P.Value;
201 Result.HasOrg = true;
202 break;
203
204 case "ORGDEPT":
205 Result.OrgDepartment = P.Value;
206 Result.HasOrg = true;
207 break;
208
209 case "ORGROLE":
210 Result.OrgRole = P.Value;
211 Result.HasOrg = true;
212 break;
213
214 case "ORGADDR":
215 Result.OrgAddress = P.Value;
216 Result.HasOrg = true;
217 break;
218
219 case "ORGADDR2":
220 Result.OrgAddress2 = P.Value;
221 Result.HasOrg = true;
222 break;
223
224 case "ORGZIP":
225 Result.OrgPostalCode = P.Value;
226 Result.HasOrg = true;
227 break;
228
229 case "ORGAREA":
230 Result.OrgArea = P.Value;
231 Result.HasOrg = true;
232 break;
233
234 case "ORGCITY":
235 Result.OrgCity = P.Value;
236 Result.HasOrg = true;
237 break;
238
239 case "ORGREGION":
240 Result.OrgRegion = P.Value;
241 Result.HasOrg = true;
242 break;
243
244 case "ORGCOUNTRY":
245 Result.OrgCountry = P.Value;
246 Result.HasOrg = true;
247 break;
248
249 case "ORGNR":
250 Result.OrgNumber = P.Value;
251 Result.HasOrg = true;
252 break;
253
254 case "PHONE":
255 Result.Phone = P.Value;
256 break;
257
258 case "EMAIL":
259 Result.EMail = P.Value;
260 break;
261
262 case "JID":
263 Result.Jid = P.Value;
264 break;
265 }
266 }
267
268 Result.HasBirthDate =
269 Result.BirthDay.HasValue &&
270 Result.BirthMonth.HasValue &&
271 Result.BirthYear.HasValue &&
272 Result.BirthDay.Value <= DateTime.DaysInMonth(Result.BirthYear.Value, Result.BirthMonth.Value);
273
274 if (!Result.HasBirthDate)
275 {
276 Result.BirthDay = null;
277 Result.BirthMonth = null;
278 Result.BirthYear = null;
279 }
280
282 Result.FullName = LegalIdentity.JoinNames(Result.FirstName, Result.MiddleNames, Result.LastNames);
286 {
287 LegalIdentity.SeparateNames(Result.FullName, out Result.FirstName, out Result.MiddleNames, out Result.LastNames);
288 }
289
290 return Result;
291 }
292
293
300 public static string GetDomain(this LegalIdentity legalIdentity, string defaultValueIfNotFound = "")
301 {
302 string? Domain = null;
303
304 if (legalIdentity is not null && legalIdentity.Properties?.Length > 0)
305 Domain = legalIdentity.Properties.FirstOrDefault(x => x.Name == Constants.XmppProperties.Domain)?.Value;
306
307 return !string.IsNullOrWhiteSpace(Domain) ? Domain : defaultValueIfNotFound;
308 }
309
315 public static bool IsOrganizational(this LegalIdentity Identity)
316 {
317 if (Identity?.Properties is null)
318 return false;
319
320 foreach (Property P in Identity.Properties)
321 {
322 switch (P.Name)
323 {
335 return true;
336 }
337 }
338
339 return false;
340 }
341
347 public static bool IsPersonal(this LegalIdentity Identity)
348 {
349 return !Identity.IsOrganizational();
350 }
351 }
352}
const string PersonalNumber
Personal number
Definition: Constants.cs:394
const string OrgAddress2
Organization Address line 2
Definition: Constants.cs:474
const string OrgArea
Organization Area
Definition: Constants.cs:479
const string OrgRegion
Organization Region
Definition: Constants.cs:494
const string OrgCity
Organization City
Definition: Constants.cs:484
const string OrgRole
Organization Role
Definition: Constants.cs:509
const string OrgZipCode
Organization Zip Code
Definition: Constants.cs:489
const string OrgCountry
Organization Country
Definition: Constants.cs:499
const string OrgDepartment
Organization Department
Definition: Constants.cs:504
const string Domain
Domain name.
Definition: Constants.cs:534
const string OrgAddress
Organization Address line 1
Definition: Constants.cs:469
const string LastNames
Last names
Definition: Constants.cs:384
const string OrgNumber
Organization number
Definition: Constants.cs:464
const string FirstName
First name
Definition: Constants.cs:374
const string OrgName
Organization name
Definition: Constants.cs:459
A set of never changing property constants and helpful values.
Definition: Constants.cs:24
Contains a reference to an attachment assigned to a legal object.
Definition: Attachment.cs:10
Contains personal information found in a legal identity.
Represents a case-insensitive string.
static bool IsNullOrEmpty(CaseInsensitiveString value)
Indicates whether the specified string is null or an CaseInsensitiveString.Empty string.
IdentityState
Lists recognized legal identity states.
Gender
Gender classification in a legal ID.
Definition: Gender.cs:7