using System; using System.Collections.Generic; using System.Linq; using System.Xml.Linq; using Avalonia.Controls; using AvaloniaApplication4.AdditionalModels; using AvaloniaApplication4.Models; using AvaloniaApplication4.Views.ActionPages; using Microsoft.EntityFrameworkCore; using ReactiveUI; namespace AvaloniaApplication4.ViewModels { public class StudentsViewModel : ViewModelBase { User? user; List all = new List(); List staticAll = new List(); string searchQueryPrograms = string.Empty; public string SearchQueryPrograms { get { return searchQueryPrograms; } set { searchQueryPrograms = value; if (searchQueryPrograms != null && searchQueryPrograms != string.Empty && searchQueryPrograms != "") { All = staticAll.Where(x=>x.Program.IdProgramTemplateNavigation.NameProgram.ToLower().StartsWith(searchQueryPrograms.ToLower())).ToList(); } else All = staticAll; } } GlobalsData globalsData; public StudentsViewModel(User? user, ref GlobalsData globalsData) { this.user = user; List programs = dataBase.RunningPrograms .Include(x=>x.IdProgramTemplateNavigation) .ToList(); List programsWithStudents = dataBase.ProgramsWithStudents .Include(x=>x.IdRunningProgramNavigation) .Include(x=>x.IdStudentNavigation) .ToList(); foreach (var program in programs) { All.Add ( new StudentsTemplate(program, programsWithStudents.Where(x=>x.IdRunningProgram == program.IdRunningPrograms).ToList()) ); } staticAll = All; this.globalsData = globalsData; } public void EditStudent(int id) { Student? student = dataBase.Students.Include(x=>x.IdEducationNavigation).FirstOrDefault(x=>x.IdStudent == id); if (student != null) { globalsData.GlobalUserControl = new EditAndAddStudent(user, student, ref globalsData); } } public void AddNewStudent() { globalsData.GlobalUserControl = new EditAndAddStudent(user, ref globalsData); } internal List All { get { return all; } set { if (all == value) return; all = value; OnPropertyChanged("All"); } } } }