예제 #1
0
        public async Task <IActionResult> GetQuestions([FromQuery] QuestionParams questionParams)
        {
            int pageSize  = questionParams.PageSize;
            int pageIndex = questionParams.PageIndex;

            var questionsFromRepo = await _repo.GetQuestionsAsync(questionParams);

            var questions = _mapper.Map <IEnumerable <QuestionToReturnDto> >(questionsFromRepo);

            return(Ok(new { questions, questionParams.Length }));
        }
예제 #2
0
        // Question Repo
        public async Task <IEnumerable <Question> > GetQuestionsAsync(QuestionParams questionParams)
        {
            // Gotta back for implementing orderby date after another migration
            var questions = _context.Questions
                            .Where(a => a.IsDeleted == false)
                            .Include(a => a.Category)
                            .Include(q => q.QuestionBy)
                            .Include(q => q.Answers)
                            .AsQueryable();

            questions = TQuery.QuestionQuery(questionParams, questions);

            return(await questions.ToListAsync());
        }
예제 #3
0
        public static IQueryable <Question> QuestionQuery(QuestionParams questionParams, IQueryable <Question> questions)
        {
            if (!string.IsNullOrEmpty(questionParams.Filter))
            {
                questions = questions.Where(a => a.Title.Contains(questionParams.Filter));
            }

            if (!string.IsNullOrEmpty(questionParams.ByUserId))
            {
                questions = questions.Where(a => a.QuestionBy.Id.Equals(questionParams.ByUserId));
            }

            if (questionParams.CategoryBy != 0)
            {
                questions = questions.Where(a => a.Category.Id == questionParams.CategoryBy);
            }

            questionParams.Length = questions.Count();

            questions = questions.Skip(questionParams.PageIndex * questionParams.PageSize).Take(questionParams.PageSize).Select(a => a);

            return(questions);
        }
예제 #4
0
        //
        // Summary:
        //     get remain a question by session id for client
        //
        // Returns:
        //      question model
        //
        // Params:
        //      question model with list of mixed sub question and choise
        //

        public async Task <QuestionParams> GetRemainByParticipantAsync(Guid?participantid)
        {
            //get participant session
            var participant = await _participantService.GetAsync(participantid.GetValueOrDefault());

            if (participantid == null)
            {
                //no history answer for participant
                //throw new ParticipantNotFoundException();

                var pp = new Participant()
                {
                    Name  = "t5hany6adol",
                    Email = "*****@*****.**"
                };

                participant = await _participantService.CreateAsync(pp);
            }

            //prepaire data
            var questions = await _questionRepository.ListAsync();

            var subQuestions = await _subQuestionRepository.ListAsync();

            var choises = await _choiseService.ListChoiseAsync();

            //get list of answer to compare with remain
            var recentAnswers = await _answerService.ListByParticipantAsync(participant.Id);

            if (recentAnswers.Any())
            {
                var temp = subQuestions.Where(c => recentAnswers.Select(y => y.SubQuestionId).ToArray().Contains(c.Id));

                //get remain question by subquestionid
                questions = questions.Where(c => !temp.GroupBy(y => y.QuestionId).Select(x => x.Key).Contains(c.Id));
            }

            //complete session with choise and subquestion by order
            var pickedQuestion = questions.OrderBy(c => c.Order).FirstOrDefault();

            //get subquestion and assign full choise
            var selectSubQuestions = subQuestions.Where(c => c.QuestionId == pickedQuestion.Id)
                                     .Select(c => { c.Choises = choises.Where(w => w.Id == c.ChoiseId).ToList(); return(c); }).ToList();

            //assign choise
            var entity = new QuestionParams()
            {
                Id    = pickedQuestion.Id,
                Title = pickedQuestion.Title,

                ParticipantId = participant.Id,

                Order = pickedQuestion.Order,

                SubQuestions = selectSubQuestions,
                By           = pickedQuestion.By,

                Date = pickedQuestion.Date
            };


            return(entity);
        }