Ejemplo n.º 1
0
        public LoginWindowViewModel(ILoginManager loginManager)
        {
            _login = new DelegateCommand(() => {
                if (ViewService.GetIfOpened(out var view, this))
                {
                    User user = loginManager.LoginAsync(new Business.Models.LoginInfo(Name, LastName, ViewService.GetPasswordHandler(view).GetPassword()));
                    if (user != null)
                    {
                        Loggined?.Invoke(this, user);
                        view.Close();
                    }
                    else
                    {
                        ViewService.MessageError("Пользователь не найден", "loginError");
                    }
                }
            },
                                         () => {
                if (ViewService.GetIfOpened(out var view, this))
                {
                    var _pHandler = ViewService.GetPasswordHandler(view);
                    if (!_handled)
                    {
                        _pHandler.PasswordUpdated += (sender, e) => _login?.CanExecuteStateChanged();
                        _handled = true;
                    }

                    var password = _pHandler.GetPassword();
                    if (Name?.Trim() != "" && LastName?.Trim() != "" && password != "")
                    {
                        return(true);
                    }
                }
                return(false);
            });
        }