MainWindowCod.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.ComponentModel;
  5. using System.Linq;
  6. using System.Runtime.CompilerServices;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Controls;
  10. using Rkis29;
  11. using Rkis29.ViewModel;
  12. using Rkis29.Windows;
  13. namespace Rkis29.Command
  14. {
  15. public class MainWindowCod : BaseViewModel
  16. {
  17. private User _user = new User();
  18. private ObservableCollection<User> _users;
  19. private RelayCommand _NextWindow;
  20. private RelayCommand _RegistrationWindow;
  21. public RelayCommand NextWindow
  22. {
  23. get
  24. {
  25. return _NextWindow ??
  26. (_NextWindow = new RelayCommand(x =>
  27. {
  28. PasswordBox pb = (PasswordBox)x;
  29. using (loferlContext db = new loferlContext())
  30. {
  31. User user_ = db.Users.FirstOrDefault(el => el.Login == User.Login && el.Password == pb.Password);
  32. if (user_ != null)
  33. {
  34. User.AutoUser = user_;
  35. YourProfile Window = new YourProfile();
  36. Window.Show();
  37. foreach (var win in App.Current.Windows)
  38. {
  39. if (win is MainWindow mainWindow)
  40. {
  41. mainWindow.Close();
  42. }
  43. }
  44. }
  45. }
  46. }));
  47. }
  48. }
  49. public RelayCommand RegistrationWindow
  50. {
  51. get
  52. {
  53. return _RegistrationWindow ?? (_RegistrationWindow = new RelayCommand(x =>
  54. {
  55. Registration Window = new Registration();
  56. Window.Show();
  57. foreach (var win in App.Current.Windows)
  58. {
  59. if (win is MainWindow mainWindow)
  60. {
  61. mainWindow.Close();
  62. }
  63. }
  64. }
  65. ));
  66. }
  67. }
  68. public User User
  69. {
  70. get => _user;
  71. set
  72. {
  73. _user = value;
  74. OnPropertyChanged();
  75. }
  76. }
  77. public ObservableCollection<User> Users
  78. {
  79. get => _users;
  80. set
  81. {
  82. _users = value;
  83. OnPropertyChanged();
  84. }
  85. }
  86. public MainWindowCod()
  87. {
  88. loferlContext loferlcontext = new loferlContext();
  89. Users = new ObservableCollection<User>(loferlcontext.Users);
  90. User = new User();
  91. }
  92. }
  93. }