MainWindowViewModel.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using YtYtAvalonia.Models;
  2. using YtYtAvalonia.Views;
  3. using YtYtAvalonia.ViewModels;
  4. using Avalonia.Controls;
  5. using ReactiveUI;
  6. using YtYtAvalonia.View;
  7. using System.Linq;
  8. namespace YtYtAvalonia.ViewModels
  9. {
  10. public class MainWindowViewModel : ViewModelBase
  11. {
  12. #pragma warning disable CA1822 // Mark members as static
  13. public static SuharevaContext myConnection = new SuharevaContext();
  14. RegistrationViewModel regVM = new RegistrationViewModel(myConnection);
  15. public RegistrationViewModel RegVM { get => regVM; set => regVM = value; }
  16. public UserControl UC { get => uc; set => this.RaiseAndSetIfChanged(ref uc, value); }
  17. private UserControl uc = new LoginView();
  18. public void LoadRegistrationView()
  19. {
  20. UC = new RegistrationView();
  21. }
  22. public void LoadLoginView() => UC = new LoginView();
  23. LoginViewModel loginVM = new LoginViewModel();
  24. public void CreateUser()
  25. {
  26. RegVM = new RegistrationViewModel(myConnection);
  27. UC = new LoginView();
  28. }
  29. public LoginViewModel LoginVM { get => loginVM; set => loginVM = value; }
  30. public void LoadPersonalAccount()
  31. {
  32. User? currentUser = myConnection.Users.FirstOrDefault(x => x.Login == LoginVM.Login && x.Password == LoginVM.Password);
  33. if(currentUser == null)
  34. {
  35. LoginVM.Message = "Пользователя с такими данными не существует!";
  36. }
  37. else
  38. {
  39. LoginVM.Message = "Успех!";
  40. UC = new PersonalAccount();
  41. }
  42. }
  43. public void SaveData()
  44. {
  45. myConnection.SaveChanges();
  46. UC = new LoginView();
  47. }
  48. }
  49. }