Exemplo n.º 1
0
        public override async Task ExecuteAsync(object parameter)
        {
            _loginViewModel.ErrorMessage = string.Empty;

            try
            {
                User user = await _authenticator.Login(_loginViewModel.Username, _loginViewModel.Password);

                string userJson = JsonConvert.SerializeObject(new User()
                {
                    Login  = user.Login,
                    Passwd = user.Passwd,
                    Id     = user.Id
                });

                await File.WriteAllTextAsync("user.json", userJson);

                var a = new UpdateCurrentViewModelCommand(_navigator, user, _authenticator.GetUserContext());
                a.Execute(ViewType.Home);
            }
            catch (Exception ex)
            {
                ErrorView errorView = new ErrorView();
                errorView.DataContext = new ErrorViewModel(ex.Message);
                errorView.ShowDialog();
            }
        }
 public MainViewModel(ICurrentContext navigator, IViewModelFactory viewModelFactory, IUserManager userManager, IRenavigator loginNavigator)
 {
     Navigator        = navigator;
     this.userManager = userManager;
     UpdateCurrentViewModelCommand = new UpdateCurrentViewModelCommand(navigator, viewModelFactory);
     UpdateCurrentViewModelCommand.Execute(ViewType.Login);
     LogoutCommand = new LogoutCommand(userManager, loginNavigator);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Assings all <see cref="ICommand"/>s
 /// </summary>
 /// <param name="navigator"> navigator needed for <see cref="UpdateCurrentViewModelCommand"/></param>
 private void AssignCommands(INavigator navigator)
 {
     UpdateCurrentViewModelCommand = new UpdateCurrentViewModelCommand(navigator);
     MoveGameItemCommand           = new MoveGameItemCommand(this);
     ToggleCPUBoatViewCommand      = new RelayCommand(() => _boatApearanceManager.ToggleBoatView(Computer.Boats));
     UserShootCommand             = new RelayCommand(() => UserShoot());
     NavigateToWinningViewCommand = new RelayCommand(() => _navigator.Navigate(new WinnerViewModel(_navigator, _winner)));
 }
Exemplo n.º 4
0
        public MainViewModel(INavigator navigator, IShopViewModelFactory viewModelFactory)
        {
            _navigator = navigator;
            _navigator.StateChanged += () => { OnPropertyChanged(nameof(CurrentViewModel)); };

            UpdateCurrentViewModelCommand = new UpdateCurrentViewModelCommand(navigator, viewModelFactory);
            UpdateCurrentViewModelCommand.Execute(ViewModelType.Employee);
        }
Exemplo n.º 5
0
 private void AssignCommands(INavigator navigator)
 {
     SwitchSelectedBoatCommand     = new RelayCommand(SwitchSelectedBoat);
     UpdateCurrentViewModelCommand = new UpdateCurrentViewModelCommand(navigator);
     MoveGameItemCommand           = new MoveGameItemCommand(this);
     PlayGameCommand = new RelayCommand(PlayGame);
     SetValidBoatPlacementCommand = new RelayCommand(SetValidBoatPlacement);
 }
Exemplo n.º 6
0
        // Constructors
        #region Constructors

        public ShellViewModel(INavigator navigator, IRootViewModelFactory viewModelFactory)
        {
            _navigator = navigator;
            _navigator.StateChanged    += Navigator_StateChanged;
            _navigator.CurrentViewModel = viewModelFactory.CreateViewModel(ViewType.Home);

            UpdateCurrentViewModelCommand = new UpdateCurrentViewModelCommand(_navigator, viewModelFactory);

            CloseApplicationCommand = new RelayCommand(CloseApplication);
        }
Exemplo n.º 7
0
        public MainViewModel(INavigator navigator, IViewModelFactory viewModelFactory)
        {
            _navigator        = navigator;
            _viewModelFactory = viewModelFactory;

            _navigator.StateChanged += Navigator_StateChanged;

            UpdateCurrentViewModelCommand = new UpdateCurrentViewModelCommand(navigator, _viewModelFactory);
            UpdateCurrentViewModelCommand.Execute(ViewType.Home);

            CloseNavigationDrawerComamnd = new ActionCommand(this, method => CloseNavigationDrawer());
        }
Exemplo n.º 8
0
        public MainViewModel(INavigator navigator, IToDoViewModelFactory viewModelFactory, IAuthenticator authenticator)
        {
            _navigator        = navigator;
            _viewModelFactory = viewModelFactory;
            _authenticator    = authenticator;

            _navigator.StateChanged     += Navigator_StateChanged;
            _authenticator.StateChanged += Authenticator_StateChanged;

            UpdateCurrentViewModelCommand = new UpdateCurrentViewModelCommand(navigator, viewModelFactory);
            UpdateCurrentViewModelCommand.Execute(ViewType.Login);
        }
		public  MainViewModel(INavigator<ViewModelBase> navigator, IRootTaskManagerViewModelFactory taskManagerViewModelFactory, IAuthenticator authenticator) {

			Navigator = navigator;
			Authenticator = authenticator;
			UpdateCurrentViewModelCommand = new UpdateCurrentViewModelCommand(navigator, taskManagerViewModelFactory);
			LogoutCommand = new LogoutCommand(this);
			System.Threading.Tasks.Task<bool> t = System.Threading.Tasks.Task.Run(() => Authenticator.TryToAuthenticateAsync());
			t.Wait();
			bool isAuthenticated =  t.Result;
			if (isAuthenticated) {
				UpdateCurrentViewModelCommand.Execute(ViewType.IssuesTasks);
			}
			else {
				UpdateCurrentViewModelCommand.Execute(ViewType.Login);
			}
		}
Exemplo n.º 10
0
        public override async Task ExecuteAsync(object parameter)
        {
            _registerViewModel.ErrorMessage = string.Empty;

            try
            {
                User user = await _authenticator.Register(_registerViewModel.Email, _registerViewModel.Username, _registerViewModel.Password, _registerViewModel.ConfirmPassword);

                string userJson = JsonSerializer.Serialize <User>(user);
                await File.WriteAllTextAsync("user.json", userJson);

                var a = new UpdateCurrentViewModelCommand(_navigator, user, _authenticator.GetUserContext());
                a.Execute(ViewType.Home);
            }
            catch (Exception ex)
            {
                ErrorView errorView = new ErrorView();
                errorView.DataContext = new ErrorViewModel(ex.Message);
                errorView.ShowDialog();
            }
        }
Exemplo n.º 11
0
 public Navigator(IRootSimpleTraderViewModelFactory viewModelFactory)
 {
     _viewModelFactory      = viewModelFactory;
     UpdateViewModelCommand = new UpdateCurrentViewModelCommand(this, viewModelFactory);
 }
Exemplo n.º 12
0
 public MenuViewModel(INavigator navigator)
 {
     Navigator = navigator;
     UpdateCurrentViewModelCommand = new UpdateCurrentViewModelCommand(navigator);
     LoadGameCommand = new RelayCommand(() => Debug.WriteLine("Load game command pressed"));
 }
Exemplo n.º 13
0
 public WinnerViewModel(INavigator navigator, Player winner)
 {
     _navigator = navigator;
     Winner     = winner;
     UpdateCurrentViewModelCommand = new UpdateCurrentViewModelCommand(navigator);
 }