123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- 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();
- }
- }
|