MainWindowViewModel.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using Avalonia.Controls;
  2. using AvaloniaExample.Models;
  3. using AvaloniaExample.Views;
  4. using Microsoft.EntityFrameworkCore;
  5. using ReactiveUI;
  6. using System;
  7. using System.Linq;
  8. using Tmds.DBus.Protocol;
  9. namespace AvaloniaExample.ViewModels
  10. {
  11. public class MainWindowViewModel : ViewModelBase
  12. {
  13. UserControl uc = new Page1();
  14. Page1ViewModel page1VM = new Page1ViewModel();
  15. public Page1ViewModel Page1VM { get => page1VM; set => page1VM = value; }
  16. public UserControl UC { get => uc; set => this.RaiseAndSetIfChanged(ref uc, value); }
  17. public static UsersContext connection = new UsersContext();
  18. UserProfileViewModel page3VM;
  19. public UserProfileViewModel Page3VM { get => page3VM; set => page3VM = value; }
  20. public void LoadPage2()
  21. {
  22. Login? curUser = connection.Logins.FirstOrDefault(x => x.Value == Page1VM.Login && x.Password == Page1VM.Password);
  23. if (curUser == null)
  24. {
  25. Page1VM.Message = "Error. Try again";
  26. Page1VM.Login = "";
  27. Page1VM.Password = "";
  28. }
  29. else
  30. {
  31. switch (curUser.Role)
  32. {
  33. case "администратор":
  34. UC = new Page2();
  35. break;
  36. default:
  37. Page3VM = new UserProfileViewModel(connection, curUser.Value);
  38. UC = new Page3();
  39. break;
  40. }
  41. }
  42. var u = connection.UsersInfos.FirstOrDefault();
  43. var l = connection.Logins.FirstOrDefault();
  44. }
  45. public void SaveChanges() => connection.SaveChanges();
  46. }
  47. }