Пример #1
0
        public ProfilePageViewModel(INavigationService navigationService, IDataRepoService dataRepoService, IPageDialogService pageDialogService) : base(navigationService)
        {
            _dataRepoService   = dataRepoService;
            _pageDialogService = pageDialogService;

            ValidatePasswordCommand = ReactiveCommand.Create(ValidatePasswordCommandExecute, null);
            ValidatePasswordCommand.ThrownExceptions.Subscribe(error =>
            {
                Debug.WriteLine(error);
                Debugger.Break();
            });

            ValidateDateCommand = ReactiveCommand.Create(ValidateDateCommandExecute, null);
            ValidateDateCommand.ThrownExceptions.Subscribe(error =>
            {
                Debug.WriteLine(error);
                Debugger.Break();
            });

            var canExecute = this.WhenAnyValue(
                x => x.User.FirstName,
                x => x.User.LastName,
                x => x.User.UserName,
                x => x.User.Password,
                x => x.User.Phone,
                x => x.User.StartDate,
                x => x.ErrorMessage,
                (firstName,
                 lastName,
                 username,
                 password,
                 phone,
                 startDate,
                 errorMessage) =>
                !string.IsNullOrEmpty(firstName) &&
                !string.IsNullOrEmpty(lastName) &&
                !string.IsNullOrEmpty(password) &&
                !string.IsNullOrEmpty(phone) &&
                startDate != DateTime.Today &&
                string.IsNullOrEmpty(errorMessage)

                );

            CreateAccountCommand = ReactiveCommand.CreateFromTask(CreateAccountCommandExecute, canExecute);
            CreateAccountCommand.ThrownExceptions.Subscribe(error =>
            {
                Debug.WriteLine(error);
                Debugger.Break();
            });
        }
Пример #2
0
        public LoginPageViewModel(INavigationService navigationService, IDataRepoService dataRepoService) : base(navigationService)
        {
            Title = "Login";

            _dataRepoService = dataRepoService;

            //Reset the error message when changing a form value
            this.WhenAnyValue(
                x => x.UserName, x => x.Password,
                (userName, password) =>
                !string.IsNullOrEmpty(userName) &&
                !string.IsNullOrEmpty(password))
            .Subscribe(x => ErrorMessage = string.Empty);

            var canExecuteLogin = this.WhenAnyValue(
                x => x.UserName, x => x.Password,
                (userName, password) =>
                !string.IsNullOrEmpty(userName) &&
                !string.IsNullOrEmpty(password));

            var canExecute = this.WhenAnyValue(x => x.IsNotBusy);

            LoginUserCommand = ReactiveCommand.CreateFromTask(LoginUserCommandExecute, canExecuteLogin);
            LoginUserCommand.ThrownExceptions.Subscribe(error =>
            {
                Debug.WriteLine(error);
                Debugger.Break();
            });

            CreateAccountCommand = ReactiveCommand.CreateFromTask(CreateAccountCommandExecute, canExecute);
            CreateAccountCommand.ThrownExceptions.Subscribe(error =>
            {
                Debug.WriteLine(error);
                Debugger.Break();
            });

            AddIsBusyObservable(this.WhenAnyObservable(x => x.LoginUserCommand.IsExecuting));
            AddIsBusyObservable(this.WhenAnyObservable(x => x.CreateAccountCommand.IsExecuting));
        }