MyProgramsViewModel.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. using System;
  2. using System.Collections.Generic;
  3. using AvaloniaApplication4.Models;
  4. using Microsoft.EntityFrameworkCore;
  5. using System.Linq;
  6. using ReactiveUI;
  7. using AvaloniaApplication4.AdditionalModels;
  8. using Tmds.DBus.Protocol;
  9. using AvaloniaApplication4.Views.StudyLists;
  10. namespace AvaloniaApplication4.ViewModels
  11. {
  12. public class MyProgramsViewModel : ViewModelBase
  13. {
  14. User? user;
  15. GlobalsData globalsData;
  16. List<RunningProgram> programs = new List<RunningProgram>();
  17. List<MyProgramsTemplate> programsWithSubject = new List<MyProgramsTemplate>();
  18. List<MyProgramsTemplate> staticProgramsWithSubject = new List<MyProgramsTemplate>();
  19. public MyProgramsViewModel(User? user, GlobalsData globalsData, int idAction)
  20. {
  21. this.user = user;
  22. this.globalsData = globalsData;
  23. List<UsersWithRole> roles = dataBase.UsersWithRoles.Include(x=>x.IdRoleNavigation).Include(x=>x.IdUserNavigation).Where(x=>x.IdUser == user.IdUser).ToList();
  24. bool isAllTutor = false;
  25. foreach(UsersWithRole role in roles)
  26. {
  27. if (role.IdRoleNavigation.RoleName == "Êóðàòîð âñåõ ïðîãðàìì") isAllTutor = true;
  28. if (role.IdRoleNavigation.RoleName == "Àäìèíèñòðàòîð") isAllTutor = true;
  29. }
  30. if (isAllTutor)
  31. {
  32. Programs = dataBase.RunningPrograms
  33. .Include(x => x.IdTutorNavigation)
  34. .Include(x => x.IdStatusNavigation)
  35. .Include(x => x.IdSecretaryNavigation)
  36. .Include(x => x.IdProgramTemplateNavigation)
  37. .ToList();
  38. }
  39. else
  40. {
  41. Programs = dataBase.RunningPrograms
  42. .Include(x => x.IdTutorNavigation)
  43. .Include(x => x.IdStatusNavigation)
  44. .Include(x => x.IdSecretaryNavigation)
  45. .Include(x => x.IdProgramTemplateNavigation)
  46. .Where(x => x.IdTutor == user.IdUser || x.IdSecretary == user.IdUser)
  47. .ToList();
  48. }
  49. List<ProgramsWithSubject> all = dataBase.ProgramsWithSubjects
  50. .Include(x => x.IdRunningProgramNavigation)
  51. .Include(x => x.IdSubjectNavigation)
  52. .Include(x => x.IdTeacherNavigation)
  53. .ToList();
  54. foreach (var program in Programs)
  55. {
  56. if (program.IdStatusNavigation.NameStatus == "Â ïðîöåññå")
  57. {
  58. ProgramsWithSubject.Add
  59. (
  60. new MyProgramsTemplate(program.IdProgramTemplateNavigation.NameProgram,program.IdProgramTemplateNavigation.CodeProgram,
  61. all.Where(x=>x.IdRunningProgram == program.IdRunningPrograms).ToList())
  62. );
  63. }
  64. }
  65. staticProgramsWithSubject = ProgramsWithSubject;
  66. }
  67. public void GetCredit(int idSubject)
  68. {
  69. var currentProgramAndSubject = dataBase.ProgramsWithSubjects
  70. .Include(x => x.IdWayNavigation).FirstOrDefault(x => x.Id == idSubject);
  71. if (currentProgramAndSubject != null)
  72. {
  73. if (currentProgramAndSubject.IdWayNavigation.Name == "Çà÷åò")
  74. {
  75. globalsData.GlobalUserControl = new DiffCredit(user, ref globalsData, currentProgramAndSubject, 1);
  76. }
  77. else if (currentProgramAndSubject.IdWayNavigation.Name == "Ýêçàìåí")
  78. {
  79. }
  80. }
  81. }
  82. public List<RunningProgram> Programs
  83. {
  84. get { return programs; }
  85. set
  86. {
  87. if (programs == value)
  88. return;
  89. programs = value;
  90. OnPropertyChanged("Programs");
  91. }
  92. }
  93. public List<MyProgramsTemplate> ProgramsWithSubject
  94. {
  95. get { return programsWithSubject; }
  96. set
  97. {
  98. if (programsWithSubject == value)
  99. return;
  100. programsWithSubject = value;
  101. OnPropertyChanged("ProgramsWithSubject");
  102. }
  103. }
  104. }
  105. }