Exemple #1
0
        /// <summary>
        /// Overload of SaveAnswer in a true or false request.
        /// It will verify if the user is the owner and if the already answer exists.
        /// Create a new answer in case of it is required, or save the values in the
        /// existing answer.
        /// </summary>
        /// <param name="answer">Answer to be persisted</param>
        /// <returns></returns>
        public ResultOperation SaveAnswer(TrueFalseAnswerView answer)
        {
            //It calls the method SaveAnswer that has a default routine for saving, and
            //gives two delegates, the first to be executed in case of Inclusion and the
            //second in case of Update.
            return(this.SaveAnswer(answer,
                                   repository =>
            {
                return new Domain.TrueFalseAnswer()
                {
                    Choice = answer.Option
                };
            },
                                   (repository, updatedItem) =>
            {
                (updatedItem as Domain.TrueFalseAnswer).Choice = answer.Option;

                return true;
            }));
        }
Exemple #2
0
        /// <summary>
        /// Create the specific AnswerView based on the question type.
        /// Can return a TrueFalseAnswerview, MultipleChoiceAnswerView or OpenEndedAnswerView
        /// </summary>
        /// <param name="repository"></param>
        /// <param name="answer"></param>
        /// <param name="idQuestion"></param>
        /// <param name="infoAnswer"></param>
        /// <returns></returns>
        private AnswerModelViewBase CreateAnswerModelView(IRepository repository,
                                                          Answer answer, int idQuestion, Domain.AnswerQuestionOption infoAnswer)
        {
            AnswerModelViewBase returnAnswer = null;

            switch (repository.GetQuestion(idQuestion).QuestionType)
            {
            case QuestionType.TrueFalse_Question:
                returnAnswer = new TrueFalseAnswerView()
                {
                    Option = (infoAnswer as TrueFalseAnswer).Choice
                };
                break;

            case QuestionType.Multiple_Choice:
                returnAnswer = new MultipleChoiceAnswerView()
                {
                    IdAnswers = new List <int>()
                };

                foreach (var item in repository.GetMultipleChoiceAnswer(answer.Id, idQuestion).MultipleChoice_Choices)
                {
                    (returnAnswer as MultipleChoiceAnswerView).IdAnswers.Add(item.IdChoice);
                }

                break;

            case QuestionType.Open_Ended:
                returnAnswer = new OpenEndedAnswerView()
                {
                    Content = (infoAnswer as OpenEnded).Response
                };
                break;
            }

            return(returnAnswer);
        }