AllSubjectsModulesAndProgramTemplatesViewModel.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Reflection;
  5. using AvaloniaApplication4.AdditionalModels;
  6. using AvaloniaApplication4.Models;
  7. using AvaloniaApplication4.Views.ActionPages;
  8. using Microsoft.EntityFrameworkCore;
  9. using ReactiveUI;
  10. namespace AvaloniaApplication4.ViewModels
  11. {
  12. public class AllSubjectsModulesAndProgramTemplatesViewModel : ViewModelBase
  13. {
  14. GlobalsData globalsData;
  15. User? user;
  16. List<Subject> subjects;
  17. List<Models.Module> modules;
  18. List<ProgramTemplate> programTemplates;
  19. public AllSubjectsModulesAndProgramTemplatesViewModel(GlobalsData globalsData, User? user)
  20. {
  21. this.globalsData = globalsData;
  22. this.user = user;
  23. subjects = dataBase.Subjects.Include(x => x.IdCodeAcademicSubjectNavigation).Include(x => x.IdTrainingStandartsNavigation).ToList();
  24. modules = dataBase.Modules.ToList();
  25. programTemplates = dataBase.ProgramTemplates.ToList();
  26. }
  27. public List<Subject> Subjects { get => subjects; set => subjects = value; }
  28. public List<Models.Module> Modules { get => modules; set => modules = value; }
  29. public List<ProgramTemplate> ProgramTemplates { get => programTemplates; set => programTemplates = value; }
  30. public void AddNewSubject()
  31. {
  32. globalsData.GlobalUserControl = new EditAndAddSubject(user, ref globalsData);
  33. }
  34. public void AddNewModule()
  35. {
  36. globalsData.GlobalUserControl = new EditAndAddModule(user, ref globalsData);
  37. }
  38. public void AddNewProgramTemplate()
  39. {
  40. globalsData.GlobalUserControl = new EditAndAddProgramTemplate(user, ref globalsData);
  41. }
  42. public void EditSubject(int idSubject)
  43. {
  44. var subject = dataBase.Subjects.FirstOrDefault(x => x.IdSubject == idSubject);
  45. if (subject != null)
  46. {
  47. globalsData.GlobalUserControl = new EditAndAddSubject(user, ref globalsData, subject);
  48. }
  49. }
  50. public void EditModule(int idModule)
  51. {
  52. var module = dataBase.Modules.FirstOrDefault(x=>x.IdModule == idModule);
  53. if (module != null)
  54. {
  55. globalsData.GlobalUserControl = new EditAndAddModule(user, ref globalsData,module);
  56. }
  57. }
  58. public void EditProgramTemplate(int idProgramTemplate)
  59. {
  60. var programTemplate = dataBase.ProgramTemplates.FirstOrDefault(x => x.IdProgramTemplate == idProgramTemplate);
  61. if (programTemplate != null)
  62. {
  63. globalsData.GlobalUserControl = new EditAndAddProgramTemplate(user, ref globalsData, programTemplate);
  64. }
  65. }
  66. }
  67. }