Esempio n. 1
0
        public TestQuestionTagDTO GetTestWithQuestionsAndTagsByID(int id)
        {
            using (var connection = Connection.GetConnection())
            {
                TestQuestionTagDTO result        = null;
                string             sqlExpression = "GetTestsByIdOneToMany";
                connection.Query <TestQuestionTagDTO, QuestionForOneToManyDTO, TagWithTestIDDTO, TestQuestionTagDTO>(sqlExpression, (test, question, tag) =>
                {
                    if (result == null)
                    {
                        result           = test;
                        result.Questions = new List <QuestionForOneToManyDTO>();
                        result.Questions.Add(question);
                        result.Tags = new List <TagWithTestIDDTO>();
                        result.Tags.Add(tag);
                    }
                    else
                    {
                        if (!result.Questions.Any(x => x.Value == question.Value))
                        {
                            result.Questions.Add(question);
                        }
                        if (!result.Tags.Any(x => x.Name == tag.Name))
                        {
                            result.Tags.Add(tag);
                        }
                    }

                    return(result);
                }
                                                                                                                     , new { id }
                                                                                                                     , splitOn: "TestID,IDtest", commandType: CommandType.StoredProcedure);
                return(result);
            }
        }
Esempio n. 2
0
        public TestOutputModel ConvertTestQuestionTagDTOToTestOutputModel(TestQuestionTagDTO testDTO)
        {
            if (testDTO != null)
            {
                List <QuestionOutputModel> questions = ConvertQuestionForOneToManyDTOToQuestionModelList(testDTO.Questions);
                List <TagOutputModel>      tags      = ConvertTagsWithTestIdToTagOutputModel(testDTO.Tags);

                return(new TestOutputModel()
                {
                    ID = testDTO.ID,
                    Name = testDTO.Name,
                    SuccessScore = testDTO.SuccessScore,
                    DurationTime = testDTO.DurationTime,
                    QuestionNumber = testDTO.QuestionNumber,
                    Questions = questions,
                    Tags = tags
                });
            }
            else
            {
                return(new TestOutputModel());
            }
        }