123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- using MVVM;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Windows;
- using System.Windows.Controls;
- namespace Work29
- {
- public class MainWindowViewModel : BaseViewModel
- {
- private ObservableCollection<User> _users;
- private User _user;
- private RelayCommand _autoReady;
- private RelayCommand _regNew;
- public RelayCommand AutoReady
- {
- get
- {
- return _autoReady ??
- (_autoReady = new RelayCommand(x =>
- {
- if (x is PasswordBox password)
- {
- Work29Context wpfContext = new Work29Context();
- User user = Users.FirstOrDefault(p => p.Login == User.Login && p.Password == password.Password);
- if (user != null)
- {
- User.a_user = user;
- UserWindow userwindow = new UserWindow();
- userwindow.Show();
- foreach (var window in App.Current.Windows)
- {
- if (window is MainWindow mainWindow)
- {
- mainWindow.Close();
- }
- }
- }
- else
- {
- MessageBox.Show("Ошибка авторизации!!!");
- }
- }
- }
- ));
- }
- }
- public RelayCommand RegNew
- {
- get
- {
- return _regNew ??
- (_regNew = new RelayCommand(x =>
- {
- RegWindow userWindow = new RegWindow();
- userWindow.Show();
- foreach (var window in App.Current.Windows)
- {
- if (window is MainWindow mainWindow)
- {
- mainWindow.Close();
- }
- }
- }
- ));
- }
- }
- public User User
- {
- get => _user;
- set
- {
- _user = value;
- OnPropertyChanged();
- }
- }
- public ObservableCollection<User> Users
- {
- get => _users;
- set
- {
- _users = value;
- OnPropertyChanged();
- }
- }
- public MainWindowViewModel()
- {
- Work29Context context = new Work29Context();
- _user = new User();
- _users = new ObservableCollection<User>(context.Users);
- }
- }
- }
|