123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Data;
- using AvaloniaApplication5.Models;
- using Microsoft.EntityFrameworkCore;
- using ReactiveUI;
- using System.Text;
- using System.Threading.Tasks;
- using MsBox.Avalonia.Enums;
- using MsBox.Avalonia;
- namespace AvaloniaApplication5.ViewModels
- {
- internal class AddPageViewModel : ViewModelBase
- {
- Teacher? _newTeacher;
- public Teacher? NewTeacher { get => _newTeacher; set => this.RaiseAndSetIfChanged(ref _newTeacher, value); }
-
- public List<TeacherCourse> TeacherCourses { get => _teacherCourses; set => this.RaiseAndSetIfChanged(ref _teacherCourses, value); }
- public AddPageViewModel()
- {
- _newTeacher = new Teacher()
- {
- Gender = new Gender()
- };
- TextButton = "Äîáàâèòü";
- }
- string text_button = "";
- public string TextButton
- {
- get { return text_button; }
- set { this.RaiseAndSetIfChanged(ref text_button, value); }
- }
- public AddPageViewModel(int idt)
- {
- _newTeacher = MainWindowViewModel.myConnection.Teachers.Include(x=>x.Gender).Include(x=>x.TeacherCourses).ThenInclude(x=>x.Course).Include(x=>x.TeacherDisciplines).ThenInclude(x=>x.Discipline).FirstOrDefault(x=>x.Id == idt);
- TeacherCourses = NewTeacher.TeacherCourses.ToList();
- TeacherDisciplines = NewTeacher.TeacherDisciplines.ToList();
-
- TextButton = "Ñîõðàíèòü èçìåíåíèÿ";
-
- }
- public List<Gender> Genders => MainWindowViewModel.myConnection.Genders.ToList();
- public List<Discipline> Disciplines => MainWindowViewModel.myConnection.Disciplines.ToList().Except(_newTeacher.TeacherDisciplines.Select(x =>x.Discipline)).ToList();
- public List<Course> Courses => MainWindowViewModel.myConnection.Courses.ToList().Except(_newTeacher.TeacherCourses.Select(x => x.Course)).ToList();
- public List<TeacherDiscipline> TeacherDisciplines { get => _teacherDisciplines; set => this.RaiseAndSetIfChanged(ref _teacherDisciplines, value); }
-
- List<TeacherCourse>? _teacherCourses;
- List<TeacherDiscipline>? _teacherDisciplines;
-
- Course? selectedCourse;
- Discipline? selectedDiscipline;
- public Course? SelectedCourse
- {
- get => null;
- set
- {
- if(value != null)
- {
- NewTeacher.TeacherCourses.Add(new TeacherCourse()
- {
- Teacher = NewTeacher, Course = value
- });
- TeacherCourses = NewTeacher.TeacherCourses.ToList();
- this.RaisePropertyChanged(nameof(Courses));
- }
- }
- }
- public Discipline? SelectedDiscipline
- {
- get => null;
- set
- {
- if (value != null)
- {
- NewTeacher.TeacherDisciplines.Add(new TeacherDiscipline()
- {
- Teacher = NewTeacher, Discipline = value
- });
- TeacherDisciplines = NewTeacher.TeacherDisciplines.ToList();
- this.RaisePropertyChanged(nameof(Disciplines));
- }
- }
- }
-
- public void DeleteDiscipline(TeacherDiscipline teacherDiscipline)
- {
- NewTeacher.TeacherDisciplines.Remove(teacherDiscipline);
- TeacherDisciplines = NewTeacher.TeacherDisciplines.ToList();
- this.RaisePropertyChanged(nameof(Disciplines));
- }
- public void DeleteCourse(TeacherCourse teacherCourse)
- {
- NewTeacher.TeacherCourses.Remove(teacherCourse);
- TeacherCourses = NewTeacher.TeacherCourses.ToList();
- this.RaisePropertyChanged(nameof(Courses));
- }
- public async void AddTeacher()
- {
-
- if (NewTeacher.Id == 0 && TextButton == "Äîáàâèòü")
- {
- ButtonResult result = await MessageBoxManager.GetMessageBoxStandard("Ïîäòâåðæäåíèå äîáàâëåíèÿ",
- "Ïîäòâåðäèòü äîáàâëåíèå ó÷èòåëÿ?", ButtonEnum.YesNo).ShowAsync();
- if (result == ButtonResult.Yes)
- {
- MainWindowViewModel.myConnection.Teachers.Add(NewTeacher);
- await MessageBoxManager.GetMessageBoxStandard("Ñîîáùåíèå", "Ó÷èòåëü äîáàâëåí", ButtonEnum.Ok).ShowAsync();
- }
- else
- {
- await MessageBoxManager.GetMessageBoxStandard("Îòìåíà", "Äîáàâëåíèå îòìåíåî", ButtonEnum.Ok).ShowAsync();
- }
-
- }
- else {
- ButtonResult result = await MessageBoxManager.GetMessageBoxStandard("Ïîäòâåðæäåíèå ðåäàêòèðîâàíèÿ",
- "Ïîäòâåðäèòü ðåäàêòèðîâàíèå ó÷èòåëÿ?", ButtonEnum.YesNo).ShowAsync();
- if (result == ButtonResult.Yes)
- {
-
- await MessageBoxManager.GetMessageBoxStandard("Ñîîáùåíèå", "Ó÷èòåëü îòðåäàêòèðîâàí", ButtonEnum.Ok).ShowAsync();
- }
- else
- {
- await MessageBoxManager.GetMessageBoxStandard("Îòìåíà", "Ðåäàêòèðîâàíèå îòìåíåíî", ButtonEnum.Ok).ShowAsync();
- }
- }
- MainWindowViewModel.myConnection.SaveChanges();
- MainWindowViewModel.Instance.PageContent = new Show();
- }
- public void ToAddDisCurs()
- {
- MainWindowViewModel.Instance.PageContent = new AddDisCurs();
- }
- string _message = "";
- public string Message
- {
- get => _message;
- set => this.RaiseAndSetIfChanged(ref _message, value);
- }
-
- }
- }
|