using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using WpfApp1.Entities; namespace WpfApp1 { /// /// Логика взаимодействия для AddEditPage.xaml /// public partial class AddEditPage : Page { private User _currentUser = new User(); public AddEditPage(User selectedUser) { InitializeComponent(); if (selectedUser != null) _currentUser = selectedUser; DataContext = _currentUser; _currentUser.IsDeleted = false; } private void BtnSave_Click(object sender, RoutedEventArgs e) { StringBuilder errors = new StringBuilder(); if (string.IsNullOrWhiteSpace(_currentUser.Password)) errors.AppendLine("Укажите свой пароль!"); if (string.IsNullOrWhiteSpace(_currentUser.FirstName))errors.AppendLine("Укажите имя!"); if (string.IsNullOrWhiteSpace(_currentUser.MiddleName))errors.AppendLine("Укажите фамилию!"); if (string.IsNullOrWhiteSpace(_currentUser.LastName))errors.AppendLine("Укажите отчество!"); if (string.IsNullOrWhiteSpace(_currentUser.Login))errors.AppendLine("Укажите свой логин!"); if (errors.Length > 0) { MessageBox.Show(errors.ToString()); return; } if (_currentUser.ID == 0) user20Entities.GetContext().User.Add(_currentUser); try { user20Entities.GetContext().SaveChanges(); MessageBox.Show("Данные сохранены!"); Manager.MainFrame.GoBack(); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } } } }