1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- 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 MainWindowViewModel()
- {
- }
-
- //Метод для авторизации
- public void Enter()
- {
- currentUser = _db.Logineds
- .Include(x => x.Role)
- .FirstOrDefault(x => x.Login == login && x.Password == password);
- if (currentUser != null)
- {
- Info = $"Добро пожаловать, {currentUser.User.Username}!";
- 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();
- }
- }
|