using System; using System.Collections.Generic; using MsBox.Avalonia.Enums; using MsBox.Avalonia; using System.Reactive; using ReactiveUI; using Microsoft.EntityFrameworkCore; using System.Threading.Tasks; using System.Linq; namespace prakt1314.ViewModels { public class AuthPageViewModel : ReactiveObject { public AuthPageViewModel() { AuthorizeCommand = ReactiveCommand.Create(AuthorizeInSystemCommandMethod); } public event Action NotifyUserWasSuccessfulAuthorize; public string Login { get => _login; set => this.RaiseAndSetIfChanged(ref _login, value); } public string Password { get => _password; set => this.RaiseAndSetIfChanged(ref _password, value); } public ReactiveCommand AuthorizeCommand { get; } private string _login; private string _password; private async void AuthorizeInSystemCommandMethod(string param) { UserLogin? user; using (AvaloniaPrakt13DbContext db = new AvaloniaPrakt13DbContext()) { user = db.UserLogins.FirstOrDefault(a => a.Login == Login && a.Password == Password); } if (user is null) { MessageBoxManager.GetMessageBoxStandard("Ошибка авторизации!" , "Пользователь не существует" , ButtonEnum.Ok).ShowAsync(); return; } NotifyUserWasSuccessfulAuthorize(user.IdUser); } } }