Exemplo n.º 1
0
        public async Task <Guid> CreateNew(QuestionCreateModel newQuestion)
        {
            var question = Domain.Entities.Question.Create(newQuestion.TeacherId, newQuestion.CourseId, newQuestion.Duration,
                                                           newQuestion.Points, newQuestion.Text);

            await _writeRepository.AddNewAsync(question);

            await _writeRepository.SaveAsync();

            await _writeRepository.SaveAsync();

            return(question.Id);
        }
Exemplo n.º 2
0
        //public async Task<bool> AddAnswer(Guid questionId, AnswerCreateModel answer)
        //{
        //    var existingQuestion = await _readRepository.FindByIdAsync<Domain.Entities.Question>(questionId);
        //    if (existingQuestion != null)
        //    {
        //        if (QuestionStillAvailable(existingQuestion.AddTime, existingQuestion.Duration))
        //        {
        //            var addAnswer = Domain.Entities.Answer.Create(answer.StudentId, questionId, answer.Text);
        //            existingQuestion.AddAnswer(addAnswer);
        //            existingQuestion.Answers.Add(addAnswer);

        //            await _writeRepository.UpdateAsync(existingQuestion.Id, existingQuestion);
        //            await _writeRepository.SaveAsync();
        //            return true;
        //        }
        //    }
        //    return false;
        //}

        public async Task <Guid> Update(Guid id, QuestionCreateModel updatedQuestion)
        {
            var exist = await _readRepository.FindByIdAsync <Domain.Entities.Question>(id);

            if (exist != null)
            {
                exist.Update(updatedQuestion.TeacherId, updatedQuestion.CourseId, updatedQuestion.Duration,
                             updatedQuestion.Points, updatedQuestion.Text);
                await _writeRepository.UpdateAsync(id, exist);

                await _writeRepository.SaveAsync();
            }
            return(exist.Id);
        }