1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- using YtYtAvalonia.Models;
- using YtYtAvalonia.Views;
- using YtYtAvalonia.ViewModels;
- using Avalonia.Controls;
- using ReactiveUI;
- using YtYtAvalonia.View;
- using System.Linq;
- namespace YtYtAvalonia.ViewModels
- {
- public class MainWindowViewModel : ViewModelBase
- {
- #pragma warning disable CA1822 // Mark members as static
- public static SuharevaContext myConnection = new SuharevaContext();
- RegistrationViewModel regVM = new RegistrationViewModel(myConnection);
- public RegistrationViewModel RegVM { get => regVM; set => regVM = value; }
- public UserControl UC { get => uc; set => this.RaiseAndSetIfChanged(ref uc, value); }
-
- private UserControl uc = new LoginView();
- public void LoadRegistrationView()
- {
- UC = new RegistrationView();
-
- }
- public void LoadLoginView() => UC = new LoginView();
- LoginViewModel loginVM = new LoginViewModel();
- public void CreateUser()
- {
- RegVM = new RegistrationViewModel(myConnection);
- UC = new LoginView();
- }
-
- public LoginViewModel LoginVM { get => loginVM; set => loginVM = value; }
- public void LoadPersonalAccount()
- {
- User? currentUser = myConnection.Users.FirstOrDefault(x => x.Login == LoginVM.Login && x.Password == LoginVM.Password);
- if(currentUser == null)
- {
- LoginVM.Message = "Пользователя с такими данными не существует!";
- }
- else
- {
- LoginVM.Message = "Успех!";
- UC = new PersonalAccount();
- }
- }
- public void SaveData()
- {
- myConnection.SaveChanges();
- UC = new LoginView();
- }
- }
- }
|