123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- using Prism.Commands;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Windows;
- using WpfAppUI.Model;
- using Prism.Mvvm;
- using System.Diagnostics;
- namespace WpfAppUI.ViewModel
- {
- internal class EditEmploeeViewModel : BindableBase
- {
- #region Поля
- private string _surname;
- private string _name;
- private string _patronymic;
- private string _birthday;
- private string _phone;
- private string _mail;
- private Post _post;
- private DelegateCommand _update;
- private int id;
- private Window window;
- #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 string birthdayInput { get => _birthday; set => _birthday = 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<Post> Posts { get; set; }
- public DelegateCommand Update { get => _update; set => _update = value; }
- #endregion
- #region Коструктор
- public EditEmploeeViewModel(int id, Window window)
- {
- this.window = window;
- _update = new DelegateCommand(UpdateRealization);
- Posts = new ObservableCollection<Post>(PostDataUpdate());
- this.id = id;
- UploadAllDataRecive(id);
- }
- #endregion
- #region Реализация методов для привязки
- private void UpdateRealization()
- {
- Debugger.Launch();
- if (Emploee.RegexCheckEmail(mailInput))
- {
- DBRequests.ChangeEmploeeData(id, surnameInput, nameInput, SelectedPost, DateTime.Parse(birthdayInput), phoneInput, mailInput, patronymicInput);
- window.Close();
- } else
- MessageBox.Show("Неправильно заполнена почта", "Ошибка");
- }
- #endregion
- #region Методы
- private void UploadAllDataRecive(int id)
- {
- var emploee = DBRequests.EmploeeById(id);
- surnameInput = emploee.Surname;
- nameInput = emploee.Name;
- patronymicInput = emploee.Patronymic;
- birthdayInput = emploee.Birthday.ToString();
- phoneInput = emploee.Phone;
- mailInput = emploee.Mail;
- SelectedPost = Posts[emploee.PostId - 1];
- }
- private ICollection<Post> PostDataUpdate()
- {
- return DBRequests.PostRequest();
- }
- #endregion
- }
- }
|