12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- using Avalonia.Controls;
- using Microsoft.EntityFrameworkCore;
- using reactivepril.Models;
- using reactivepril.Views;
- using ReactiveUI;
- using System.Collections.Generic;
- using System.Linq;
- using Tmds.DBus.Protocol;
- namespace reactivepril.ViewModels
- {
- public class MainWindowViewModel : ViewModelBase
- {
- #pragma warning disable CA1822 // Mark members as static
- Galochkin41pContext db = new Galochkin41pContext();
- string login;
- string password;
- List<Gender> gendersList;
- UserControl page = new Page1();
- PersonsViewModel personsVM;
- User user;
- string name;
- string surname;
- public Gender idgender;
- List<Gender> genderList;
- User registruser;
- Page2ViewModel page2VM = new Page2ViewModel();
- User currentUser;
- public int id;
- public List<Gender> GenderList { get => genderList; set => this.RaiseAndSetIfChanged(ref genderList, value); }
- public string Login { get => login; set => this.RaiseAndSetIfChanged(ref login, value); }
- public string Password { get => password; set => this.RaiseAndSetIfChanged(ref password, value); }
- public UserControl Page { get => page; set => this.RaiseAndSetIfChanged(ref page, value); }
- public string Name { get => name; set => this.RaiseAndSetIfChanged(ref name, value); }
- public string Surname { get => surname; set => this.RaiseAndSetIfChanged(ref surname, value); }
- public Gender? Idgender { get => idgender; set => this.RaiseAndSetIfChanged(ref idgender, value); }
- public User User { get => user; set => this.RaiseAndSetIfChanged(ref user, value); }
- public Page2ViewModel Page2VM { get => page2VM; set => page2VM = value; }
- public User CurrentUser { get => currentUser; set => this.RaiseAndSetIfChanged(ref currentUser, value); }
- public static MainWindowViewModel Self;
- public MainWindowViewModel()
- {
- Self = this;
-
- }
- public void AddToTable()
- {
- registruser = new User { Name = Name, Surname = Surname, Genders = idgender.IdGender, Login = Login, Password = Password, Roles = 2};
- db.Users.Add(registruser);
- db.SaveChanges();
- registruser = db.Users.FirstOrDefault(x=>x.Login == Login);
-
- Page = new Page2Next(User.UserId);
- }
- public void Enter()
- {
- registruser = db.Users.FirstOrDefault(x => x.Login == Login && x.Password == Password);
- if (registruser == null)
- {
- Password = "";
- }
- else
- {
- switch (registruser.Roles)
- {
- case 2:
- Page = new Page2Next(registruser.UserId); break;
- case 1:
- Page = new Page2(registruser.UserId); break;
- }
- }
- }
- public void Registr()
- {
- Page = new RegistrPage();
- }
- }
- #pragma warning restore CA1822 // Mark members as static
- }
|