示例#1
0
        // получение дерева-объекта для выбора фильтров при регистрации
        public async Task <OperationDetailDTO <List <FacultyDTO> > > GetAllStudiesAsync()
        {
            var resFacultyDTOList = new List <FacultyDTO>();

            try
            {
                var entityList = await _context.Faculties
                                 .Include(f => f.Groups)
                                 .Include(f => f.Departments)
                                 .AsNoTracking()
                                 .ToListAsync();

                foreach (var entity in entityList)
                {
                    resFacultyDTOList.Add(FacultyDTO.Map(entity));
                }
                return(new OperationDetailDTO <List <FacultyDTO> > {
                    Succeeded = true, Data = resFacultyDTOList, ErrorMessages = null
                });
            }
            catch (Exception e)
            {
                return(new OperationDetailDTO <List <FacultyDTO> > {
                    Succeeded = false, ErrorMessages = { _serverErrorMessage + e.Message }
                });
            }
        }
        // списки-фильтры по типу сущностей
        // для заявок только те подразделения факультета, где есть заявки
        // для существующих факультеты со всех их подразделениями показываются только если в факультете есть подраздения, количество людей не учитывается
        public async Task <OperationDetailDTO <List <FacultyDTO> > > GetAllStudyFiltersAsync(string userType)
        {
            var resFacultyDTOList = new List <FacultyDTO>();
            var resFacEntityList  = new List <Faculty>();

            try
            {
                IQueryable <Faculty> faculties = from f in _context.Faculties select f;

                faculties = faculties.OrderBy(f => f.Name);

                switch (userType)
                {
                case "reg_students":
                {
                    IQueryable <Group> groups;
                    foreach (var fac in faculties)
                    {
                        groups = from g in _context.Groups
                                 .Include(g => g.StudentRegisterRequests)
                                 .Where(g => g.StudentRegisterRequests.Count > 0)
                                 .Where(g => g.FacultyId == fac.Id)
                                 select g;

                        var testGroupList = groups.ToList();

                        foreach (var group in groups)
                        {
                        }
                        if (fac.Groups.Count > 0)
                        {
                            resFacEntityList.Add(fac);
                        }
                    }
                    break;
                }

                case "reg_teachers":
                {
                    IQueryable <Department> departments;
                    foreach (var fac in faculties)
                    {
                        departments = from d in _context.Departments
                                      .Include(d => d.TeacherRegisterRequests)
                                      .Where(d => d.TeacherRegisterRequests.Count > 0)
                                      .Where(d => d.FacultyId == fac.Id)
                                      select d;

                        var testDepList = departments.ToList();

                        foreach (var department in departments)
                        {
                        }
                        if (fac.Departments.Count > 0)
                        {
                            resFacEntityList.Add(fac);
                        }
                    }
                    break;
                }

                case "exist_students":
                {
                    // возвращается список всех групп факультета
                    faculties = faculties.Include(f => f.Groups);
                    foreach (var fac in faculties)
                    {
                        if (fac.Groups.Count > 0)
                        {
                            resFacEntityList.Add(fac);
                        }
                    }
                    break;
                }

                case "exist_teachers":
                {
                    // возвращается список всех кафедр факультета
                    faculties = faculties.Include(f => f.Departments);
                    foreach (var fac in faculties)
                    {
                        if (fac.Departments.Count > 0)
                        {
                            resFacEntityList.Add(fac);
                        }
                    }
                    break;
                }
                }

                foreach (var entity in resFacEntityList)
                {
                    resFacultyDTOList.Add(FacultyDTO.Map(entity));
                }
                return(new OperationDetailDTO <List <FacultyDTO> > {
                    Succeeded = true, Data = resFacultyDTOList, ErrorMessages = null
                });
            }
            catch (Exception e)
            {
                return(new OperationDetailDTO <List <FacultyDTO> > {
                    Succeeded = false, ErrorMessages = { _filtersErrorHeader + _serverErrorMessage + e.Message }
                });
            }
        }