/
SergeyReHub
/
WPF_Project_TeraTeams
Обзор
Документация
Войти
/
SergeyReHub
/
WPF_Project_TeraTeams
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
ViewModel/RegistrationViewModel.cs
142 строки
4 KB
SergeyReHub
Code_commit
08 дек 2024, 11:43
08 дек 2024, 11:43
33f488f
Код
Авторство
О чём код?
using CursovayaRybakov.Model; using CursovayaRybakov.Navigation; using CursovayaRybakov.Repositories; using CursovayaRybakov.View; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; namespace CursovayaRybakov.ViewModel { public class RegistrationViewModel : ViewModelBase { //properties private WindowService _windowService; private User _user = new User(); private string _password; private string _password_repeat; private string _login; // The same as the Username private IUserRepository _userRepository; private string _textErrorRegistration; //Fields public User OurUser { get { return _user; } set { _user = value; OnPropertyChanged(nameof(_user)); OnPropertyChanged(nameof(OurUser)); } } public string TextErrorRegistration { get { return _textErrorRegistration; } set { _textErrorRegistration = value; OnPropertyChanged(nameof(TextErrorRegistration)); } } public string Login { get { return _login; } set { _login = value; OnPropertyChanged(nameof(Login)); } } public string Password { get { return _password; } set { _password = value; OnPropertyChanged(nameof(Password)); } } public string PasswordRepeat { get { return _password_repeat; } set { _password_repeat = value; OnPropertyChanged(nameof(PasswordRepeat)); } } //Comands public ICommand RegistrationCommand { get; } public ICommand ToEnterWindowCommand { get; } public RegistrationViewModel(WindowService windowService) { _userRepository = new UserRepository(); _windowService = windowService; RegistrationCommand = new ViewModelComand(ExecuteRegistrationCommand, CanExecuteRegistrationCommand); ToEnterWindowCommand = new ViewModelComand(ExecuteToEnterWindowCommand); } //Registration private void ExecuteRegistrationCommand(object obj) { if (Password == PasswordRepeat) { OurUser.Login = Login; OurUser.Password = Password; _userRepository.Add(OurUser); _windowService.ShowWindow(new ListClients()); } else { TextErrorRegistration = "* Password are not matches."; } } private bool CanExecuteRegistrationCommand(object obj) { bool canEx; if (string.IsNullOrWhiteSpace(Login) || string.IsNullOrWhiteSpace(Password) || string.IsNullOrWhiteSpace(PasswordRepeat) || Password.Length < 3 || Password.Length < 3 || Login.Length < 3) { canEx = false; } else { canEx = false; if (_userRepository.Login_exist(Login)) { canEx = true; } } return canEx; } private void ExecuteToEnterWindowCommand(object obj) // function of redirects to MainWindow { _windowService.ShowWindow(new MainWindow()); } } }