12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- 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<StudentsTemplate> all = new List<StudentsTemplate>();
- List<StudentsTemplate> staticAll = new List<StudentsTemplate>();
- 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<RunningProgram> programs = dataBase.RunningPrograms
- .Include(x=>x.IdProgramTemplateNavigation)
- .ToList();
- List<ProgramsWithStudent> 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<StudentsTemplate> All
- {
- get { return all; }
- set
- {
- if (all == value)
- return;
- all = value;
- OnPropertyChanged("All");
- }
- }
- }
- }
|