public MainViewModel(AccountService accountService, INavigationService navigationService) { _accountService = accountService; _navigationService = navigationService; if (IsInDesignMode) LoadData(); AddAccountCommand = new RelayCommand(() => { _navigationService.Navigate(typeof(AddAccountPage)); }); BrowseAccountCommand = new RelayCommand<Account>(account => { _navigationService.Navigate(typeof(BrowsePage), account); }); }
public AddAccountViewModel(ConnectionService connectionService, AccountService accountService, INavigationService navigationService) { _connectionService = connectionService; _accountService = accountService; _navigationService = navigationService; AnonymousAccess = false; IsHostValid = false; CheckHostCommand = new RelayCommand(async () => { // TODO: check if really changed IsHostValid = false; var host = Host; if (!host.EndsWith("/")) host = host + "/"; _connectionInfo = await _connectionService.GetConnectionInfo(host); if (_connectionInfo != null) { var auth = await _connectionService.GetAuthenticationInfo(_connectionInfo); if (auth != AuthenticationMethod.Unknown) IsHostValid = true; AnonymousAccess = auth == AuthenticationMethod.None; } }); AddAccountCommand = new RelayCommand(async () => { var newAccount = new Account { IsAnonymous = AnonymousAccess, Protocol = _connectionInfo.WebDAVUrl.Scheme, ServerDomain = _connectionInfo.WebDAVUrl.Host, WebDAVPath = _connectionInfo.WebDAVUrl.LocalPath }; if (!AnonymousAccess) { newAccount.UsernamePlain = UserName; newAccount.PasswordPlain = Password; await _accountService.UpdateCredentials(newAccount); } _accountService.AddAccount(newAccount); await _accountService.SaveAccounts(); if (_navigationService.CanGoBack) _navigationService.GoBack(); else _navigationService.Navigate(typeof(MainPage)); }, () => IsHostValid && (AnonymousAccess || (!string.IsNullOrWhiteSpace(UserName) && !string.IsNullOrEmpty(Password)))); }
public BrowseViewModel(AccountService accountService) { _accountService = accountService; }