123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167 |
- 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;
- AllSort();
- }
- }
- // Ñâîéñòâà äëÿ âûáîðêè ïî ïîëó
- int genderSort = 0;
- public int GenderSort { get => genderSort; set { genderSort = value; AllSort(); } }
- // Ñâîéñòâà äëÿ âûáîðêè ïî òåëåôîíó
- bool phoneNumSort = false;
- public bool PhoneNumSort { get => phoneNumSort; set { phoneNumSort = value; AllSort(); } }
- // Ñâîéñòâà äëÿ ñîðòèðîâêè
- int generalSort = 0;
- public int GeneralSort { get => generalSort; set { generalSort = value; AllSort(); } }
- bool up = true;
- public bool Up { get => up; set { this.RaiseAndSetIfChanged(ref up, value); AllSort(); } }
- bool down = false;
- public bool Down { get => down; set { this.RaiseAndSetIfChanged(ref down, value); AllSort(); } }
- 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();
- }
- else
- {
- TeachersList = TeachersList.ToList();
- }
- //âûáîðêà ïî ïðåäìåòó
- if (selectedSubject!=null && selectedSubject.Subjectid != 0)
- {
- TeachersList = TeachersList.Where(x => x.TeachersAndSubjects.Any(y => y.Subjectid == selectedSubject.Subjectid)).ToList();
- }
- //âûáîðêà ïî íàëè÷èþ íîìåðà òåëåôîíà
- if (phoneNumSort==true)
- {
- TeachersList = TeachersList.Where(x => x.PhoneNumber != String.Empty).ToList();
- }
- else
- {
- TeachersList = TeachersList.ToList();
- }
- //ñîðòèðîâêà
- switch (generalSort)
- {
- case 0:
- break;
- case 1:
- if (Down)
- {
- TeachersList = TeachersList.OrderByDescending(x=>x.ExperienceInMonth).ToList();
- }
- else
- {
- TeachersList = TeachersList.OrderBy(x => x.ExperienceInMonth).ToList();
- }
- break;
- case 2:
- if (Down)
- {
- TeachersList = TeachersList.OrderByDescending(x => x.Lastname).ToList();
- }
- else
- {
- TeachersList = TeachersList.OrderBy(x => x.Lastname).ToList();
- }
- break;
- }
- }
- 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);
- }
- }
- }
|