123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- 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<MainWindow>()?.Close();
- }
- );
- }
- }
- public RelayCommand? _commandGoRegister;
- public RelayCommand? CommandGoRegister
- {
- get
- {
- return _commandGoRegister ??= new RelayCommand(
- x =>
- {
- new RegistrationWindow().Show();
- AppHelper.GetWindowAtType<MainWindow>()?.Close();
- }
- );
- }
- }
- }
- }
|