Пример #1
0
        public async Task <IEnumerable <QuestionDto> > GetQuestions(string examId)
        {
            var result = new List <QuestionDto>();
            var query  = new LoadMoreQuery
            {
                Limit = 100
            };
            var response = await _service.GetQuestions(examId, query);

            while (response.HasMoreData)
            {
                result.AddRange(response.Items);
                query.Offset = response.NextOffset;
                response     = await _service.GetQuestions(examId, query);
            }
            result.AddRange(response.Items);
            return(result);
        }
Пример #2
0
        private async Task LoadMoreExecute(LoadMoreQuery loadMoreQuery)
        {
            IsLoading = true;

            //Simulate Server Call
            await Task.Delay(TimeSpan.FromSeconds(2));

            Debug.WriteLine("Page Number {0}, Page Size {1}", loadMoreQuery.PageNumber, loadMoreQuery.PageSize);

            for (var i = 1; i <= loadMoreQuery.PageSize; i++, _y++)
            {
                People.Add(new Person
                {
                    FirstName   = "John " + _y,
                    LastName    = "Doe",
                    PhoneNumber = string.Format("(262)564-123{0}", _y),
                    Address     = string.Format("12{0} Lake ave", _y)
                });
            }

            IsLoading = false;
        }
Пример #3
0
        public async Task <LoadMoreResult <QuestionDto> > GetQuestions(string examId, LoadMoreQuery query)
        {
            var examDocRef   = db.Collection(_examCollectionName).Document(examId);
            var examSnapshot = await examDocRef.GetSnapshotAsync();

            ParameterChecker.Against <FileNotFoundException>(examSnapshot.Exists == false, $"Exam {examSnapshot.Id} does not exist!");

            var exam = examSnapshot.ConvertTo <Exam>();

            var           sections               = new List <Section>();
            Query         allSectionsQuery       = db.Collection(_examCollectionName).Document(examId).Collection(_sectionCollectionName);
            QuerySnapshot allCitiesQuerySnapshot = await allSectionsQuery.GetSnapshotAsync();

            foreach (DocumentSnapshot documentSnapshot in allCitiesQuerySnapshot.Documents)
            {
                var section = documentSnapshot.ConvertTo <Section>();
                sections.Add(section);
            }

            var remain       = query.Limit;
            var dtos         = new List <QuestionDto>();
            var currentIndex = 0;
            var offsetInExam = query.Offset;

            for (int i = 0; i < sections.Count; i++)
            {
                var section = sections[i];
                if (currentIndex < query.Offset)
                {
                    if (currentIndex + section.NumberOfQuestions < query.Offset)
                    {
                        currentIndex += section.NumberOfQuestions;
                        offsetInExam += query.Offset;
                        continue;
                    }
                    else
                    {
                        var offsetInSection = query.Offset - currentIndex;
                        var sectionQuery    = new SectionQuery
                        {
                            ExamId     = exam.Reference.Id,
                            Section    = section,
                            Offset     = offsetInSection,
                            Limit      = remain,
                            SearchText = query.SearchText
                        };

                        var queryResult = await QuerySection(sectionQuery, offsetInExam);

                        offsetInExam = queryResult.OffsetInExam;
                        if (queryResult.Items.Any())
                        {
                            dtos.AddRange(queryResult.Items);
                            remain -= queryResult.Items.Count;
                        }
                    }
                }
                else
                {
                    var sectionQuery = new SectionQuery
                    {
                        ExamId     = exam.Reference.Id,
                        Section    = section,
                        Offset     = 0,
                        Limit      = remain,
                        SearchText = query.SearchText
                    };
                    var queryResult = await QuerySection(sectionQuery, offsetInExam);

                    offsetInExam = queryResult.OffsetInExam;
                    if (queryResult.Items.Any())
                    {
                        dtos.AddRange(queryResult.Items);
                        remain -= queryResult.Items.Count;
                    }
                }
                if (remain == 0)
                {
                    break;
                }
            }

            return(new LoadMoreResult <QuestionDto>(offsetInExam < exam.NumberOfQuestions, offsetInExam, dtos));
        }
Пример #4
0
 public async Task <LoadMoreResult <QuestionDto> > GetQuestions(string examId, LoadMoreQuery query)
 {
     return(await _service.GetQuestions(examId, query));
 }
Пример #5
0
 public Task <LoadMoreResult <QuestionDto> > GetQuestions(string examId, LoadMoreQuery query)
 {
     throw new NotImplementedException();
 }
Пример #6
0
 private bool CanExecuteLoadMore(LoadMoreQuery loadMoreQuery)
 {
     return(!IsLoading);
 }