using AvaloniaApplication2.Models; using Avalonia.Controls; using System.Collections.ObjectModel; using System.Linq; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using AvaloniaPractic; using AvaloniaPractic.Models; namespace AvaloniaApplication2.ViewModels { public partial class MainWindowViewModel: ViewModelBase { Pavlov41pContext _db = new Pavlov41pContext(); [ObservableProperty] string login; [ObservableProperty] string password; [ObservableProperty] string info; [ObservableProperty] Logined? currentUser; [ObservableProperty] UserControl page = new Autorization(); public static MainWindowViewModel Self; public MainWindowViewModel() { Self = this; } //Метод для авторизации public void Enter() { currentUser = _db.Logineds .Include(x => x.Role) .FirstOrDefault(x => x.Login == login && x.Password == password); if (currentUser != null) { Info = "Добро пожаловать!"; Password = ""; //Переход на страницу в зависимости от роли switch (currentUser.Role.Name) { case "admin": Page = new AdminWindow(); break; case "user": Page = new UserWindow(); break; } } else { Info = "Неверный логин или пароль"; Password = ""; } } public void Save() =>_db.SaveChanges(); public void GoBack() => Page = new Autorization(); } }