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 programs = new List(); List programsWithSubject = new List(); List staticProgramsWithSubject = new List(); public MyProgramsViewModel(User? user, GlobalsData globalsData, int idAction) { this.user = user; this.globalsData = globalsData; List 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 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 Programs { get { return programs; } set { if (programs == value) return; programs = value; OnPropertyChanged("Programs"); } } public List ProgramsWithSubject { get { return programsWithSubject; } set { if (programsWithSubject == value) return; programsWithSubject = value; OnPropertyChanged("ProgramsWithSubject"); } } } }