using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using AvaloniaApplication4.AdditionalModels; using AvaloniaApplication4.Models; using AvaloniaApplication4.Views.ActionPages; using Microsoft.EntityFrameworkCore; using ReactiveUI; namespace AvaloniaApplication4.ViewModels { public class AllSubjectsModulesAndProgramTemplatesViewModel : ViewModelBase { GlobalsData globalsData; User? user; List subjects; List modules; List programTemplates; public AllSubjectsModulesAndProgramTemplatesViewModel(GlobalsData globalsData, User? user) { this.globalsData = globalsData; this.user = user; subjects = dataBase.Subjects.Include(x => x.IdCodeAcademicSubjectNavigation).Include(x => x.IdTrainingStandartsNavigation).ToList(); modules = dataBase.Modules.ToList(); programTemplates = dataBase.ProgramTemplates.ToList(); } public List Subjects { get => subjects; set => subjects = value; } public List Modules { get => modules; set => modules = value; } public List ProgramTemplates { get => programTemplates; set => programTemplates = value; } public void AddNewSubject() { globalsData.GlobalUserControl = new EditAndAddSubject(user, ref globalsData); } public void AddNewModule() { globalsData.GlobalUserControl = new EditAndAddModule(user, ref globalsData); } public void AddNewProgramTemplate() { globalsData.GlobalUserControl = new EditAndAddProgramTemplate(user, ref globalsData); } public void EditSubject(int idSubject) { var subject = dataBase.Subjects.FirstOrDefault(x => x.IdSubject == idSubject); if (subject != null) { globalsData.GlobalUserControl = new EditAndAddSubject(user, ref globalsData, subject); } } public void EditModule(int idModule) { var module = dataBase.Modules.FirstOrDefault(x=>x.IdModule == idModule); if (module != null) { globalsData.GlobalUserControl = new EditAndAddModule(user, ref globalsData,module); } } public void EditProgramTemplate(int idProgramTemplate) { var programTemplate = dataBase.ProgramTemplates.FirstOrDefault(x => x.IdProgramTemplate == idProgramTemplate); if (programTemplate != null) { globalsData.GlobalUserControl = new EditAndAddProgramTemplate(user, ref globalsData, programTemplate); } } } }