public MainWindowViewModel(IViewModelsFactory factory) { OpenLoginWindow = new DelegateCommand(() => { var vm = factory.LoginWindowViewModel(); vm.Loggined += (sender, e) => { var role = e.Role.Type == "teacher" ? "Преподаватель" : "Студент"; UserName = $"{role}: {e.Name} {e.LastName}"; _user = e; Loggined?.Invoke(this, EventArgs.Empty); if (e.Role.Type.Trim() == "teacher") { Current = factory.TeacherInfoViewModel((Teacher)e); } else { Current = factory.StudentInfoViewModel((Student)e); } }; ViewService.CreateView(vm).ShowDialog(); }); OpenRegisterWindow = new DelegateCommand(() => ViewService.CreateView(factory.RegisterWindowViewModel()).ShowDialog()); OpenAddMaterailWindow = new DelegateCommand(() => { if (_user != null && _user is Teacher) { ViewService.CreateView(factory.AddMaterialWindowViewModel((Teacher)_user)).ShowDialog(); } }); OpenAddTaskWindow = new DelegateCommand(() => { if (_user != null && _user is Teacher) { ViewService.CreateView(factory.AddTaskWindowViewModel((Teacher)_user)).ShowDialog(); } }); OpenAddStudentWindow = new DelegateCommand(() => { if (_user != null && _user is Teacher) { ViewService.CreateView(factory.AddStudentWindowViewModel((Teacher)_user)).ShowDialog(); } }); Logout = new DelegateCommand(() => { _user = null; Current = null; Logouted?.Invoke(this, EventArgs.Empty); }); }
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); }); }