public RegisterPageViewModel(INavigationService navigationService, IUserUsecase userUsecase, IUserDialogs userDialogs) : base(navigationService) { _userUsecase = userUsecase; _userDialogs = userDialogs; Name.SetValidateAttribute(() => Name); RegisterCommand = new[] { Name.ObserveHasErrors, _busyNotifier, } .CombineLatestValuesAreAllFalse() .ObserveOn(SynchronizationContext.Current) .ToReactiveCommand() .WithSubscribe(() => { _registerRequested.OnNext(Unit.Default); _userUsecase.Register(Name.Value); }) .AddTo(_disposables); _registerRequested.SelectMany(_ => Observable.Using(() => { return(new CompositeDisposable() { _busyNotifier.ProcessStart(), _userDialogs.Loading(""), }); }, _ => Observable.Amb( _userUsecase.UserRegistered.Select <User, (User?user, Exception?error)>(user => (user, null)), _userUsecase.ErrorOccurred.Select <Exception, (User?user, Exception?error)>(ex => (null, ex))) .Take(1))) .ObserveOn(SynchronizationContext.Current) .Subscribe(async t => { if (t.user is not null) { await _userDialogs.AlertAsync("登録が完了しました", "確認"); await navigationService.NavigateAsync("/MainPage"); } else { await _userDialogs.AlertAsync("登録に失敗しました", "エラー"); } }) .AddTo(_disposables); }
public InitialPageViewModel(INavigationService navigationService, IUserUsecase userUsecase) : base(navigationService) { _userUsecase = userUsecase; _userUsecase.UserExists.Where(x => x.HasValue) .Select(exists => exists !.Value) .ObserveOn(SynchronizationContext.Current) .Subscribe(exists => { if (exists) { navigationService.NavigateAsync("/MainPage"); } else { navigationService.NavigateAsync("/RegisterPage"); } }).AddTo(_disposables); }
public UserController(IUserUsecase userUsecase) { this.userUsecase = userUsecase; }