123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- using System;
- using Avalonia.Controls;
- using System.Collections.Generic;
- using ReactiveUI;
- using DatabaseMVVMApp.Models;
- using System.Linq;
- using Microsoft.EntityFrameworkCore;
- using System.Threading;
- using MsBox.Avalonia;
- using MsBox.Avalonia.Models;
- using Avalonia.Notification;
- namespace DatabaseMVVMApp.ViewModels
- {
- public class AllTeachersViewModel : ReactiveObject
- {
- public List<Teacher> Teachers => MainWindowViewModel.connection.Teachers.Include(x => x.Gender).Include(x => x.TeachersCourses).ThenInclude(x => x.Course).Include(x => x.TeachersSubjects).ThenInclude(x => x.Subject).ToList();
- public string Count => Teachers.Count().ToString();
- public INotificationMessageManager Manager { get; } = new NotificationMessageManager();
- public void ToAddPage()
- {
- MainWindowViewModel.Instance.Control = new AddTeacher();
- }
-
- public async void DeleteTeacher(int id)
- {
- var box = MessageBoxManager.GetMessageBoxCustom(
- new MsBox.Avalonia.Dto.MessageBoxCustomParams {
- ButtonDefinitions = new List<ButtonDefinition> {
- new ButtonDefinition { Name = "Äà",},
- new ButtonDefinition { Name = "Îòìåíà",},
- },
- ContentTitle = "Ïðåäóïðåæäåíèå",
- ContentMessage = "Âû óâåðåííû ÷òî õîòèòå óäàëèòü äàííûå ó÷èòåëÿ?",
- Icon = MsBox.Avalonia.Enums.Icon.Warning,
- WindowStartupLocation = WindowStartupLocation.CenterOwner,
- CanResize = false,
- MaxWidth = 500,
- MaxHeight = 800,
- SizeToContent = SizeToContent.WidthAndHeight,
- ShowInCenter = true,
- Topmost = false
- });
- var result = await box.ShowAsync();
- if (result == "Äà")
- {
- Teacher deleteTeacher = MainWindowViewModel.connection.Teachers.First(x => x.Id == id);
- MainWindowViewModel.connection.Teachers.Remove(deleteTeacher);
- MainWindowViewModel.connection.SaveChanges();
- MainWindowViewModel.Instance.Control = new AllTeachers();
- var box1 = MessageBoxManager.GetMessageBoxCustom(
- new MsBox.Avalonia.Dto.MessageBoxCustomParams
- {
- ButtonDefinitions = new List<ButtonDefinition> {
- new ButtonDefinition { Name = "Îê",},
- },
- ContentTitle = "Óâåäîìëåíèå",
- ContentMessage = "Ó÷èòåëü áûë óñïåøíî óäàëåí",
- Icon = MsBox.Avalonia.Enums.Icon.Success,
- WindowStartupLocation = WindowStartupLocation.CenterOwner,
- CanResize = false,
- MaxWidth = 500,
- MaxHeight = 800,
- SizeToContent = SizeToContent.WidthAndHeight,
- ShowInCenter = true,
- Topmost = false
- });
- await box1.ShowAsync();
- }
- }
- public void UpdateTeacher(int id)
- {
- MainWindowViewModel.Instance.Control = new AddTeacher(id);
- }
- }
-
- }
|