12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- 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<string>(AuthorizeInSystemCommandMethod);
- }
- public event Action<int> 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<string, Unit> 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);
- }
- }
- }
|