RegistrationCod.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows;
  8. using Rkis29.ViewModel;
  9. using Rkis29.Windows;
  10. namespace Rkis29.Command
  11. {
  12. public class RegistrationCod: BaseViewModel
  13. {
  14. private ObservableCollection<User> _users;
  15. private User _user;
  16. private RelayCommand _registration;
  17. private RelayCommand _return;
  18. public RelayCommand Return
  19. {
  20. get
  21. {
  22. return _return ?? (_return = new RelayCommand(x =>
  23. {
  24. MainWindow Window = new MainWindow();
  25. Window.Show();
  26. foreach (var win in App.Current.Windows)
  27. {
  28. if (win is Registration mainWindow)
  29. {
  30. mainWindow.Close();
  31. }
  32. }
  33. }
  34. ));
  35. }
  36. }
  37. public RelayCommand Registration
  38. {
  39. get
  40. {
  41. return _registration ??
  42. (_registration = new RelayCommand((x) =>
  43. {
  44. if ((User.FirstName != null) && (User.Name != null) && (User.LastName != null) && (User.PhonNum != null) && (User.Login != null) && (User.Password != null))
  45. {
  46. loferlContext loferlcontext = new loferlContext();
  47. User user = User;
  48. loferlcontext.Users.Add(user);
  49. loferlcontext.SaveChanges();
  50. user = null;
  51. MainWindow mainWindow = new MainWindow();
  52. mainWindow.Show();
  53. foreach (var window in App.Current.Windows)
  54. {
  55. if (window is Registration registration)
  56. {
  57. registration.Close();
  58. }
  59. }
  60. }
  61. else
  62. {
  63. MessageBox.Show("You are not write to the box ");
  64. }
  65. }));
  66. }
  67. }
  68. public ObservableCollection<User> Users
  69. {
  70. get => _users;
  71. set
  72. {
  73. _users = value;
  74. OnPropertyChanged();
  75. }
  76. }
  77. public User User
  78. {
  79. get => _user;
  80. set
  81. {
  82. _user = value;
  83. OnPropertyChanged();
  84. }
  85. }
  86. public RegistrationCod()
  87. {
  88. loferlContext loferlcontext = new loferlContext();
  89. _users = new ObservableCollection<User>(loferlcontext.Users);
  90. _user = new User();
  91. }
  92. }
  93. }