using Avalonia.Controls; using AvaloniaHomeTry.Models; using AvaloniaHomeTry.Views; using ReactiveUI; using System.Linq; namespace AvaloniaHomeTry.ViewModels { public class MainWindowViewModel : ViewModelBase { public int ID; private UserControl uc = new AuthPage(); public UserControl UC { get => uc; set =>this.RaiseAndSetIfChanged(ref uc, value); } AuthPageViewModel contentDbVM = new AuthPageViewModel(); public AuthPageViewModel ContentDbVM { get => contentDbVM; set => contentDbVM = value; } public static MainWindowViewModel Self; public MainWindowViewModel() { Self = this; } public void Registration() => MainWindowViewModel.Self.UC = new RegistrationPage(); public void Enter() { UsersTable? currentUser = db.UsersTable.FirstOrDefault(x=>x.Login == ContentDbVM.Login && x.Password == ContentDbVM.Password); if (currentUser == null) { ContentDbVM.Message = "Нет такого пользователя"; } else { ID = currentUser.Id; switch (currentUser.IdRole) { case 1: UC = new AdminPage(); break; case 2: UC = new UserPage(currentUser.Id); break; } } } } }