AddUser.xaml.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Shapes;
  14. namespace olimp8
  15. {
  16. /// <summary>
  17. /// Interaction logic for AddUser.xaml
  18. /// </summary>
  19. public partial class AddUser : Window
  20. {
  21. olimp_8Entities entity = new olimp_8Entities();
  22. public AddUser()
  23. {
  24. InitializeComponent();
  25. RoleBox.ItemsSource = entity.Role.ToList();
  26. }
  27. private void Button_Click(object sender, RoutedEventArgs e)
  28. {
  29. if (string.IsNullOrWhiteSpace(LoginBox.Text) || string.IsNullOrWhiteSpace(PassBox.Text) || string.IsNullOrWhiteSpace(NameBox.Text) || string.IsNullOrWhiteSpace(SurnameBox.Text) || string.IsNullOrWhiteSpace(PatrBox.Text) || string.IsNullOrWhiteSpace(RoleBox.Text))
  30. {
  31. MessageBox.Show("Заполнены не все поля");
  32. return;
  33. }
  34. else
  35. {
  36. User user = new User
  37. {
  38. Login = LoginBox.Text,
  39. Password = PassBox.Text,
  40. Name = NameBox.Text,
  41. Surname = SurnameBox.Text,
  42. Patronymic = PatrBox.Text,
  43. RoleID = Convert.ToInt32(RoleBox.SelectedValue),
  44. UserStatusID = 1
  45. };
  46. entity.User.Add(user);
  47. entity.SaveChanges();
  48. MessageBox.Show("Пользователь " + NameBox.Text + " " + SurnameBox.Text + " добавлен!");
  49. }
  50. }
  51. }
  52. }