|
@@ -5,33 +5,39 @@ using System.Data;
|
|
|
using AvaloniaApplication5.Models;
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
using ReactiveUI;
|
|
|
+using System.Text;
|
|
|
+using System.Threading.Tasks;
|
|
|
|
|
|
namespace AvaloniaApplication5.ViewModels
|
|
|
{
|
|
|
internal class AddPageViewModel : ViewModelBase
|
|
|
{
|
|
|
Teacher? _newTeacher;
|
|
|
-
|
|
|
- public List<TeacherCourse> TeacherCourses { get => _teacherCourses; set => this.RaiseAndSetIfChanged(ref _teacherCourses, value); }
|
|
|
- public Teacher? NewTeacher { get => _newTeacher; set => this.RaiseAndSetIfChanged(ref _newTeacher, value); }
|
|
|
- public AddPageViewModel()
|
|
|
+ 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()
|
|
|
};
|
|
|
}
|
|
|
- public AddPageViewModel(int id)
|
|
|
+ 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 == id);
|
|
|
+ _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();
|
|
|
}
|
|
|
public List<Gender> Genders => MainWindowViewModel.myConnection.Genders.ToList();
|
|
|
- public List<Discipline> Disciplines => MainWindowViewModel.myConnection.Disciplines.ToList();
|
|
|
- public List<Course> Courses => MainWindowViewModel.myConnection.Courses.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;
|
|
|
- public List<TeacherDiscipline> TeacherDisciplines { get => _teacherDisciplines; set => this.RaiseAndSetIfChanged(ref _teacherDisciplines, value); }
|
|
|
+
|
|
|
Course? selectedCourse;
|
|
|
Discipline? selectedDiscipline;
|
|
|
public Course? SelectedCourse
|
|
@@ -69,13 +75,18 @@ namespace AvaloniaApplication5.ViewModels
|
|
|
|
|
|
|
|
|
|
|
|
- public void DeleteDiscipline(int id)
|
|
|
+ public void DeleteDiscipline(TeacherDiscipline teacherDiscipline)
|
|
|
{
|
|
|
- NewTeacher.TeacherDisciplines.Remove(NewTeacher.TeacherDisciplines.FirstOrDefault(x => x.Id == id));
|
|
|
+ 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 void AddTeacher()
|
|
|
{
|
|
|
if(NewTeacher.Id == 0)
|