using Avalonia.Controls; using AvaloniaApplication5.Models; //using AvaloniaApplication5.Models; using AvaloniaApplication5.Views; using Microsoft.EntityFrameworkCore; using ReactiveUI; using System.Collections.Generic; using System.Linq; using Tmds.DBus.Protocol; namespace AvaloniaApplication5.ViewModels { public class MainWindowViewModel : ViewModelBase { static _1234Context DBConnect = new _1234Context(); private UserControl uc = new PageLogin(); public UserControl UC { get => uc; set => this.RaiseAndSetIfChanged(ref uc, value); } #region VMLogin PageLoginViewModel pageLoginVM = new PageLoginViewModel(); public PageLoginViewModel PageLoginVM { get => pageLoginVM; set => pageLoginVM = value; } public void LoadPageList() { Logintable? currentUser = DBConnect.Logintables.FirstOrDefault(x => x.Login == PageLoginVM.Login && x.Password == PageLoginVM.Password); if (currentUser != null) { switch (currentUser.IdRole) { case 1: UC = new PageUserList(); break; case 2: PageUCabinetVM = new PageUserCabinetViewModel(DBConnect, currentUser.Id); UC = new PageUserCabinet(); break; } } else PageLoginVM.Message = "Пользователь отсутствует в системе, либо указанные данные введены неверно"; } #endregion #region VMUserCabinet private PageUserCabinetViewModel pageUCabinetVM; public PageUserCabinetViewModel PageUCabinetVM { get => pageUCabinetVM; set => pageUCabinetVM = value; } #endregion #region VMadmin private PageUserListViewModel pageUserListViewVM = new PageUserListViewModel(DBConnect); public PageUserListViewModel PageUserListViewVM { get => pageUserListViewVM; set => pageUserListViewVM = value; } UserControl ucAdmin; public UserControl UCAdmin { get => ucAdmin; set => this.RaiseAndSetIfChanged(ref ucAdmin, value); } public void EditUser(int id) { PageUCabinetVM = id == 0 ? new PageUserCabinetViewModel(DBConnect) : new PageUserCabinetViewModel(DBConnect, id); UCAdmin = new PageUserCabinet(); } public void DeleteUser(int id) { Logintable? delUser = DBConnect.Logintables.FirstOrDefault(x => x.Id == id); DBConnect.Logintables.Remove(delUser); DBConnect.SaveChanges(); UC = new PageUserList();//для обновления списка на странице } #endregion } }