12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using WpfApp29.Models;
- namespace WpfApp29.ViewModels
- {
- class RegistrationWindowViewModel : BaseViewModel
- {
- private User? _user;
- public User User
- {
- get { return _user ??= new User(); }
- set { _user = value; OnPropertyChanged(); }
- }
- public RelayCommand? _commandRegister;
- public RelayCommand? CommandRegister
- {
- get
- {
- return _commandRegister ??= new RelayCommand(
- x =>
- {
- MainContext ctx = new MainContext();
-
- if (ctx.Users.Any(u => u.Login == User.Login))
- {
- MessageBox.Show("Такой логин уже занят");
- return;
- }
- if (ctx.Users.Any(u => u.Phone == User.Phone))
- {
- MessageBox.Show("Такой номер телефона уже занят");
- return;
- }
- ctx.Users.Add(User);
- ctx.SaveChanges();
- MainWindow mainWindow = new MainWindow();
- MessageBox.Show(mainWindow, "Вы успешно зарегистрировались");
- mainWindow.Show();
- AppHelper.GetWindowAtType<RegistrationWindow>()?.Close();
- }
- );
- }
- }
- public RelayCommand? _commandGoLogin;
- public RelayCommand? CommandGoLogin
- {
- get
- {
- return _commandGoLogin ??= new RelayCommand(
- x =>
- {
- new MainWindow().Show();
- AppHelper.GetWindowAtType<RegistrationWindow>()?.Close();
- });
- }
- }
- }
- }
|