123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using System;
- using System.Collections.Generic;
- using AvaloniaApplication4.Models;
- using Microsoft.EntityFrameworkCore;
- using System.Linq;
- using ReactiveUI;
- using AvaloniaApplication4.AdditionalModels;
- using Tmds.DBus.Protocol;
- using AvaloniaApplication4.Views.StudyLists;
- namespace AvaloniaApplication4.ViewModels
- {
- public class MyProgramsViewModel : ViewModelBase
- {
- User? user;
- GlobalsData globalsData;
- List<RunningProgram> programs = new List<RunningProgram>();
- List<MyProgramsTemplate> programsWithSubject = new List<MyProgramsTemplate>();
- List<MyProgramsTemplate> staticProgramsWithSubject = new List<MyProgramsTemplate>();
-
- public MyProgramsViewModel(User? user, GlobalsData globalsData, int idAction)
- {
- this.user = user;
- this.globalsData = globalsData;
- List<UsersWithRole> roles = dataBase.UsersWithRoles.Include(x=>x.IdRoleNavigation).Include(x=>x.IdUserNavigation).Where(x=>x.IdUser == user.IdUser).ToList();
- bool isAllTutor = false;
- foreach(UsersWithRole role in roles)
- {
- if (role.IdRoleNavigation.RoleName == "Êóðàòîð âñåõ ïðîãðàìì") isAllTutor = true;
- if (role.IdRoleNavigation.RoleName == "Àäìèíèñòðàòîð") isAllTutor = true;
- }
- if (isAllTutor)
- {
- Programs = dataBase.RunningPrograms
- .Include(x => x.IdTutorNavigation)
- .Include(x => x.IdStatusNavigation)
- .Include(x => x.IdSecretaryNavigation)
- .Include(x => x.IdProgramTemplateNavigation)
- .ToList();
- }
- else
- {
- Programs = dataBase.RunningPrograms
- .Include(x => x.IdTutorNavigation)
- .Include(x => x.IdStatusNavigation)
- .Include(x => x.IdSecretaryNavigation)
- .Include(x => x.IdProgramTemplateNavigation)
- .Where(x => x.IdTutor == user.IdUser || x.IdSecretary == user.IdUser)
- .ToList();
- }
- List<ProgramsWithSubject> all = dataBase.ProgramsWithSubjects
- .Include(x => x.IdRunningProgramNavigation)
- .Include(x => x.IdSubjectNavigation)
- .Include(x => x.IdTeacherNavigation)
- .ToList();
- foreach (var program in Programs)
- {
- if (program.IdStatusNavigation.NameStatus == "Â ïðîöåññå")
- {
- ProgramsWithSubject.Add
- (
- new MyProgramsTemplate(program.IdProgramTemplateNavigation.NameProgram,program.IdProgramTemplateNavigation.CodeProgram,
- all.Where(x=>x.IdRunningProgram == program.IdRunningPrograms).ToList())
- );
- }
- }
- staticProgramsWithSubject = ProgramsWithSubject;
- }
- public void GetCredit(int idSubject)
- {
- var currentProgramAndSubject = dataBase.ProgramsWithSubjects
- .Include(x => x.IdWayNavigation).FirstOrDefault(x => x.Id == idSubject);
- if (currentProgramAndSubject != null)
- {
- if (currentProgramAndSubject.IdWayNavigation.Name == "Çà÷åò")
- {
- globalsData.GlobalUserControl = new DiffCredit(user, ref globalsData, currentProgramAndSubject, 1);
- }
- else if (currentProgramAndSubject.IdWayNavigation.Name == "Ýêçàìåí")
- {
- }
- }
- }
- public List<RunningProgram> Programs
- {
- get { return programs; }
- set
- {
- if (programs == value)
- return;
- programs = value;
- OnPropertyChanged("Programs");
- }
- }
- public List<MyProgramsTemplate> ProgramsWithSubject
- {
- get { return programsWithSubject; }
- set
- {
- if (programsWithSubject == value)
- return;
- programsWithSubject = value;
- OnPropertyChanged("ProgramsWithSubject");
- }
- }
- }
- }
|