MainWindowViewModel.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using Avalonia.Controls;
  2. using Microsoft.EntityFrameworkCore;
  3. using reactivepril.Models;
  4. using reactivepril.Views;
  5. using ReactiveUI;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using Tmds.DBus.Protocol;
  9. namespace reactivepril.ViewModels
  10. {
  11. public class MainWindowViewModel : ViewModelBase
  12. {
  13. #pragma warning disable CA1822 // Mark members as static
  14. Galochkin41pContext db = new Galochkin41pContext();
  15. string login;
  16. string password;
  17. List<Gender> gendersList;
  18. UserControl page = new Page1();
  19. PersonsViewModel personsVM;
  20. User user;
  21. string name;
  22. string surname;
  23. public Gender idgender;
  24. List<Gender> genderList;
  25. User registruser;
  26. Page2ViewModel page2VM = new Page2ViewModel();
  27. User currentUser;
  28. public int id;
  29. public List<Gender> GenderList { get => genderList; set => this.RaiseAndSetIfChanged(ref genderList, value); }
  30. public string Login { get => login; set => this.RaiseAndSetIfChanged(ref login, value); }
  31. public string Password { get => password; set => this.RaiseAndSetIfChanged(ref password, value); }
  32. public UserControl Page { get => page; set => this.RaiseAndSetIfChanged(ref page, value); }
  33. public string Name { get => name; set => this.RaiseAndSetIfChanged(ref name, value); }
  34. public string Surname { get => surname; set => this.RaiseAndSetIfChanged(ref surname, value); }
  35. public Gender? Idgender { get => idgender; set => this.RaiseAndSetIfChanged(ref idgender, value); }
  36. public User User { get => user; set => this.RaiseAndSetIfChanged(ref user, value); }
  37. public Page2ViewModel Page2VM { get => page2VM; set => page2VM = value; }
  38. public User CurrentUser { get => currentUser; set => this.RaiseAndSetIfChanged(ref currentUser, value); }
  39. public static MainWindowViewModel Self;
  40. public MainWindowViewModel()
  41. {
  42. Self = this;
  43. }
  44. public void AddToTable()
  45. {
  46. registruser = new User { Name = Name, Surname = Surname, Genders = idgender.IdGender, Login = Login, Password = Password, Roles = 2};
  47. db.Users.Add(registruser);
  48. db.SaveChanges();
  49. registruser = db.Users.FirstOrDefault(x=>x.Login == Login);
  50. Page = new Page2Next(User.UserId);
  51. }
  52. public void Enter()
  53. {
  54. registruser = db.Users.FirstOrDefault(x => x.Login == Login && x.Password == Password);
  55. if (registruser == null)
  56. {
  57. Password = "";
  58. }
  59. else
  60. {
  61. switch (registruser.Roles)
  62. {
  63. case 2:
  64. Page = new Page2Next(registruser.UserId); break;
  65. case 1:
  66. Page = new Page2(registruser.UserId); break;
  67. }
  68. }
  69. }
  70. public void Registr()
  71. {
  72. Page = new RegistrPage();
  73. }
  74. }
  75. #pragma warning restore CA1822 // Mark members as static
  76. }