123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- using TeacheresAndCourses.Models;
- using System;
- using System.Collections.Generic;
- using ReactiveUI;
- using System.Linq;
- using Microsoft.EntityFrameworkCore;
- using System.Diagnostics;
- using System.Data;
- using MsBox.Avalonia.Enums;
- using MsBox.Avalonia;
- namespace TeacheresAndCourses.ViewModels
- {
- public class TeachersPageViewModel : ViewModelBase
- {
- List<Teacher> teachersList;
- public List<Teacher> TeachersList { get => teachersList; set => this.RaiseAndSetIfChanged(ref teachersList, value); }
- public TeachersPageViewModel() {
- teachersList = MainWindowViewModel.connection.Teachers.Include(x => x.GenderNavigation).
- Include(x => x.TeachersAndCourses).ThenInclude(x => x.Course).
- Include(x => x.TeachersAndSubjects).ThenInclude(x => x.Subject).ToList();
- }
- public void ToAddingPage()
- {
- MainWindowViewModel.Instance.Uc = new AddTeacher();
- }
- //Ñâîéñòâà äëÿ âûáîðêè ïî ÔÈÎ
- string searchLine;
- public string SearchLine { get => searchLine; set { searchLine = value; AllSort(); } }
- // Ñâîéñòâà äëÿ âûáîðêè ïî ïðåäìåòó
- List<Subject> subjectsList = [new Subject() { Subjectid = 0, Title = "Âñå ïðåäìåòû" }, ..MainWindowViewModel.connection.Subjects.ToList()];
- public List<Subject> SubjectsList { get => subjectsList; }
- Subject selectedSubject = null;
- public Subject SelectedSubject {
- get {
- if (selectedSubject == null) return subjectsList[0];
- else return selectedSubject;
- }
- set {
- selectedSubject = value;
- }
- }
- // Ñâîéñòâà äëÿ âûáîðêè ïî ïîëó
- int genderSort = 0;
- public int GenderSort { get => genderSort; set { genderSort = value; AllSort(); } }
- // Ñâîéñòâà äëÿ âûáîðêè ïî ïîëó
- int phoneNumSort = 0;
- public int PhoneNumSort { get => phoneNumSort; set { phoneNumSort = value; } }
- // Ñâîéñòâà äëÿ âûáîðêè ïî ïîëó
- int generalSort = 0;
- public int GeneralSort { get => generalSort; set { generalSort = value; } }
- void AllSort()
- {
- teachersList = MainWindowViewModel.connection.Teachers.Include(x => x.GenderNavigation).
- Include(x => x.TeachersAndCourses).ThenInclude(x => x.Course).
- Include(x => x.TeachersAndSubjects).ThenInclude(x => x.Subject).ToList();
- //ïîèñêîâàÿ ñòðîêà
- if (!string.IsNullOrWhiteSpace(searchLine))
- {
- TeachersList = TeachersList.Where(x => x.Lastname.ToLower().Contains(searchLine.ToLower()) || x.Firstname.ToLower().Contains(searchLine.ToLower()) || x.Patronymic.ToLower().Contains(searchLine.ToLower())).ToList();
- }
- // âûáîðêà ïî ïîëó
- if (genderSort==1)
- {
- TeachersList = TeachersList.Where(x=>x.Gender==1).ToList();
- }
- else if(genderSort == 2)
- {
- TeachersList = TeachersList.Where(x => x.Gender == 2).ToList();
- }
- // âûáîðêà ïî íàëè÷èþ íîìåðà òåëåôîíà
- if (phoneNumSort == 1)
- {
- TeachersList = TeachersList.Where(x => x.PhoneNumber!=null).ToList();
- }
- else if (phoneNumSort == 2)
- {
- TeachersList = TeachersList.Where(x => x.PhoneNumber == null).ToList();
- }
- }
- public async void DeleteTeacher(int teacherId)
- {
- ButtonResult checking = await MessageBoxManager.GetMessageBoxStandard("Ïðîâåðêà", "Âû õîòèòå óäàëèòü ïîëüçîâàòåëÿ?", ButtonEnum.YesNo).ShowAsync();
- switch (checking)
- {
- case ButtonResult.Yes:
- {
- Teacher deleteTeacher = MainWindowViewModel.connection.Teachers.First(x => x.Teacherid == teacherId);
- MainWindowViewModel.connection.Teachers.Remove(deleteTeacher);
- MainWindowViewModel.connection.SaveChanges();
- MainWindowViewModel.Instance.Uc = new TeachersPage();
- break;
- }
- case ButtonResult.No:
- {
- break;
- }
- }
- }
- public void EditTeacher(int teacherId)
- {
- MainWindowViewModel.Instance.Uc = new AddTeacher(teacherId);
- }
- }
- }
|