MainWindowViewModel.cs 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using Acosta.Views;
  2. using Avalonia.Controls;
  3. using ReactiveUI;
  4. using Acosta.Models;
  5. using System.Linq;
  6. using Acosta.ViewModels;
  7. namespace Acosta.ViewModels
  8. {
  9. public class MainWindowViewModel : ViewModelBase
  10. {
  11. public static SuharevaContext myConnection = new SuharevaContext();
  12. AuthorizationViewModel authorizationVM = new AuthorizationViewModel();
  13. public AuthorizationViewModel AuthorizationVM { get => authorizationVM; set => authorizationVM = value; }
  14. AddTradeNetworksViewViewModel addTradeNetworksVM = new AddTradeNetworksViewViewModel(myConnection);
  15. public AddTradeNetworksViewViewModel AddTradeNetworksVM { get => addTradeNetworksVM; set => addTradeNetworksVM = value; }
  16. AddEmployeesViewModel addEmployeesViewModel = new AddEmployeesViewModel(myConnection);
  17. public AddEmployeesViewModel AddEmployeesViewModel { get => addEmployeesViewModel; set => addEmployeesViewModel = value; }
  18. public void SaveNetwork()
  19. {
  20. myConnection.SaveChanges();
  21. UC = new TradeNetworksView();
  22. }
  23. public void SaveUser()
  24. {
  25. myConnection.SaveChanges();
  26. UC = new EmployeesView();
  27. }
  28. public UserControl UC { get => uc; set => this.RaiseAndSetIfChanged(ref uc, value); }
  29. private UserControl uc = new AuthorizationView();
  30. public void LoadPersonalAccount()
  31. {
  32. UC = new PersonalAccountView();
  33. Employee? currentUser = myConnection.Employees.FirstOrDefault(x => x.Email == AuthorizationVM.Login && x.Password == AuthorizationVM.Password);
  34. if (currentUser == null)
  35. {
  36. AuthorizationVM.Message = "Пользователя с такими данными не существует.";
  37. }
  38. else if (currentUser.Role != 1)
  39. {
  40. AuthorizationVM.Message = "Ваша роль не соответсвует требованиям.";
  41. }
  42. else
  43. {
  44. AuthorizationVM.Message = "Успех!";
  45. }
  46. }
  47. public void ExitFromProfile()
  48. {
  49. UC = new AuthorizationView();
  50. }
  51. public void AddTradeNetworksView()
  52. {
  53. UC = new AddTradeNetworksView();
  54. }
  55. public void BackTradeNetworksView()
  56. {
  57. UC = new TradeNetworksView();
  58. }
  59. public void AddOutletsView()
  60. {
  61. UC = new AddOutletsView();
  62. }
  63. public void BackOutletsView()
  64. {
  65. UC = new OutletsView();
  66. }
  67. public void EditOutletsView()
  68. {
  69. UC = new EditOutletsView();
  70. }
  71. public void AddEmployeesView()
  72. {
  73. UC = new AddEmployeesView();
  74. }
  75. public void BackEmployeesView()
  76. {
  77. UC = new EmployeesView();
  78. }
  79. public void EditEmployeesView()
  80. {
  81. UC = new EditEmployeesView();
  82. }
  83. }
  84. }