Exemplo n.º 1
0
        public void Create(AlternativeManager alternativeManager, SendQuestionManager sendQuestionManager, SubscribeManager subscribeManager, Question question, Course course, List <Alternative> alternatives)
        {
            Transaction(() =>
            {
                if (course == null)
                {
                    throw new QuestionarException("O curso selecionado é inválido.");
                }

                if (string.IsNullOrEmpty(question.Description))
                {
                    throw new QuestionarException("Descrição é um campo obrigatório.");
                }

                question.Course = course;
                question.Order  = Order(question);
                Repository.Create(question);
                alternativeManager.Create(alternatives, question);

                var isTheFirst = !Repository.Query().Any(c => c.Id != question.Id && c.Course.Id == course.Id);
                if (isTheFirst)
                {
                    SendFirstQuestion(subscribeManager, sendQuestionManager, course, question);
                    question.Sent     = true;
                    question.SentDate = DateTime.Now;
                }
            });
        }
Exemplo n.º 2
0
        public List <MQuestion> ListByTeacher(AlternativeManager alternativeManager, User teacher)
        {
            var questions    = Repository.Query().Where(c => c.Course.Teacher.Id == teacher.Id).OrderByDescending(c => c.Id).ToList();
            var alternatives = alternativeManager.GetByQuestions(questions);

            return(GroupAlternatives(questions, alternatives));
        }
Exemplo n.º 3
0
        public MQuestion DailyQuestion(User user, AlternativeManager alternativeManager)
        {
            var question = Repository.Query()
                           .Where(c => c.User.Id == user.Id && c.Question.SentDate.Date == DateTime.Now.Date && !c.Answered)
                           .Select(c => c.Question).FirstOrDefault();

            if (question != null)
            {
                return new MQuestion()
                       {
                           Course       = question.Course,
                           Description  = question.Description,
                           Alternatives = alternativeManager.GetByQuestion(question)
                       }
            }
            ;

            return(null);
        }
Exemplo n.º 4
0
        public bool Reply(int idAlternative, User student, AlternativeManager alternativeManager, SendQuestionManager sendQuestionManager)
        {
            var alternative = alternativeManager.Repository.GetById(idAlternative);

            if (alternative == null)
            {
                throw new QuestionarException("Alternativa inválida");
            }

            Transaction(() =>
            {
                var answer = new Answer()
                {
                    Alternative = alternative,
                    Student     = student,
                    Created     = DateTime.Now
                };

                Repository.Create(answer);
                sendQuestionManager.AnswerQuestion(student, alternative.Question);
            });

            return(alternative.IsCorrect);
        }