public AddUserViewModel(IScreen screen) : base(screen)
        {
            User              = new User();
            Age               = 0;
            Username          = "";
            FullName          = "";
            Educations        = EducationTypeLookup.Load();
            Genders           = GenderTypeLookup.Load();
            MaritalStatus     = MaritalStatusTypeLookup.Load();
            SelectedEducation = Educations.FirstOrDefault();
            SelectedGender    = Genders.FirstOrDefault();
            SelectedMarital   = MaritalStatus.FirstOrDefault();
            Insert            = ReactiveCommand.Create(AddUser);

            this.WhenActivated(d =>
            {
                this.WhenAnyValue(x => x.FullName)
                .WhereNotNull()
                .Where(x => x.HasValue())
                .Where(x => this.Username.IsEmpty())
                .Subscribe(x =>
                {
                    if (!x.HasSpecialCharacters())
                    {
                        var i = 0;
                        var suggestedUsername = x.Remove(" ", "\n");
                        while (UserManager.UserExists(suggestedUsername))
                        {
                            i += 1;
                            suggestedUsername = suggestedUsername + i;
                        }
                        Username = suggestedUsername;
                    }
                }).DisposeWith(d);
            });

            this.ValidationRule(vm => vm.FullName,
                                name => name.HasValue() && name.Length > 2,
                                LanguageHelper.GetString("MustProvideAge", "Text"));

            this.ValidationRule(vm => vm.Username,
                                name => name.HasValue() && name.Length > 2,
                                LanguageHelper.GetString("MustProvideUserName", "Text"));

            this.ValidationRule(vm => vm.Username,
                                name => !name.HasSpecialCharacters() && !name.ContainsAny(' ', '\n'),
                                LanguageHelper.GetString("UserNameHasInvalidChars", "Text"));

            this.ValidationRule(vm => vm.Username,
                                name => !UserManager.UserExists(name),
                                LanguageHelper.GetString("UserExists", "Text"));

            this.ValidationRule(vm => vm.Age,
                                age => age > 4,
                                LanguageHelper.GetString("MustProvideAge", "Text"));
        }
Beispiel #2
0
        /// <summary>
        /// Charge les données initiales à afficher
        /// </summary>
        public override async Task LoadAsync()
        {
            User   = m_Mapper.Map <UserModel>(await m_Repository.GetUserAsync(CurrentSession.Id));
            Gender = Genders.FirstOrDefault(x => x.Equals(User.Gender));

            Email       = User.Email;
            FirstName   = User.FirstName;
            LastName    = User.LastName;
            PhoneNumber = User.PhoneNumber;
            Gender      = User.Gender;
            BirthDate   = User.BirthDate;
        }