1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- using MVVM;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- namespace Work29.ViewModels
- {
- public class RegWindowViewModel : BaseViewModel
- {
- private User _user;
- private RelayCommand _createUser;
- public RelayCommand CreateUser
- {
- get
- {
- return _createUser ??
- (_createUser = new RelayCommand(x =>
- {
- string stroka = "";
- User user = User;
- if ((User.Surname != stroka) && (User.Name != stroka)
- && (User.Patronimyc != stroka) && (User.Login != stroka)
- && (User.Password != stroka) && (User.Phone != stroka))
- {
- Work29Context context = new Work29Context();
- context.Users.Add(user);
- context.SaveChanges();
- user = new User();
- MainWindow mainWindow = new MainWindow();
- mainWindow.Show();
- foreach (var window in App.Current.Windows)
- {
- if (window is RegWindow regWindow)
- {
- regWindow.Close();
- }
- }
- }
- else
- {
- MessageBox.Show("Все поля должны быть заполнены!");
- }
- }
- ));
- }
- }
- public User User
- {
- get => _user;
- set
- {
- _user = value;
- OnPropertyChanged();
- }
- }
- public RegWindowViewModel()
- {
- Work29Context context = new Work29Context();
- _user = new User();
- }
- }
- }
|