示例#1
0
        public async Task <PagedResultDto <SubscriptionShortDto> > GetAllSubscriptionsAsync(int page)
        {
            IQueryable <NotificationSubscription> query  = _dbContext.Notifications.Where(x => x.Active);
            PagedResultDto <SubscriptionShortDto> result = await PagedResultUtil.ToPagedResult(query, page, MaterializeSubscriptionList);

            return(result);
        }
示例#2
0
        public async Task <PagedResultDto <CourseDto> > GetCoursesAsync(int page)
        {
            IQueryable <Course> query = this._dbContext.Courses
                                        .OrderBy(x => x.Title)
                                        .ThenBy(x => x.Id);

            return(await PagedResultUtil.ToPagedResult(query, page, ToDto));
        }
示例#3
0
        public async Task <PagedResultDto <VersionInfoDto> > GetVersionsAsync(VersionInfoParametersDto versionInfoParameters)
        {
            Question questionEntity = await _dbContext.FindAsync <Question>(versionInfoParameters.IdQuestion);

            IQueryable <Question> query = _dbContext.Questions.Where(x => x.Container.Id == questionEntity.IdContainer)
                                          .OrderByDescending(x => x.Id);

            return(await PagedResultUtil.ToPagedResult(query, versionInfoParameters.Page, MaterializeQuestionList));
        }
示例#4
0
        public async Task <PagedResultDto <TextDto> > GetTextsAsync(SearchTextDto parameters)
        {
            IQueryable <Text> query = _dbContext.Texts
                                      .OrderBy(x => x.Key)
                                      .ThenBy(x => x.Id);

            PagedResultDto <TextDto> result = await PagedResultUtil.ToPagedResult(query, parameters.Page, ToDto);

            return(result);
        }
示例#5
0
        public async Task <PagedResultDto <CourseInstanceListEntryDto> > GetMyCourseInstancesAsync(int page)
        {
            string userid = _securityService.GetUserId();
            IQueryable <CourseInstance> query = _dbContext.CourseInstances
                                                .Where(x => x.User.UserId == userid)
                                                .OrderByDescending(x => x.InsertDate)
                                                .ThenBy(x => x.Id);

            PagedResultDto <CourseInstanceListEntryDto> resultDto = await PagedResultUtil.ToPagedResult(query, page, ToDto);

            return(resultDto);
        }
示例#6
0
        public async Task <PagedResultDto <QuestionListEntryDto> > GetMyQuestionsAsync(int page)
        {
            string userId = _securityService.GetUserId();

            IQueryable <Question> query = _dbContext.Questions.Where(q => q.User.UserId == userId)
                                          .OrderBy(x => x.Title)
                                          .ThenBy(x => x.Id);
            PagedResultDto <QuestionListEntryDto> result = await PagedResultUtil.ToPagedResult(query, page, MaterializeQuestionList);


            return(result);
        }
示例#7
0
        public async Task <PagedResultDto <QuestionListEntryDto> > SearchForQuestionsAsync(SearchQParametersDto parameters)
        {
            IQueryable <Question> queryBeforeSkipAndTake = _dbContext.Questions
                                                           .OrderBy(x => x.Title)
                                                           .ThenBy(x => x.Id);

            if (!string.IsNullOrWhiteSpace(parameters.Title))
            {
                queryBeforeSkipAndTake = queryBeforeSkipAndTake.Where(x => x.Title.Contains(parameters.Title));
            }

            if (parameters.AndTags.Any())
            {
                IList <int> tagids = parameters.AndTags.Select(x => x.Id).ToList();
                foreach (int tagId in tagids)
                {
                    queryBeforeSkipAndTake = queryBeforeSkipAndTake.Where(x => x.RelTags.Any(rel => rel.Tag.Id == tagId));
                }
            }

            if (parameters.OrTags.Any())
            {
                IList <int> tagids = parameters.OrTags.Select(x => x.Id).ToList();
                queryBeforeSkipAndTake = queryBeforeSkipAndTake.Where(x => x.RelTags.Any(rel => tagids.Contains(rel.Tag.Id)));
            }

            if (!string.IsNullOrWhiteSpace(parameters.Language))
            {
                if (Enum.TryParse(parameters.Language, out Language lang))
                {
                    queryBeforeSkipAndTake = queryBeforeSkipAndTake.Where(x => x.Language == lang);
                }
            }

            if (parameters.StatusCreated || parameters.StatusReleased || parameters.StatusObsolete)
            {
                queryBeforeSkipAndTake = queryBeforeSkipAndTake.Where(x =>
                                                                      x.Status == QuestionStatus.Created && parameters.StatusCreated ||
                                                                      x.Status == QuestionStatus.Released && parameters.StatusReleased ||
                                                                      x.Status == QuestionStatus.Obsolete && parameters.StatusObsolete);
            }
            else
            {
                queryBeforeSkipAndTake = queryBeforeSkipAndTake.Where(x =>
                                                                      x.Status == QuestionStatus.Created ||
                                                                      x.Status == QuestionStatus.Released);
            }

            PagedResultDto <QuestionListEntryDto> result = await PagedResultUtil.ToPagedResult(queryBeforeSkipAndTake, parameters.Page, MaterializeQuestionList);

            return(result);
        }
示例#8
0
        public async Task <PagedResultDto <CourseDto> > GetFavoriteCourseAsync(int page)
        {
            string userId             = this._securityService.GetUserId();
            IQueryable <Course> query = from x in _dbContext.Courses
                                        join relUser in _dbContext.RelUserCourseFavorites on x.Id equals relUser.Course.Id
                                        where
                                        relUser.User.UserId == userId
                                        select x;


            query = query.OrderBy(x => x.Title).ThenBy(x => x.Id);
            return(await PagedResultUtil.ToPagedResult(query, page, ToDto));
        }
示例#9
0
        public async Task <PagedResultDto <TagDto> > SearchForTagsAsync(SearchTags parameters)
        {
            IQueryable <Tag> query = _dbContext.Tags
                                     .OrderBy(x => x.Name)
                                     .ThenBy(x => x.Id);

            if (!string.IsNullOrWhiteSpace(parameters.Name))
            {
                query = query.Where(x => x.Name.Contains(parameters.Name));
            }

            PagedResultDto <TagDto> result = await PagedResultUtil.ToPagedResult(query, parameters.Page, ToDto);

            return(result);
        }