using Avalonia.Controls; using ReactiveUI; using System.Linq; namespace prakt1314.ViewModels { public class MainWindowViewModel : ViewModelBase { public MainWindowViewModel() { AuthPageViewModel apvm = new AuthPageViewModel(); apvm.NotifyUserWasSuccessfulAuthorize += NotifyUserWasSuccessfulAuthorize; UserControl = (new ViewLocator()).Build(apvm); } private void NotifyUserWasSuccessfulAuthorize(int userID) { _userID = userID; UserRole role; using (AvaloniaPrakt13DbContext _dbContextForThis = new AvaloniaPrakt13DbContext()) role = _dbContextForThis.UserRoles.Where(a => (a.UserLogins.Where(a => a.IdUser == userID)).LongCount() == 1).First(); switch (role.IdRole) { case 1: { CourcesListViewModel CLVM = new CourcesListViewModel(); UserControl = (new ViewLocator()).Build(CLVM); break; } case 2: { CabinetViewModel CVM = new CabinetViewModel(_userID); UserControl = (new ViewLocator()).Build(CVM); return; } default: { return; } } } public Control UserControl { get => _userControl; set => this.RaiseAndSetIfChanged(ref _userControl, value); } private Control _userControl; private int _userID; } }