using System; using Prism.Mvvm; using Prism.Commands; using System.Collections.ObjectModel; using WpfAppUI.Model; using System.Windows; namespace WpfAppUI.ViewModel { internal class NewEmploeeViewModel : BindableBase { #region Поля private Window myWindow; private string _surname; private string _name; private string _patronymic; private DateTime _birthday; private string _phone; private string _mail; private Post _post; private DelegateCommand _create; #endregion #region Свойства public string surnameInput { get => _surname; set => _surname = value; } public string nameInput { get => _name; set => _name = value; } public string patronymicInput { get => _patronymic; set => _patronymic = value; } public DateTime birthdayInput { get => _birthday; set => _birthday = (DateTime)value; } public string phoneInput { get => _phone; set => _phone = value; } public string mailInput { get => _mail; set => _mail = value; } public Post SelectedPost { get => _post; set => _post = value; } public ObservableCollection Posts { get; set; } public DelegateCommand Create { get => _create; } #endregion #region Конструктор public NewEmploeeViewModel(Window window) { Posts = new ObservableCollection(); PostDataUpdate(); this.myWindow = window; _create = new DelegateCommand(CreateRealization); } #endregion #region Методы private void PostDataUpdate() { var post = DBRequests.PostRequest(); foreach (var item in post) { Posts.Add(item); } } #endregion #region Реализация методов для связей private void CreateRealization() { if(Emploee.RegexCheckEmail(mailInput)) { if (!string.IsNullOrWhiteSpace(surnameInput) && !string.IsNullOrWhiteSpace(nameInput) && birthdayInput != DateTime.MinValue || !string.IsNullOrWhiteSpace(phoneInput) && !string.IsNullOrWhiteSpace(mailInput) && SelectedPost != null) { if (DBRequests.AddNewEmploee(surnameInput, nameInput, SelectedPost, birthdayInput, phoneInput, mailInput, patronymicInput)) { MessageBox.Show("Сотрудник создан успешно", "Создано"); myWindow.Close(); } else MessageBox.Show("Произошла непредвиденная ошибка", "Ошибка"); } } else MessageBox.Show("Неправильно заполнена почта", "Ошибка"); } #endregion } }