using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using WpfApp29.Models; namespace WpfApp29.ViewModels { internal class MainWindowViewModel : BaseViewModel { public User? _user; public User User { get => _user ??= new User(); set { _user = value; OnPropertyChanged(); } } public RelayCommand? _commandLogin; public RelayCommand CommandLogin { get { return _commandLogin ??= new RelayCommand( x => { User.Password = (x as PasswordBox)?.Password ?? ""; MainContext ctx = new MainContext(); User? user = ctx.Users.FirstOrDefault(u => u.Login == User.Login && u.Password == User.Password); if (user == null) { MessageBox.Show("Вы ввели неверные логин или пароль"); return; } User.CurrentUser = user; new UserWindow().Show(); AppHelper.GetWindowAtType()?.Close(); } ); } } public RelayCommand? _commandGoRegister; public RelayCommand? CommandGoRegister { get { return _commandGoRegister ??= new RelayCommand( x => { new RegistrationWindow().Show(); AppHelper.GetWindowAtType()?.Close(); } ); } } } }