Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
RegisterIdentityModel.cs
1using System.Globalization;
2using CommunityToolkit.Mvvm.ComponentModel;
3using CommunityToolkit.Mvvm.Input;
10
12{
16 public partial class RegisterIdentityModel : XmppViewModel
17 {
22 : base()
23 {
24 }
25
27 protected override async Task OnInitialize()
28 {
29 await base.OnInitialize();
30
32 }
33
35 protected override Task XmppService_ConnectionStateChanged(object? Sender, XmppState NewState)
36 {
37 return MainThread.InvokeOnMainThreadAsync(async () =>
38 {
39 await base.XmppService_ConnectionStateChanged(Sender, NewState);
40 await this.OnConnected();
41 });
42 }
43
47 protected virtual Task OnConnected()
48 {
50 return Task.CompletedTask;
51 }
52
54 public override void SetIsBusy(bool IsBusy)
55 {
56 base.SetIsBusy(IsBusy);
58 }
59
63 protected virtual void NotifyCommandsCanExecuteChanged()
64 {
65 this.ApplyCommand.NotifyCanExecuteChanged();
66 }
67
71 [ObservableProperty]
72 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
73 [NotifyPropertyChangedFor(nameof(FirstNameOk))]
74 private string? firstName = "";
75
79 [ObservableProperty]
80 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
81 [NotifyPropertyChangedFor(nameof(MiddleNamesOk))]
82 private string? middleNames;
83
87 [ObservableProperty]
88 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
89 [NotifyPropertyChangedFor(nameof(LastNamesOk))]
90 private string? lastNames;
91
95 [ObservableProperty]
96 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
97 [NotifyPropertyChangedFor(nameof(PersonalNumberOk))]
98 private string? personalNumber;
99
103 [ObservableProperty]
104 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
105 [NotifyPropertyChangedFor(nameof(AddressOk))]
106 private string? address;
107
111 [ObservableProperty]
112 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
113 [NotifyPropertyChangedFor(nameof(Address2Ok))]
114 private string? address2;
115
119 [ObservableProperty]
120 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
121 [NotifyPropertyChangedFor(nameof(ZipCodeOk))]
122 private string? zipCode;
123
127 [ObservableProperty]
128 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
129 [NotifyPropertyChangedFor(nameof(AreaOk))]
130 private string? area;
131
135 [ObservableProperty]
136 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
137 [NotifyPropertyChangedFor(nameof(CityOk))]
138 private string? city;
139
143 [ObservableProperty]
144 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
145 [NotifyPropertyChangedFor(nameof(RegionOk))]
146 private string? region;
147
151 [ObservableProperty]
152 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
153 [NotifyPropertyChangedFor(nameof(CountryOk))]
154 private string? countryCode;
155
159 [ObservableProperty]
160 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
161 [NotifyPropertyChangedFor(nameof(NationalityOk))]
162 private string? nationalityCode;
163
167 [ObservableProperty]
168 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
169 [NotifyPropertyChangedFor(nameof(GenderOk))]
170 private string? genderCode;
171
176 [ObservableProperty]
177 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
178 [NotifyPropertyChangedFor(nameof(BirthDateOk))]
179 [NotifyPropertyChangedFor(nameof(NullIfInvalidBirthDate))]
180 private DateTime birthDate = DateTime.Today;
181
185 [ObservableProperty]
186 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
187 [NotifyPropertyChangedFor(nameof(OrgNameOk))]
188 private string? orgName;
189
193 [ObservableProperty]
194 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
195 [NotifyPropertyChangedFor(nameof(OrgNumberOk))]
196 private string? orgNumber;
197
201 [ObservableProperty]
202 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
203 [NotifyPropertyChangedFor(nameof(OrgAddressOk))]
204 private string? orgAddress;
205
209 [ObservableProperty]
210 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
211 [NotifyPropertyChangedFor(nameof(OrgAddress2Ok))]
212 private string? orgAddress2;
213
217 [ObservableProperty]
218 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
219 [NotifyPropertyChangedFor(nameof(OrgZipCodeOk))]
220 private string? orgZipCode;
221
225 [ObservableProperty]
226 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
227 [NotifyPropertyChangedFor(nameof(OrgAreaOk))]
228 private string? orgArea;
229
233 [ObservableProperty]
234 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
235 [NotifyPropertyChangedFor(nameof(OrgCityOk))]
236 private string? orgCity;
237
241 [ObservableProperty]
242 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
243 [NotifyPropertyChangedFor(nameof(OrgRegionOk))]
244 private string? orgRegion;
245
249 [ObservableProperty]
250 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
251 private string? orgCountryCode;
252
256 [ObservableProperty]
257 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
258 [NotifyPropertyChangedFor(nameof(OrgDepartmentOk))]
259 private string? orgDepartment;
260
264 [ObservableProperty]
265 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
266 [NotifyPropertyChangedFor(nameof(OrgRoleOk))]
267 private string? orgRole;
268
272 [ObservableProperty]
273 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
274 private string? phoneNr;
275
279 [ObservableProperty]
280 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
281 private string? eMail;
282
286 [ObservableProperty]
287 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
288 private string? deviceId;
289
293 [ObservableProperty]
294 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
295 private string? jid;
296
300 [ObservableProperty]
301 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
302 [NotifyPropertyChangedFor(nameof(FirstNameOk))]
303 private bool requiresFirstName;
304
308 [ObservableProperty]
309 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
310 [NotifyPropertyChangedFor(nameof(MiddleNamesOk))]
311 private bool requiresMiddleNames;
312
316 [ObservableProperty]
317 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
318 [NotifyPropertyChangedFor(nameof(LastNamesOk))]
319 private bool requiresLastNames;
320
324 [ObservableProperty]
325 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
326 [NotifyPropertyChangedFor(nameof(PersonalNumberOk))]
327 private bool requiresPersonalNumber;
328
332 [ObservableProperty]
333 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
334 [NotifyPropertyChangedFor(nameof(AddressOk))]
335 private bool requiresAddress;
336
340 [ObservableProperty]
341 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
342 [NotifyPropertyChangedFor(nameof(Address2Ok))]
343 private bool requiresAddress2;
344
348 [ObservableProperty]
349 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
350 [NotifyPropertyChangedFor(nameof(ZipCodeOk))]
351 private bool requiresZipCode;
352
356 [ObservableProperty]
357 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
358 [NotifyPropertyChangedFor(nameof(AreaOk))]
359 private bool requiresArea;
360
364 [ObservableProperty]
365 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
366 [NotifyPropertyChangedFor(nameof(CityOk))]
367 private bool requiresCity;
368
372 [ObservableProperty]
373 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
374 [NotifyPropertyChangedFor(nameof(RegionOk))]
375 private bool requiresRegion;
376
380 [ObservableProperty]
381 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
382 [NotifyPropertyChangedFor(nameof(CountryOk))]
383 private bool requiresCountry;
384
388 [ObservableProperty]
389 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
390 [NotifyPropertyChangedFor(nameof(CountryOk))]
391 private bool requiresCountryIso3166;
392
396 [ObservableProperty]
397 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
398 [NotifyPropertyChangedFor(nameof(NationalityOk))]
399 private bool requiresNationality;
400
404 [ObservableProperty]
405 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
406 [NotifyPropertyChangedFor(nameof(GenderOk))]
407 private bool requiresGender;
408
412 [ObservableProperty]
413 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
414 [NotifyPropertyChangedFor(nameof(BirthDateOk))]
415 private bool requiresBirthDate;
416
420 [ObservableProperty]
421 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
422 [NotifyPropertyChangedFor(nameof(OrgNameOk))]
423 private bool requiresOrgName;
424
428 [ObservableProperty]
429 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
430 [NotifyPropertyChangedFor(nameof(OrgDepartmentOk))]
431 private bool requiresOrgDepartment;
432
436 [ObservableProperty]
437 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
438 [NotifyPropertyChangedFor(nameof(OrgRoleOk))]
439 private bool requiresOrgRole;
440
444 [ObservableProperty]
445 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
446 [NotifyPropertyChangedFor(nameof(OrgNumberOk))]
447 private bool requiresOrgNumber;
448
452 [ObservableProperty]
453 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
454 [NotifyPropertyChangedFor(nameof(OrgAddressOk))]
455 private bool requiresOrgAddress;
456
460 [ObservableProperty]
461 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
462 [NotifyPropertyChangedFor(nameof(OrgAddress2Ok))]
463 private bool requiresOrgAddress2;
464
468 [ObservableProperty]
469 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
470 [NotifyPropertyChangedFor(nameof(OrgZipCodeOk))]
471 private bool requiresOrgZipCode;
472
476 [ObservableProperty]
477 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
478 [NotifyPropertyChangedFor(nameof(OrgAreaOk))]
479 private bool requiresOrgArea;
480
484 [ObservableProperty]
485 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
486 [NotifyPropertyChangedFor(nameof(OrgCityOk))]
487 private bool requiresOrgCity;
488
492 [ObservableProperty]
493 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
494 [NotifyPropertyChangedFor(nameof(OrgRegionOk))]
495 private bool requiresOrgRegion;
496
500 [ObservableProperty]
501 [NotifyCanExecuteChangedFor(nameof(ApplyCommand))]
502 [NotifyPropertyChangedFor(nameof(OrgCountryOk))]
503 private bool requiresOrgCountry;
504
508 public bool FirstNameOk => !this.RequiresFirstName || !string.IsNullOrWhiteSpace(this.FirstName);
509
513 public bool MiddleNamesOk => !this.RequiresMiddleNames || !string.IsNullOrWhiteSpace(this.MiddleNames);
514
518 public bool LastNamesOk => !this.RequiresLastNames || !string.IsNullOrWhiteSpace(this.LastNames);
519
524 {
525 get
526 {
527 if (string.IsNullOrWhiteSpace(this.PersonalNumber))
528 return !this.RequiresPersonalNumber;
529
530 if (string.IsNullOrWhiteSpace(this.CountryCode))
531 return false;
532
533 NumberInformation Info = PersonalNumberSchemes.Validate(this.CountryCode, this.PersonalNumber).Result;
534
535 return !Info.IsValid.HasValue || Info.IsValid.Value;
536 }
537 }
538
542 public bool AddressOk => !this.RequiresAddress || !string.IsNullOrWhiteSpace(this.Address);
543
547 public bool Address2Ok => !this.RequiresAddress2 || !string.IsNullOrWhiteSpace(this.Address2);
548
552 public bool ZipCodeOk => !this.RequiresZipCode || !string.IsNullOrWhiteSpace(this.ZipCode);
553
557 public bool AreaOk => !this.RequiresArea || !string.IsNullOrWhiteSpace(this.Area);
558
562 public bool CityOk => !this.RequiresCity || !string.IsNullOrWhiteSpace(this.City);
563
567 public bool RegionOk => !this.RequiresRegion || !string.IsNullOrWhiteSpace(this.Region);
568
572 public bool CountryOk
573 {
574 get
575 {
576 if (string.IsNullOrWhiteSpace(this.CountryCode))
577 return !this.RequiresCountry;
578
579 if (this.RequiresCountryIso3166 && !ISO_3166_1.TryGetCountryByCode(this.CountryCode, out _))
580 return false;
581
582 return true;
583 }
584 }
585
589 public bool NationalityOk
590 {
591 get
592 {
593 if (string.IsNullOrWhiteSpace(this.NationalityCode))
594 return !this.RequiresNationality;
595
596 if (this.RequiresCountryIso3166 && !ISO_3166_1.TryGetCountryByCode(this.NationalityCode, out _))
597 return false;
598
599 return true;
600 }
601 }
602
606 public bool GenderOk
607 {
608 get
609 {
610 if (string.IsNullOrEmpty(this.GenderCode))
611 return !this.RequiresGender;
612
613 return ISO_5218.LetterToGender(this.GenderCode, out _);
614 }
615 }
616
620 public DateTime MaxBirthDate => DateTime.Today.AddYears(-Constants.Age.MinAge);
621
625 public DateTime MinBirthDate => DateTime.Today.AddYears(-Constants.Age.MaxAge);
626
630 public DateTime? NullIfInvalidBirthDate => (this.BirthDate == DateTime.Today) ? null : this.BirthDate;
631
635 public bool BirthDateOk
636 {
637 get
638 {
639 if (this.NullIfInvalidBirthDate.HasValue && (this.BirthDate > this.MaxBirthDate || this.BirthDate < this.MinBirthDate))
640 return false;
641
642 return !this.RequiresBirthDate;
643 }
644 }
645
649 public bool OrgNameOk => !this.RequiresOrgName || !string.IsNullOrWhiteSpace(this.OrgName);
650
654 public bool OrgDepartmentOk => !this.RequiresOrgDepartment || !string.IsNullOrWhiteSpace(this.OrgDepartment);
655
659 public bool OrgRoleOk => !this.RequiresOrgRole || !string.IsNullOrWhiteSpace(this.OrgRole);
660
664 public bool OrgNumberOk => !this.RequiresOrgNumber || !string.IsNullOrEmpty(this.OrgNumber);
665
669 public bool OrgAddressOk => !this.RequiresOrgAddress || !string.IsNullOrWhiteSpace(this.OrgAddress);
670
674 public bool OrgAddress2Ok => !this.RequiresOrgAddress2 || !string.IsNullOrWhiteSpace(this.OrgAddress2);
675
679 public bool OrgZipCodeOk => !this.RequiresOrgZipCode || !string.IsNullOrWhiteSpace(this.OrgZipCode);
680
684 public bool OrgAreaOk => !this.RequiresOrgArea || !string.IsNullOrWhiteSpace(this.OrgArea);
685
689 public bool OrgCityOk => !this.RequiresOrgCity || !string.IsNullOrWhiteSpace(this.OrgCity);
690
694 public bool OrgRegionOk => !this.RequiresOrgRegion || !string.IsNullOrWhiteSpace(this.OrgRegion);
695
699 public bool OrgCountryOk
700 {
701 get
702 {
703 if (string.IsNullOrWhiteSpace(this.OrgCountryCode))
704 return !this.RequiresOrgCountry;
705
706 if (this.RequiresCountryIso3166 && !ISO_3166_1.TryGetCountryByCode(this.OrgCountryCode, out _))
707 return false;
708
709 return true;
710 }
711 }
712
718 public Property[] ToProperties(IXmppService XmppService)
719 {
720 List<Property> Properties = [];
721
722 AddProperty(Properties, Constants.XmppProperties.FirstName, this.FirstName);
723 AddProperty(Properties, Constants.XmppProperties.MiddleNames, this.MiddleNames);
724 AddProperty(Properties, Constants.XmppProperties.LastNames, this.LastNames);
725 AddProperty(Properties, Constants.XmppProperties.PersonalNumber, this.PersonalNumber);
726 AddProperty(Properties, Constants.XmppProperties.Address, this.Address);
727 AddProperty(Properties, Constants.XmppProperties.Address2, this.Address2);
728 AddProperty(Properties, Constants.XmppProperties.ZipCode, this.ZipCode);
729 AddProperty(Properties, Constants.XmppProperties.Area, this.Area);
730 AddProperty(Properties, Constants.XmppProperties.City, this.City);
731 AddProperty(Properties, Constants.XmppProperties.Region, this.Region);
732 AddProperty(Properties, Constants.XmppProperties.Country, ISO_3166_1.ToCode(this.CountryCode));
733 AddProperty(Properties, Constants.XmppProperties.Nationality, ISO_3166_1.ToCode(this.NationalityCode));
734 AddProperty(Properties, Constants.XmppProperties.Gender, this.GenderCode);
735
736 if (this.NullIfInvalidBirthDate.HasValue)
737 {
738 AddProperty(Properties, Constants.XmppProperties.BirthDay, this.NullIfInvalidBirthDate.Value.Day.ToString(CultureInfo.InvariantCulture));
739 AddProperty(Properties, Constants.XmppProperties.BirthMonth, this.NullIfInvalidBirthDate.Value.Month.ToString(CultureInfo.InvariantCulture));
740 AddProperty(Properties, Constants.XmppProperties.BirthYear, this.NullIfInvalidBirthDate.Value.Year.ToString(CultureInfo.InvariantCulture));
741 }
742
743 AddProperty(Properties, Constants.XmppProperties.OrgName, this.OrgName);
744 AddProperty(Properties, Constants.XmppProperties.OrgNumber, this.OrgNumber);
745 AddProperty(Properties, Constants.XmppProperties.OrgDepartment, this.OrgDepartment);
746 AddProperty(Properties, Constants.XmppProperties.OrgRole, this.OrgRole);
747 AddProperty(Properties, Constants.XmppProperties.OrgAddress, this.OrgAddress);
748 AddProperty(Properties, Constants.XmppProperties.OrgAddress2, this.OrgAddress2);
749 AddProperty(Properties, Constants.XmppProperties.OrgZipCode, this.OrgZipCode);
750 AddProperty(Properties, Constants.XmppProperties.OrgArea, this.OrgArea);
751 AddProperty(Properties, Constants.XmppProperties.OrgCity, this.OrgCity);
752 AddProperty(Properties, Constants.XmppProperties.OrgRegion, this.OrgRegion);
753 AddProperty(Properties, Constants.XmppProperties.OrgCountry, ISO_3166_1.ToCode(this.OrgCountryCode));
754 AddProperty(Properties, Constants.XmppProperties.Phone, this.PhoneNr);
755 AddProperty(Properties, Constants.XmppProperties.EMail, this.EMail);
756 AddProperty(Properties, Constants.XmppProperties.DeviceId, this.DeviceId);
757 AddProperty(Properties, Constants.XmppProperties.Jid, XmppService.BareJid);
758
759 return [.. Properties];
760 }
761
762 private static void AddProperty(List<Property> Properties, string PropertyName, string? PropertyValue)
763 {
764 string? s = PropertyValue?.Trim();
765
766 if (!string.IsNullOrWhiteSpace(s))
767 Properties.Add(new Property(PropertyName, s));
768 }
769
778 protected virtual Task SetProperties(LegalIdentity Identity, bool ClearPropertiesNotFound, bool SetPersonalProperties,
779 bool SetOrganizationalProperties, bool SetAppProperties)
780 {
781 if (ClearPropertiesNotFound)
782 {
783 this.FirstName = string.Empty;
784 this.MiddleNames = string.Empty;
785 this.LastNames = string.Empty;
786 this.PersonalNumber = string.Empty;
787 this.Address = string.Empty;
788 this.Address2 = string.Empty;
789 this.ZipCode = string.Empty;
790 this.Area = string.Empty;
791 this.City = string.Empty;
792 this.Region = string.Empty;
793 this.CountryCode = string.Empty;
794 this.NationalityCode = string.Empty;
795 this.GenderCode = string.Empty;
796 this.BirthDate = DateTime.Today;
797 this.OrgName = string.Empty;
798 this.OrgNumber = string.Empty;
799 this.OrgAddress = string.Empty;
800 this.OrgAddress2 = string.Empty;
801 this.OrgZipCode = string.Empty;
802 this.OrgArea = string.Empty;
803 this.OrgCity = string.Empty;
804 this.OrgRegion = string.Empty;
805 this.OrgCountryCode = string.Empty;
806 this.OrgDepartment = string.Empty;
807 this.OrgRole = string.Empty;
808 this.PhoneNr = string.Empty;
809 this.EMail = string.Empty;
810 this.DeviceId = string.Empty;
811 this.Jid = string.Empty;
812 }
813
814 int? BirthDay = null;
815 int? BirthMonth = null;
816 int? BirthYear = null;
817
818 foreach (Property P in Identity.Properties)
819 {
820 switch (P.Name)
821 {
823 if (SetPersonalProperties)
824 this.FirstName = P.Value;
825 break;
826
828 if (SetPersonalProperties)
829 this.MiddleNames = P.Value;
830 break;
831
833 if (SetPersonalProperties)
834 this.LastNames = P.Value;
835 break;
836
838 if (SetPersonalProperties)
839 this.PersonalNumber = P.Value;
840 break;
841
843 if (SetPersonalProperties)
844 this.Address = P.Value;
845 break;
846
848 if (SetPersonalProperties)
849 this.Address2 = P.Value;
850 break;
851
853 if (SetPersonalProperties)
854 this.ZipCode = P.Value;
855 break;
856
858 if (SetPersonalProperties)
859 this.Area = P.Value;
860 break;
861
863 if (SetPersonalProperties)
864 this.City = P.Value;
865 break;
866
868 if (SetPersonalProperties)
869 this.Region = P.Value;
870 break;
871
873 if (SetPersonalProperties)
874 this.CountryCode = P.Value;
875 break;
876
878 if (SetPersonalProperties)
879 this.NationalityCode = P.Value;
880 break;
881
883 if (SetPersonalProperties)
884 this.GenderCode = P.Value;
885 break;
886
888 if (int.TryParse(P.Value, out int i))
889 BirthDay = i;
890 break;
891
893 if (int.TryParse(P.Value, out i))
894 BirthMonth = i;
895 break;
896
898 if (int.TryParse(P.Value, out i))
899 BirthYear = i;
900 break;
901
903 if (SetOrganizationalProperties)
904 this.OrgName = P.Value;
905 break;
906
908 if (SetOrganizationalProperties)
909 this.OrgNumber = P.Value;
910 break;
911
913 if (SetOrganizationalProperties)
914 this.OrgRole = P.Value;
915 break;
916
918 if (SetOrganizationalProperties)
919 this.OrgDepartment = P.Value;
920 break;
921
923 if (SetOrganizationalProperties)
924 this.OrgAddress = P.Value;
925 break;
926
928 if (SetOrganizationalProperties)
929 this.OrgAddress2 = P.Value;
930 break;
931
933 if (SetOrganizationalProperties)
934 this.OrgZipCode = P.Value;
935 break;
936
938 if (SetOrganizationalProperties)
939 this.OrgArea = P.Value;
940 break;
941
943 if (SetOrganizationalProperties)
944 this.OrgCity = P.Value;
945 break;
946
948 if (SetOrganizationalProperties)
949 this.OrgRegion = P.Value;
950 break;
951
953 if (SetOrganizationalProperties)
954 this.OrgCountryCode = P.Value;
955 break;
956
958 this.DeviceId = P.Value;
959 break;
960
962 this.Jid = P.Value;
963 break;
964
966 this.PhoneNr = P.Value;
967 break;
968
970 this.EMail = P.Value;
971 break;
972 }
973 }
974
975 if (SetPersonalProperties && BirthDay.HasValue && BirthMonth.HasValue && BirthYear.HasValue)
976 {
977 try
978 {
979 this.BirthDate = new DateTime(BirthYear.Value, BirthMonth.Value, BirthDay.Value);
980 }
981 catch (Exception ex)
982 {
983 ServiceRef.LogService.LogException(ex);
984 this.BirthDate = DateTime.Today;
985 }
986 }
987
988 if (SetAppProperties)
989 {
990 this.DeviceId = ServiceRef.PlatformSpecific.GetDeviceId();
991 this.Jid = ServiceRef.XmppService.BareJid;
992 this.PhoneNr = ServiceRef.TagProfile.PhoneNumber;
993 this.EMail = ServiceRef.TagProfile.EMail;
994 }
995
996 return Task.CompletedTask;
997 }
998
1002 public virtual bool CanExecuteCommands => !this.IsBusy && this.IsConnected;
1003
1007 public virtual bool CanApply => false;
1008
1012 [RelayCommand(CanExecute = nameof(CanApply))]
1013 protected virtual Task Apply()
1014 {
1015 return Task.CompletedTask; // Do nothing by default.
1016 }
1017
1018 }
1019}
Age-related constants.
Definition: Constants.cs:749
const int MinAge
Minimum age for applying for an ID
Definition: Constants.cs:753
const int MaxAge
Maximum age for applying for an ID
Definition: Constants.cs:758
const string PersonalNumber
Personal number
Definition: Constants.cs:284
const string OrgAddress2
Organization Address line 2
Definition: Constants.cs:364
const string OrgArea
Organization Area
Definition: Constants.cs:369
const string OrgRegion
Organization Region
Definition: Constants.cs:384
const string Nationality
Nationality
Definition: Constants.cs:324
const string BirthYear
Birth Year
Definition: Constants.cs:344
const string OrgCity
Organization City
Definition: Constants.cs:374
const string OrgRole
Organization Role
Definition: Constants.cs:399
const string Phone
Phone number
Definition: Constants.cs:414
const string EMail
e-Mail address
Definition: Constants.cs:419
const string OrgZipCode
Organization Zip Code
Definition: Constants.cs:379
const string MiddleNames
Middle names
Definition: Constants.cs:274
const string OrgCountry
Organization Country
Definition: Constants.cs:389
const string OrgDepartment
Organization Department
Definition: Constants.cs:394
const string Address2
Address line 2
Definition: Constants.cs:294
const string OrgAddress
Organization Address line 1
Definition: Constants.cs:359
const string Address
Address line 1
Definition: Constants.cs:289
const string LastNames
Last names
Definition: Constants.cs:279
const string OrgNumber
Organization number
Definition: Constants.cs:354
const string BirthMonth
Birth Month
Definition: Constants.cs:339
const string FirstName
First name
Definition: Constants.cs:269
const string OrgName
Organization name
Definition: Constants.cs:349
A set of never changing property constants and helpful values.
Definition: Constants.cs:7
Conversion between Country Names and ISO-3166-1 country codes.
Definition: ISO_3166_1.cs:10
static bool TryGetCountryByCode(string? CountryCode, [NotNullWhen(true)] out ISO_3166_Country? Country)
Tries to get the country, given its country code.
Definition: ISO_3166_1.cs:71
static ? string ToCode(string? CountryName)
Converts the name to a country code (if found). If not found, returns the original name.
Definition: ISO_3166_1.cs:113
Static class containing ISO 5218 gender codes
Definition: ISO_5218.cs:9
static bool LetterToGender(string Letter, out ISO_5218_Gender? Gender)
Tries to get the gender label corresponding to an ISO 5218 gender code.
Definition: ISO_5218.cs:40
bool? IsValid
true = valid: PersonalNumber may be normalized. false = invalid null = scheme not applicable,...
Personal Number Schemes available in different countries.
static async Task< NumberInformation > Validate(string CountryCode, string PersonalNumber)
Checks if a personal number is valid, in accordance with registered personal number schemes.
Base class that references services in the app.
Definition: ServiceRef.cs:31
static ILogService LogService
Log service.
Definition: ServiceRef.cs:91
static ITagProfile TagProfile
TAG Profile service.
Definition: ServiceRef.cs:79
static IXmppService XmppService
The XMPP service for XMPP communication.
Definition: ServiceRef.cs:67
virtual bool CanExecuteCommands
Used to find out if a command can execute
DateTime MinBirthDate
Minimum birth date. (i.e. Maximum age.)
Property[] ToProperties(IXmppService XmppService)
Converts the RegisterIdentityModel to an array of .
virtual Task OnConnected()
Gets called when the app gets connected.
override async Task OnInitialize()
Method called when view is initialized for the first time. Use this method to implement registration ...
RegisterIdentityModel()
The data model for registering an identity.
virtual bool CanApply
If user can apply for an identity.
DateTime MaxBirthDate
Maximum birth date. (i.e. Minimum age.)
override Task XmppService_ConnectionStateChanged(object? Sender, XmppState NewState)
Listens to connection state changes from the XMPP server.
virtual void NotifyCommandsCanExecuteChanged()
Updates status of commands.
override void SetIsBusy(bool IsBusy)
Sets the IsBusy property.
virtual Task SetProperties(LegalIdentity Identity, bool ClearPropertiesNotFound, bool SetPersonalProperties, bool SetOrganizationalProperties, bool SetAppProperties)
Sets the properties of the view model.
DateTime? NullIfInvalidBirthDate
Returns null if birth date is the minimum birth date. Else returns BirthDate.
virtual Task Apply()
Executes the application command.
A view model that holds the XMPP state.
Represents an abstraction of a connection to an XMPP Server.
Definition: IXmppService.cs:35
string BareJid
The Bare Jid of the current connection, or null.
Definition: IXmppService.cs:72
XmppState
State of XMPP connection.
Definition: XmppState.cs:7