// test
        // сразу формировать DTO
        public async Task <OperationDetailDTO <List <SubjectDTO> > > GetMainDataAsync()
        {
            var detail            = new OperationDetailDTO <List <SubjectDTO> >();
            var resSubjectDTOList = new List <SubjectDTO>();

            try
            {
                var currentUserEntity = await GetUserFromClaimsAsync();

                var currentTeacher = await _context.Teachers
                                     .Include(t => t.User)
                                     .Include(t => t.Department)
                                     .ThenInclude(d => d.Faculty)
                                     .Where(t => t.UserId == currentUserEntity.Id)
                                     .FirstOrDefaultAsync();

                // все задачи текущего преподавателя
                IQueryable <TaskModel> teacherTaskQueryList = from t in _context.TaskModels
                                                              .Include(t => t.Teacher)
                                                              .Include(t => t.Group)
                                                              .ThenInclude(g => g.Tasks)
                                                              .Include(t => t.Group)
                                                              .ThenInclude(g => g.Students)
                                                              .Include(t => t.Subject)
                                                              .Include(t => t.Type)
                                                              .Include(t => t.Solutions)
                                                              .Include(t => t.TaskStudentItems)
                                                              .Where(t => t.TeacherId == currentTeacher.Id)
                                                              select t;

                // все предметы, по которым есть задачи
                IQueryable <Subject> subjectQueryList_ = from s in _context.Subjects
                                                         .Include(s => s.Tasks)
                                                         .Where(s => s.Tasks.Count > 0)
                                                         select s;


                // формируем список сущностей предметов
                var resSubjectEntityList = new List <Subject>();

                var resGroupEntityList = new List <Group>();

                // из всех задач препода получить список предметов по которым у препода есть задачи
                foreach (var task in teacherTaskQueryList)
                {
                    SubjectDTO currentSubjectDTO;
                    GroupDTO   currentGroupDTO;
                    var        newStudentDTO = new StudentDTO();

                    if ((currentSubjectDTO = resSubjectDTOList.FirstOrDefault(s => s.Id == task.SubjectId)) != null)
                    {
                        if ((currentGroupDTO = currentSubjectDTO.Groups.FirstOrDefault(g => g.Id == task.GroupId)) != null)
                        {
                            if (currentGroupDTO.Students != null)
                            {
                                foreach (var student in currentGroupDTO.Students)
                                {
                                    // get every student solution for current task
                                    var ts       = new TaskStudentItem();
                                    var solution = new Solution();
                                    if ((ts = task.TaskStudentItems.FirstOrDefault(ts => (ts.StudentId == student.Id) && (ts.TaskId == task.Id))) != null)
                                    {
                                        var taskDTO = TaskDTO.Map(task);

                                        var solEnt = task.Solutions.Where(s => s.StudentId == student.Id).FirstOrDefault();
                                        if (solEnt != null)
                                        {
                                            taskDTO.Solution = SolutionDTO.Map(solEnt);
                                        }

                                        student.Tasks.Add(taskDTO);
                                    }
                                }
                            }
                        }
                        else
                        {
                            currentGroupDTO = GroupDTO.Map(task.Group); //
                            currentSubjectDTO.Groups.Add(currentGroupDTO);
                            if (currentGroupDTO.Students != null)
                            {
                                foreach (var student in currentGroupDTO.Students)
                                {
                                    var ts       = new TaskStudentItem();
                                    var solution = new Solution();
                                    if ((ts = task.TaskStudentItems.FirstOrDefault(ts => (ts.StudentId == student.Id) && (ts.TaskId == task.Id))) != null)
                                    {
                                        var taskDTO = TaskDTO.Map(task);

                                        var solEnt = task.Solutions.Where(s => s.StudentId == student.Id).FirstOrDefault();
                                        if (solEnt != null)
                                        {
                                            taskDTO.Solution = SolutionDTO.Map(solEnt);
                                        }

                                        student.Tasks.Add(taskDTO);
                                    }
                                }
                            }
                        }
                    }

                    else
                    {
                        currentGroupDTO   = GroupDTO.Map(task.Group);
                        currentSubjectDTO = SubjectDTO.Map(task.Subject);
                        // наполняем студентов группы заданиями и решениями
                        foreach (var student in currentGroupDTO.Students)
                        {
                            var ts = new TaskStudentItem();
                            if ((ts = task.TaskStudentItems.FirstOrDefault(ts => (ts.StudentId == student.Id) && (ts.TaskId == task.Id))) != null)
                            {
                                var taskDTO = TaskDTO.Map(task);
                                var solEnt  = task.Solutions.Where(s => s.StudentId == student.Id).FirstOrDefault();
                                if (solEnt != null)
                                {
                                    taskDTO.Solution = SolutionDTO.Map(solEnt);
                                }
                                student.Tasks.Add(taskDTO);
                            }
                        }
                        currentSubjectDTO.Groups.Add(currentGroupDTO);
                        resSubjectDTOList.Add(currentSubjectDTO);
                    }
                }

                detail.Succeeded = true;
                detail.Data      = resSubjectDTOList;

                return(new OperationDetailDTO <List <SubjectDTO> > {
                    Data = resSubjectDTOList, Succeeded = true
                });
            }
            catch (Exception e)
            {
                detail.Succeeded = false;
                detail.ErrorMessages.Add(_serverErrorMessage + e.Message);
                return(detail);
            }
        }
        // done
        // получение дерева объектов для фильтрации заданий
        public async Task <OperationDetailDTO <TaskFiltersModelDTO> > GetTaskFiltersAsync()
        {
            var detail = new OperationDetailDTO <TaskFiltersModelDTO>();

            try
            {
                var resSubjectDTOList = new List <SubjectDTO>();
                var resTypeDTOList    = new List <TypeOfTaskDTO>();

                var currentUserEntity = await GetUserFromClaimsAsync();

                var teacherUser = await _context.Users
                                  .Where(u => u.Id == currentUserEntity.Id)
                                  .FirstOrDefaultAsync();

                var teacherEntity = await _context.Teachers
                                    .Include(t => t.User)
                                    .Include(t => t.Department)
                                    .ThenInclude(d => d.Faculty)
                                    .Where(t => t.UserId == currentUserEntity.Id)
                                    .FirstOrDefaultAsync();

                IQueryable <Subject> subjects = from s in _context.Subjects select s;

                // error
                IQueryable <TaskModel> teacherTaskQueryList = from t in _context.TaskModels
                                                              .Include(t => t.Teacher)
                                                              .Include(t => t.Group)
                                                              .Include(t => t.Subject)
                                                              .Include(t => t.Type)
                                                              .Where(t => t.TeacherId == teacherEntity.Id)
                                                              select t;

                foreach (var task in teacherTaskQueryList)
                {
                    var groupDTO   = GroupDTO.Map(task.Group);
                    var subjectDTO = new SubjectDTO();
                    var typeDTO    = new TypeOfTaskDTO();

                    if ((subjectDTO = resSubjectDTOList.FirstOrDefault(s => s.Id == task.SubjectId)) != null)
                    {
                        // куда добавляется группа
                        if (subjectDTO.Groups.FirstOrDefault(g => g.Id == groupDTO.Id) != null) // добавить проверку по id
                        {
                        }
                        else
                        {
                            subjectDTO.Groups.Add(groupDTO);
                        }
                    }
                    else
                    {
                        subjectDTO = SubjectDTO.Map(task.Subject);
                        subjectDTO.Groups.Add(groupDTO);
                        resSubjectDTOList.Add(subjectDTO);
                    }

                    if ((typeDTO = resTypeDTOList.FirstOrDefault(t => t.Id == task.TypeId)) != null)
                    {
                    }
                    else
                    {
                        typeDTO = TypeOfTaskDTO.Map(task.Type);
                        resTypeDTOList.Add(typeDTO);
                    }
                }

                detail.Data = new TaskFiltersModelDTO
                {
                    Subjects = resSubjectDTOList,
                    Types    = resTypeDTOList
                };

                detail.Succeeded = true;
                return(detail);
            }
            catch (Exception e)
            {
                detail.ErrorMessages.Add(_serverErrorMessage + e.Message);
                return(detail);
            }
        }
        // - только тот факультет, на котором препод
        // получение списков-фильтров для создания задачи
        // форируются списки существующих предметов, типов, групп для отправки на клиент
        public async Task <OperationDetailDTO <TaskFiltersModelDTO> > GetAddingTaskFiltersAsync()
        {
            var detail = new OperationDetailDTO <TaskFiltersModelDTO>();

            try
            {
                var currentUserEntity = await GetUserFromClaimsAsync();

                //var teacherUser = await _context.Users
                //    .Where(u => u.Id == currentUserEntity.Id)
                //    .FirstOrDefaultAsync();

                var teacherEntity = await _context.Teachers
                                    .Include(t => t.User)
                                    .Include(t => t.Department)
                                    .ThenInclude(d => d.Faculty)
                                    .Where(t => t.UserId == currentUserEntity.Id)
                                    .FirstOrDefaultAsync();

                var types = await _context.TaskTypes.AsNoTracking().ToListAsync();

                var subjects = await _context.Subjects.AsNoTracking().ToListAsync();

                var groups = await _context.Groups
                             .Include(g => g.Students)
                             .Where(g => g.Faculty.Id == teacherEntity.Department.FacultyId)
                             .AsNoTracking()
                             .ToListAsync();

                var typeList    = new List <TypeOfTaskDTO>();
                var subjectList = new List <SubjectDTO>();
                var groupList   = new List <GroupDTO>();

                foreach (var t in types)
                {
                    typeList.Add(TypeOfTaskDTO.Map(t));
                }
                foreach (var s in subjects)
                {
                    subjectList.Add(SubjectDTO.Map(s));
                }
                foreach (var g in groups)
                {
                    groupList.Add(GroupDTO.Map(g));
                }
                detail.Data = new TaskFiltersModelDTO
                {
                    Subjects = subjectList,
                    Groups   = groupList,
                    Types    = typeList
                };
                detail.Succeeded = true;
                return(detail);
            }

            catch (Exception e)
            {
                detail.ErrorMessages.Add(_serverErrorMessage + e.Message);
                return(detail);
            }
        }