//
        // Summary:
        //     create range of answer
        //
        // Returns:
        //      list of created anwser model
        //
        // Params:
        //     answer param gatway
        //

        public async Task <IEnumerable <Answer> > BatchCreateAsync(AnswerParams param)
        {
            List <Answer> entities = new List <Answer>();

            //persist all of answer for earch subquestion
            foreach (var a in param.Answers)
            {
                //set some value
                a.Date          = DateTime.UtcNow;
                a.ParticipantId = param.ParticipantId;

                // a.By = param.ParticipantId;

                entities.Add(a);
            }

            var entity = await _answerRepository.CreateRangeAsync(entities);

            if (entity == null)
            {
                throw new AnswerNotCreatedException();
            }

            return(entities);
        }
        public async Task <IActionResult> GetAnswers(int id, [FromQuery] AnswerParams answerParams)
        {
            int pageSize  = answerParams.PageSize;
            int pageIndex = answerParams.PageIndex;

            var answersFromRepo = await _repo.GetAnswersAsync(id, answerParams);

            var answers = _mapper.Map <IEnumerable <Answer> >(answersFromRepo);

            return(Ok(new { answers, answerParams.Length }));
        }
Exemple #3
0
        public static IQueryable <Answer> QuestionQuery(AnswerParams questionParams, IQueryable <Answer> questions)
        {
            questionParams.Length = questions.Count();

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

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

            return(questions);
        }
        // Answer Repo
        public async Task <IEnumerable <Answer> > GetAnswersAsync(int id, AnswerParams questionParams)
        {
            // Gotta back for implementing orderby date after another migration
            var answers = _context.Answers
                          .Where(a => a.IsDeleted == false)
                          .Where(a => a.Question.Id == id)
                          .Include(a => a.AnsweredBy)
                          .AsQueryable();

            answers = TQuery.QuestionQuery(questionParams, answers);

            return(await answers.ToListAsync());
        }
        //
        // Summary:
        //     list answer and detailed question for csv
        //
        // Returns:
        //      list of anwser params
        //

        public async Task <IEnumerable <AnswerParams> > ListAnswerDetailAsync()
        {
            var answers = await _answerRepository.ListAsync();

            var questions = await _questionService.ListDetailAsync();

            var choises = await _choiseService.ListSubChoiseAsync();

            List <AnswerParams> entities = new List <AnswerParams>();

            //persist all of answer for earch subquestion
            foreach (var a in answers)
            {
                var p = new AnswerParams()
                {
                    //set some value
                    ParticipantId = a.ParticipantId,
                    AnswerDate    = a.Date,
                    AnswerId      = a.Id,

                    AnswerText  = a.Text,
                    AnswerValue = a.Value,
                };

                //set value of choise
                var ch = choises.Where(c => c.Id == a.Value).FirstOrDefault();
                if (ch != null)
                {
                    p.AnswerText = ch.Title;
                }

                //set question and subquestion
                var q = questions.Where(c => c.Id == a.SubQuestionId).FirstOrDefault();
                if (q != null)
                {
                    p.SubQuestionId = q.Id;
                    p.QuestionId    = q.QuestionId;

                    p.QuestionTitle    = q.QuestionTitle;
                    p.SubQuestionValue = q.Value;

                    p.SubQuestionType  = q.Type;
                    p.SubQuestionOrder = q.Order;
                }


                entities.Add(p);
            }

            return(entities);
        }
Exemple #6
0
    //POST /media/connections/{media_connection_id}/answer で渡すJSON Objectのパラメータ作成
    private AnswerParams _CreateAnswerParams()
    {
        var videoRedirect = new Redirect();

        videoRedirect.ip_v4 = "127.0.0.1";
        videoRedirect.port  = 7000;
        var redirectParams = new RedirectParams();

        redirectParams.video = videoRedirect;
        var constraints  = new Constraints();
        var answerParams = new AnswerParams();

        answerParams.constraints     = constraints;
        answerParams.redirect_params = redirectParams;
        return(answerParams);
    }
 public async Task<IActionResult> BatchCreateAsync(AnswerParams param)
 {
     var entities = await _answerService.BatchCreateAsync(param);
     return Ok(entities);
 }