Inheritance: IQuestion
        public QuestionViewModel(
            Question question, 
            IValidator<Question> questionValidator,
            IValidator<Answer> answerValidator,
            IValidator<AssociatedSubject> subjectValidator,
            ISubjectQuery subjectQuery,
            Guid busId
        )
            : base()
        {
            _busId = busId;
            _question = question;
            _questionValidator = questionValidator;
            _answerValidator = answerValidator;
            _subjectValidator = subjectValidator;
            _subjectQuery = subjectQuery;

            InitializeCommands();
            InitializeAnswers();
        }
 public void DeleteQuestionChoice(Action action, Question question, Choice choice)
 {
     ThrowBusinessRuleViolation(question);
     question.DeleteChoice(action, choice);
 }
Exemple #3
0
 public NewAnswer(Question question)
 {
     _question = question;
 }
 public Question CreateQuestion(string text, bool isActive)
 {
     var question = new Question(text, isActive);
     Questions.Add(question);
     return question;
 }
 public void DeleteQuestion(Question question, Action action)
 {
     ThrowBusinessRuleViolation(question);
     action();
 }
Exemple #6
0
 public RemoveAnswer(Question question, Answer answer)
 {
     _question = question;
     _answer = answer;
 }
 private void ThrowBusinessRuleViolation(Question question)
 {
     if (question.IsBeingUsedInTestInstance)
         throw new BusinessRuleException("Unable to update question because is it being used in the Test Instance");
     else if (question.IsBeingUsedInTestTemplate)
         throw new BusinessRuleException("Unable to update question because is it being used in the Test Template");
 }
 public void DeleteQuestion(Question question, Action action)
 {
     QuestionBank.DeleteQuestion(question, action);
 }
 public void DeleteQuestionChoice(Action action, Question question, Choice choice)
 {
     QuestionBank.DeleteQuestionChoice(action, question, choice);
 }
Exemple #10
0
                public async Task <QuestionDto> Handle(CreateQuestionsCommand request, CancellationToken cancellationToken)
                {
                    var quiz = await _context.Quizzes
                               .Where(x => x.Id == request.QuizId)
                               .FirstOrDefaultAsync();

                    if (quiz == null)
                    {
                        throw new RestException(HttpStatusCode.NotFound, "Quiz Not Found");
                    }

                    await using var transaction = await _context.Database.BeginTransactionAsync();

                    var inputType = await _context.InputTypes
                                    .Where(x => x.Id == request.InputTypeId)
                                    .FirstOrDefaultAsync();

                    if (inputType == null)
                    {
                        await transaction.RollbackAsync();

                        throw new RestException(HttpStatusCode.NotFound, "Input Type Not Found");
                    }

                    var question = new Domain.Question
                    {
                        Title           = request.Title,
                        Required        = request.Required,
                        MultipleOptions = request.MultipleOptions,
                        Quiz            = quiz,
                        InputType       = inputType
                    };

                    await _context.Questions.AddAsync(question);

                    if (await _context.SaveChangesAsync() < 1)
                    {
                        await transaction.RollbackAsync();

                        throw new RestException(HttpStatusCode.BadRequest, "Error savig questions changes");
                    }

                    if (request.MultipleOptions && request.Options != null)
                    {
                        foreach (var option in request.Options)
                        {
                            var op = new Option
                            {
                                Description = option,
                                Question    = question
                            };

                            await _context.Options.AddAsync(op);
                        }

                        if (await _context.SaveChangesAsync() < 1)
                        {
                            await transaction.RollbackAsync();

                            throw new RestException(HttpStatusCode.BadRequest, "Error savig option changes");
                        }
                    }

                    var document = new Document();

                    if (request.File != null)
                    {
                        document = await _uploadFiles.UploadDocuments(request.File);

                        document.Question = question;

                        await _context.Documents.AddAsync(document);

                        if (await _context.SaveChangesAsync() < 1)
                        {
                            await transaction.RollbackAsync();

                            throw new RestException(HttpStatusCode.BadRequest, "Error savig document changes");
                        }
                    }

                    await transaction.CommitAsync();

                    // var mapper = _customMapper.GetMapper();
                    // var questionDto = mapper.Map<QuestionDto>(question);


                    var documentUrl = new Document();

                    if (request.File != null)
                    {
                        documentUrl = await _documentsUrl.GetDocumentUrl(document, "Questions");
                    }

                    var options = await _context.Options
                                  .Where(x => x.Question == question)
                                  .Select(x => new OptionDto
                    {
                        Description = x.Description,
                        QuestionId  = question.Id
                    })
                                  .ToListAsync();

                    return(new QuestionDto
                    {
                        Title = question.Title,
                        Required = question.Required,
                        Document = documentUrl,
                        InputType = inputType,
                        MultipleOptions = question.MultipleOptions,
                        Options = options,
                        QuizId = request.QuizId
                    });
                }
Exemple #11
0
 private void deleteQuestion(Question question)
 {
     deleteAllQuestionChoice(question.Choices.ToList());
     _context.Questions.Remove(question);
 }
 private void RaiseQuestionRemoved(Question question)
 {
     var handler = QuestionRemovedEvent;
     if (handler != null)
         handler(this, new QuestionEventArgs(question));
 }
 public QuestionEventArgs(Question question)
 {
     _question = question;
 }
Exemple #14
0
        public long GetRecountFor(Guid questionId, Guid choiceId)
        {
            Question question = null;
            var      urns     = new List <Guid>();
            var      recounts = new List <Recount>();

            foreach (var block in trunk)
            {
                if (question == null)
                {
                    foreach (var i in block.Questions)
                    {
                        if (i.Id == questionId)
                        {
                            question = i;
                            break;
                        }
                    }
                }

                if (question != null)
                {
                    foreach (var urn in block.Urns)
                    {
                        if (urn.QuestionId == questionId)
                        {
                            urns.Add(urn.Id);
                        }
                    }

                    foreach (var recount in block.Recounts)
                    {
                        if (urns.Contains(recount.UrnId))
                        {
                            recounts.Add(recount);
                        }
                    }
                }
            }

            var recountByUrn = recounts.GroupBy(r => r.UrnId);

            long total = 0;

            foreach (var group in recountByUrn)
            {
                var results = group.SelectMany(g => g.Results).Where(r => r.ChoiceId == choiceId).ToArray();

                var votes = results[0].Votes;
                foreach (var result in results)
                {
                    if (result.Votes != votes)
                    {
                        votes = 0;
                        break;
                    }
                }

                total += votes;
            }

            return(total);
        }