123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- using AvaloniaBaseTeacher.Models;
- using Microsoft.EntityFrameworkCore;
- using MsBox.Avalonia;
- using MsBox.Avalonia.Enums;
- using ReactiveUI;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace AvaloniaBaseTeacher.ViewModels
- {
- internal class add : ViewModelBase
- {
- public string ButtonName;
- public string message;
- public string message1;
- public string Button
- {
- get => ButtonName;
- set => this.RaiseAndSetIfChanged(ref ButtonName, value);
- }
- public string Message
- {
- get => message;
- set => this.RaiseAndSetIfChanged(ref message, value);
- }
- public string Message1
- {
- get => message1;
- set => this.RaiseAndSetIfChanged(ref message1, value);
- }
- Teacher? _newTeacher;
- public Teacher? NewTeacher
- {
- get => _newTeacher;
- set => this.RaiseAndSetIfChanged(ref _newTeacher, value);
- }
- public add()
- {
- _newTeacher = new Teacher() { GenderNavigation = new Gender() };
- ButtonName = "Добавить";
- Message = "Вы точно хотите добавить пользователя?";
- Message1 = "Пользователь добавлен";
- }
- public add(int TeacherId)
- {
- _newTeacher = MainWindowViewModel.myConnection.Teachers.Include(x => x.GenderNavigation).Include(x => x.Course1Teachers).ThenInclude(x => x.IdCourseNavigation).Include(x => x.Discipline1Teachers).ThenInclude(x => x.IdDisciplineNavigation).FirstOrDefault(x => x.IdTeacher == TeacherId);
- Course1Teachers = NewTeacher.Course1Teachers.ToList();
- Discipline1Teachers = NewTeacher.Discipline1Teachers.ToList();
- ButtonName = "Сохранить изменения";
- Message = "Вы точно хотите изменить?";
- Message1 = "Пользователь изменен";
- }
- public List<Gender> genders => MainWindowViewModel.myConnection.Genders.ToList();
- public List<Course> courses => MainWindowViewModel.myConnection.Courses.ToList().Except(_newTeacher.Course1Teachers.Select(x => x.IdCourseNavigation)).ToList();
- public List<Discipline> disciplines => MainWindowViewModel.myConnection.Disciplines.ToList().Except(_newTeacher.Discipline1Teachers.Select(x=>x.IdDisciplineNavigation)).ToList();
-
- List<Course1Teacher>? _Course1Teach;
- public List<Course1Teacher>? Course1Teachers
- {
- get => _Course1Teach;
- set=>this.RaiseAndSetIfChanged(ref _Course1Teach, value);
- }
- List<Discipline1Teacher>? _Discipline1Teac;
- public List<Discipline1Teacher>? Discipline1Teachers
- {
- get => _Discipline1Teac;
- set => this.RaiseAndSetIfChanged(ref _Discipline1Teac, value);
- }
- public Course? SelectedCourse
- {
- get => null;
- set
- {
- if(value != null)
- {
- NewTeacher.Course1Teachers.Add(new Course1Teacher() {IdTeacherNavigation = NewTeacher, IdCourseNavigation = value});
- Course1Teachers = NewTeacher.Course1Teachers.ToList();
- this.RaisePropertyChanged(nameof(courses));
- }
- }
- }
- public Discipline? SelectedDiscipline
- {
- get => null;
- set
- {
- if (value != null)
- {
- NewTeacher.Discipline1Teachers.Add(new Discipline1Teacher() { IdTeacherNavigation = NewTeacher, IdDisciplineNavigation = value });
- Discipline1Teachers = NewTeacher.Discipline1Teachers.ToList();
- this.RaisePropertyChanged(nameof(disciplines));
- }
- }
- }
- public void DeleteCourse(int id)
- {
- NewTeacher.Course1Teachers.Remove(NewTeacher.Course1Teachers.FirstOrDefault(x => x.Id == id));
- Course1Teachers = NewTeacher.Course1Teachers.ToList();
- this.RaisePropertyChanged(nameof(courses));
- }
- public void DeleteDiscipline(int id)
- {
- NewTeacher.Discipline1Teachers.Remove(NewTeacher.Discipline1Teachers.FirstOrDefault(x => x.Id == id));
- Discipline1Teachers = NewTeacher.Discipline1Teachers.ToList();
- this.RaisePropertyChanged(nameof(disciplines));
- }
- public async Task AddTeacher()
- {
- ButtonResult result = await MessageBoxManager.GetMessageBoxStandard("Вы уверенны?", Message, ButtonEnum.YesNo).ShowAsync();
- if (result == ButtonResult.Yes)
- {
- if (NewTeacher.IdTeacher == 0)
- {
- MainWindowViewModel.myConnection.Teachers.Add(NewTeacher);
- }
- MainWindowViewModel.myConnection.SaveChanges();
- MainWindowViewModel.Instance.PageContent = new Show();
- ButtonResult result1 = await MessageBoxManager.GetMessageBoxStandard("Успешно", Message1, ButtonEnum.Ok).ShowAsync();
- }
- else { }
- }
- public void AddCoursePage()
- {
- MainWindowViewModel.Instance.PageContent = new AddCourse();
- }
- }
- }
|