123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- using Avalonia.Controls;
- using AvaloniaApplication1.Models;
- using AvaloniaApplication1.Views;
- using Microsoft.EntityFrameworkCore;
- using ReactiveUI;
- using System;
- using System.Linq;
- using System.Net.Http;
- using System.Text.Json.Serialization;
- namespace AvaloniaApplication1.ViewModels
- {
- public class MainWindowViewModel : ViewModelBase
- {
- private readonly ApiService _apiService;
- string login;
- string password;
- string info;
- UserControl uc ;
- int id;
- User user = new User();
- public static MainWindowViewModel Self;
- HttpClient client;
- public MainWindowViewModel()
- {
- _apiService = new ApiService();
- Self = this;
- Uc = new UserControl1();
- }
- public string Login { get => login; set => this.RaiseAndSetIfChanged(ref login, value); }
- public int Id { get => id; set => this.RaiseAndSetIfChanged(ref id, value); }
- public string Password { get => password; set => this.RaiseAndSetIfChanged(ref password, value); }
- public string Info { get => info; set => this.RaiseAndSetIfChanged(ref info, value); }
- public UserControl Uc { get => uc; set => this.RaiseAndSetIfChanged(ref uc, value); }
- public void Enter() => Uc = new Enter();
- public void Registrainon() => Uc = new RedistrationPage();
- public async void SignIn()
- {
- User user = await _apiService.GetAsync<User>($"signIn?login={login}&password={password}");
- if (user != null)
- {
- if(user.IdRole == 2)
- {
- Id = user.Id;
- Uc = new AdminPage();
-
- }
- else
- {
- Id = user.Id;
- Uc = new UserPage();
-
- }
- }
- else
- {
- Info = "Неверный логин или пароль";
- Password = "";
- }
- }
-
- }
- }
|