示例#1
0
        public RegistrationViewModel(IMvxNavigationService navigationService, IAuthService authService, IUserDialogs userDialogs, IValidator validator /*, ILocationService locationService*/, MvvmCross.Plugins.Validation.IMvxToastService toastService, IBottomNavigationViewModelService bottomNavigationViewModelService, ITopNavigationViewModelService topNavigationViewModelService)
        {
            _navigationService                = navigationService;
            _topNavigationViewModelService    = topNavigationViewModelService;
            _bottomNavigationViewModelService = bottomNavigationViewModelService;

            _authService  = authService;
            _userDialogs  = userDialogs;
            _toastService = toastService;

            _validationHelper = new ValidationHelper(validator, this, Errors.Value, (propertyName) => { FocusName.Value = propertyName; });

            //_locationService = locationService;

            ValidateEmailCommand     = new MvxCommand(() => _validationHelper.Validate(() => Email));
            ValidateFirstNameCommand = new MvxCommand(() => _validationHelper.Validate(() => FirstName));
            ValidateLastNameCommand  = new MvxCommand(() => _validationHelper.Validate(() => LastName));
            ValidatePasswordCommand  = new MvxCommand(() => _validationHelper.Validate(() => Password));
            ValidateBirthDateCommand = new MvxCommand(() => _validationHelper.Validate(() => BirthDate));

            RegisterCommand = new MvxCommand(() =>
            {
                if (!IsTaskExecutedValueConverter.Convert(RegisterTask.Value))
                {
                    RegisterTask.Value = NotifyTaskCompletion.Create(AttemptRegisterAsync);
                }
            });

            ChangeBirthDateCommand = new MvxAsyncCommand(async() => {
                var datePromptResult = await _userDialogs.DatePromptAsync(new DatePromptConfig()
                {
                    MinimumDate = new DateTime(1900, 1, 1), MaximumDate = DateTime.Now, SelectedDate = BirthDate.Value ?? new DateTime?(new DateTime(1990, 1, 1)), OkText = "OK", CancelText = "Cancel"
                });
                if (datePromptResult.Ok)
                {
                    BirthDate.Value = new DateTime?(datePromptResult.SelectedDate);
                }
                else
                {
                    BirthDate.Value = null;
                }
                ValidateBirthDateCommand.Execute(null);
            });

            InitValidationCommand = new MvxCommand(() => {
                _validationHelper.ResetValidation();
            });
        }
        public async Task <(bool Ok, DateTime SelectedDate)> DatePromptAsync(
            DateTime?selectedDate         = null,
            string title                  = null,
            string okText                 = null,
            string cancelText             = null,
            DateTime?minimumDate          = null,
            DateTime?maximumDate          = null,
            CancellationToken cancelToken = default(CancellationToken))
        {
            var config = new DatePromptConfig
            {
                OkText       = okText ?? "Ok",
                CancelText   = cancelText ?? "Cancel",
                SelectedDate = selectedDate,
                MinimumDate  = minimumDate,
                MaximumDate  = maximumDate,
                Title        = title,
            };

            var dialog = await _dialogs.DatePromptAsync(config, cancelToken);

            return(dialog.Ok, dialog.SelectedDate);
        }