예제 #1
0
        public bool Add(Data.ApplicationDbContext context)
        {
            try
            {
                var question = new Data.Question {
                    Title = this.Title, SurveyId = this.ParentId
                };

                context.Questions.Add(question);
                context.SaveChanges();

                if (this.Childs != null)
                {
                    foreach (var child in this.Childs)
                    {
                        child.Add(context);
                    }
                }

                return(true);
            }
            catch
            {
                return(false);
            }
        }
예제 #2
0
 public static SignupQuestion Create(Data.Question q)
 => new SignupQuestion
 {
     Id          = q.Id,
     Type        = q.Type,
     Title       = q.Title,
     Description = q.Description,
     Options     = q.Options.ToList()
 };
예제 #3
0
        public async Task <bool> CreateQuiz(Models.NewQuizModel newQuiz)
        {
            var quiz = new Data.Quiz
            {
                Title     = newQuiz.Title,
                Questions = new List <Data.Question>()
            };

            foreach (var question in newQuiz.NewQuestions)
            {
                var questionToAdd = new Data.Question
                {
                    QuestionString = question.Question,
                    CorrectAnswer  = new Answer {
                        AnswerText = question.CorrectAnswer
                    },
                    WrongAnswers = new WrongAnswers()
                    {
                        Answers = new List <Answer>()
                    }
                };

                foreach (var wrongAnswer in question.WrongAnswers)
                {
                    var wrongAnswerToAdd = new Answer
                    {
                        AnswerText = wrongAnswer
                    };

                    questionToAdd.WrongAnswers.Answers.Add(wrongAnswerToAdd);
                }
                ;

                quiz.Questions.Add(questionToAdd);
            }
            ;


            try
            {
                await _quizManagerContext.Quizzes.AddAsync(quiz);

                await _quizManagerContext.SaveChangesAsync();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
예제 #4
0
 public static DTO.QuestionResponse MapQuestionResponse(this Data.Question question)
 => new DTO.QuestionResponse
 {
     Id = question.Id,
     QuestionContent = question.QuestionContent,
     QuestionPoints  = question.QuestionPoints,
     QuestionPapers  = question.QuestionPQuestions?.Select(qp => new DTO.QuestionPaper
     {
         Id          = qp.QuestionPaperId,
         Description = qp.QuestionPaper.Description
     }).ToList(),
     Answers = question.QuestionAnswers?.Select(a => new DTO.Answer <string>
     {
         Id            = a.AnswerId,
         AnswerContent = a.Answer.AnswerContent
     }).ToList()
 };
예제 #5
0
        public async Task <bool> CreateQuestion(NewQuestionModel question)
        {
            var questionToInsert = new Data.Question
            {
                QuestionString = question.Question,
                CorrectAnswer  = new Answer
                {
                    AnswerText = question.CorrectAnswer
                },
                WrongAnswers = new WrongAnswers
                {
                    Answers = new List <Answer>()
                }
            };

            foreach (var wrongAnswer in question.WrongAnswers)
            {
                var wrongAnswerToAdd = new Answer
                {
                    AnswerText = wrongAnswer
                };

                questionToInsert.WrongAnswers.Answers.Add(wrongAnswerToAdd);
            }
            ;

            try
            {
                var quiz = await _quizManagerContext.Quizzes
                           .Include(a => a.Questions)
                           .ThenInclude(b => b.CorrectAnswer)
                           .Include(c => c.Questions)
                           .ThenInclude(d => d.WrongAnswers)
                           .ThenInclude(e => e.Answers)
                           .FirstOrDefaultAsync(x => x.Id == Convert.ToInt32(question.QuizId));

                quiz.Questions.Add(questionToInsert);
                await _quizManagerContext.SaveChangesAsync();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
 public static SignupQuestion Create(Data.Question q)
 => new()