MainWindowViewModel.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using Avalonia.Controls;
  2. using pr13.Models;
  3. using ReactiveUI;
  4. using System.Linq;
  5. using System.Net;
  6. namespace pr13.ViewModels
  7. {
  8. public class MainWindowViewModel : ViewModelBase
  9. {
  10. public static PostgresContext DB = new PostgresContext();
  11. UserControl us = new Auth();
  12. public UserControl US
  13. {
  14. get => us;
  15. set => this.RaiseAndSetIfChanged(ref us, value);
  16. }
  17. AuthViewModel authorizationvm = new AuthViewModel();
  18. PersonalCabinetViewModel personalpagevm;
  19. CoursesViewModel coursesvm = new CoursesViewModel();
  20. public AuthViewModel AuthorizationVM
  21. {
  22. get => authorizationvm;
  23. set => authorizationvm = value;
  24. }
  25. public PersonalCabinetViewModel PPVM
  26. {
  27. get => personalpagevm;
  28. set => personalpagevm = value;
  29. }
  30. public CoursesViewModel CourseVM
  31. {
  32. get => coursesvm;
  33. set => coursesvm = value;
  34. }
  35. public void GoAuth()
  36. {
  37. int index = AuthorizationVM.Auth();
  38. if (index != 0)
  39. {
  40. if (DB.Users.Where(x => x.IdUser == index).Select(x => x.IdRole).FirstOrDefault() == 2)
  41. {
  42. PPVM = new PersonalCabinetViewModel(index);
  43. US = new PersonalCabinet();
  44. }
  45. else
  46. {
  47. US = new Courses();
  48. }
  49. }
  50. }
  51. }
  52. }