コード例 #1
0
ファイル: AnswersService.cs プロジェクト: starsaminf/jalasoft
        public EvaluationScore CreateAnswers(Guid idEvaluation, EvaluationAnswer answersList)
        {
            return(ServiceErrorHandler.Handle(() =>
            {
                Log.Info($"Checking if evaluation with id {idEvaluation} exists");
                var answersDao = this.answersDaoBuilder.Create();
                var evaluationsDao = this.evaluationsDaoBuilder.Create();
                var templatesDao = this.templatesDaoBuilder.Create();

                if (!evaluationsDao.EvaluationExists(idEvaluation))
                {
                    throw new ItemNotFoundServiceException($"Unable to find an evaluation with id {idEvaluation}");
                }

                var evaluation = evaluationsDao.GetEvaluation(idEvaluation);
                var template = templatesDao.GetTemplate(evaluation.IdTemplate);
                var evaluationTemplate = EvaluationScoreHelpers.GenerateEvaluationTemplate(template, evaluation);
                evaluationTemplate.AppendAnswers(answersList);
                var scoreService = ServicesFacade.Instance.GetScoreService();
                var caluculatedEvaluation = scoreService.CalculateScore(evaluationTemplate);

                Log.Info($"Creating answers for evaluation {idEvaluation}");
                caluculatedEvaluation.IdEvaluation = idEvaluation;
                caluculatedEvaluation.Date = DateTime.Now.ToUniversalTime();
                EvaluationScore newAnswers = answersDao.CreateAnswers(caluculatedEvaluation);

                Log.Info($"Evaluation answers created succesfully, Id {newAnswers.Id}");
                return newAnswers;
            }));
        }
コード例 #2
0
 public EvaluationScore CreateAnswers(Guid idEvaluation, EvaluationAnswer answersList)
 {
     return(new EvaluationScore()
     {
         Id = Guid.NewGuid(),
         IdEvaluation = answersList.IdEvaluation,
         Date = DateTime.Parse("2019-02-28T12:12:00.5973309Z"),
         Score = 0,
         Owner = "anonymous 1"
     });
 }
コード例 #3
0
 public ActionResult <EvaluationScore> PostAnswers(Guid idEvaluation, [FromBody] EvaluationAnswer answersList)
 {
     return(this.ExecuteRequestAndHandle(
                () =>
     {
         var newAnswers = ServicesFacade.Instance.GetAnswersService().CreateAnswers(idEvaluation, answersList);
         Log.Info(string.Format("Answers for evaluation {0} created", idEvaluation));
         return newAnswers;
     },
                StatusCodes.Status201Created));
 }
コード例 #4
0
        public void TestCreateEvaluationAnswers_ReturnStatusCreated()
        {
            var sampleAnswers = new EvaluationAnswer
            {
                IdEvaluation = Guid.NewGuid()
            };

            var id       = sampleAnswers.IdEvaluation;
            var actual   = this.Controller.PostAnswers(id, sampleAnswers).Result as IStatusCodeActionResult;
            var expected = StatusCodes.Status201Created;

            Assert.Equal(actual.StatusCode, expected);
        }
コード例 #5
0
 public static EvaluationAnswerModel ToModel(this EvaluationAnswer model)
 {
     if (model == null)
     {
         return(null);
     }
     return(new EvaluationAnswerModel
     {
         Id = model.Id,
         Title = model.Text,
         Score = model.Score,
         Order = model.Order
     });
 }
コード例 #6
0
        public static void AppendAnswers(this EvaluationScore evaluationTemplate, EvaluationAnswer answers)
        {
            evaluationTemplate.Date  = answers.Date;
            evaluationTemplate.Owner = answers.Owner;
            var questionAnswers = answers.Sections.SelectMany(p => p.QuestionAnswers);

            questionAnswers.Join(
                evaluationTemplate.QuestionList,
                questionAnswer => questionAnswer.IdQuestion,
                evaluationQuestion => evaluationQuestion.IdQuestion,
                (questionAnswer, evaluationAnswer) =>
            {
                evaluationAnswer.Answers = questionAnswer.SelectedAnswersIds;
                return(true);
            }).ToArray();
        }
コード例 #7
0
        public void TestAppendAnswers()
        {
            var answerList = new EvaluationAnswer()
            {
                IdEvaluation = this.Evaluation.Id,
                Owner        = "annonymous",
                Sections     = new List <SectionAnswer>()
                {
                    new SectionAnswer()
                    {
                        QuestionAnswers = new List <QuestionAnswer>()
                        {
                            new QuestionAnswer()
                            {
                                IdQuestion         = this.Evaluation.Body[0].Questions[0].Id,
                                SelectedAnswersIds = new List <Guid>()
                                {
                                    this.Evaluation.Body[0].Questions[0].Options[0].Id
                                }
                            },
                            new QuestionAnswer()
                            {
                                IdQuestion         = this.Evaluation.Body[0].Questions[1].Id,
                                SelectedAnswersIds = new List <Guid>()
                                {
                                    this.Evaluation.Body[0].Questions[1].Options[1].Id,
                                    this.Evaluation.Body[0].Questions[1].Options[0].Id,
                                    this.Evaluation.Body[0].Questions[0].Options[0].Id
                                }
                            }
                        }
                    }
                }
            };

            EvaluationScoreHelpers.AppendAnswers(this.Expected, answerList);

            Assert.Equal(answerList.Sections[0].QuestionAnswers[0].SelectedAnswersIds, this.Expected.QuestionList.ToList()[0].Answers.ToList());
            Assert.Equal(answerList.Sections[0].QuestionAnswers[1].SelectedAnswersIds, this.Expected.QuestionList.ToList()[1].Answers.ToList());
        }
コード例 #8
0
 public void SetAnswer(long evaluationQuestionId, long evaluationId)
 {
     Answer = new EvaluationAnswer(evaluationQuestionId, evaluationId);
 }