// 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);
            }
        }
示例#2
0
        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 studentEntity = await _context.Students
                                    .Include(s => s.User)
                                    .Include(s => s.Group)
                                    .ThenInclude(g => g.Faculty)
                                    .Include(s => s.TaskStudentItems)
                                    .Where(s => s.UserId == currentUserEntity.Id)
                                    .FirstOrDefaultAsync();

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

                IQueryable <TypeOfTask> types = from t in _context.TaskTypes select t;

                // получить все задания студента
                IQueryable <TaskModel> tasks = from t in _context.TaskModels
                                               .Include(t => t.Teacher)
                                               .Include(t => t.Group)
                                               .Include(t => t.Subject)
                                               .Include(t => t.Type)
                                               .Where(t => (t.TaskStudentItems.FirstOrDefault(x => x.StudentId == studentEntity.Id) != null))
                                               select t;

                foreach (var task in tasks)
                {
                    var subjectDTO = new SubjectDTO();
                    var typeDTO    = new TypeOfTaskDTO();

                    if ((subjectDTO = resSubjectDTOList.FirstOrDefault(s => s.Id == task.SubjectId)) != null)
                    {
                    }
                    else
                    {
                        subjectDTO = SubjectDTO.Map(task.Subject);
                        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);
            }
        }