using Microsoft.EntityFrameworkCore; using MsBox.Avalonia; using MsBox.Avalonia.Dto; using MsBox.Avalonia.Enums; using ReactiveUI; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Teachers.Models; using Teachers.ViewModels; namespace Teachers.ViewModels { internal class TeachersViewModel : ViewModelBase { List _teachersList = MainWindowViewModel.myConnection.Teachers .Include(x => x.GenderNavigation) .Include(x => x.SubjectsTaughts).ThenInclude(x => x.IdSubjectNavigation) .Include(x => x.TeacherCourses).ThenInclude(x => x.IdCourseNavigation) .ToList(); public List TeachersList { get => _teachersList; set => this.RaiseAndSetIfChanged(ref _teachersList, value); } public async void DeleteTeacher(int id) { Teacher teacherForDelete = MainWindowViewModel.myConnection.Teachers.First(x => x.Id == id); ButtonResult result = await MessageBoxManager.GetMessageBoxStandard("Внимание", "Вы уверены, что хотите удалить " + teacherForDelete.FIO + "?", MsBox.Avalonia.Enums.ButtonEnum.YesNo).ShowAsync(); switch (result) { case ButtonResult.Yes: { MainWindowViewModel.myConnection.Teachers.Remove(teacherForDelete); MainWindowViewModel.myConnection.SaveChanges(); MainWindowViewModel.Instance.Us = new TeachersView(); break; } case ButtonResult.No: { break; } } } public void ToAdd() { MainWindowViewModel.Instance.Us = new AddTeacherView(); } public void ToUpdate(int idTeacher) { MainWindowViewModel.Instance.Us = new AddTeacherView(idTeacher); } //public void DeleteTeacher(int id) //{ // Teacher teacherForDelete = MainWindowViewModel.myConnection.Teachers.First(x => x.Id == id); // MainWindowViewModel.myConnection.Teachers.Remove(teacherForDelete); // MainWindowViewModel.myConnection.SaveChanges(); // MainWindowViewModel.Instance.Us = new TeachersView(); //} } }