Esempio n. 1
0
        public async Task <bool> Handle(RegisterAnswerCommentCommand request, CancellationToken cancellationToken)
        {
            var question = await _questionRepository.GetByIdAsync(request.QuestionId);

            if (question == null)
            {
                return(false);
            }

            var answer = question.Answers.ToList().FirstOrDefault(answer => answer.Id == request.AnswerId);

            if (answer == null)
            {
                return(false);
            }

            var comment = new CommentEntity(
                request.UserId,
                request.Body
                );

            comment.DefineId(request.Id);
            comment.SetParent(answer);

            await _repository.RegisterCommentAsync(comment);

            return(true);
        }
Esempio n. 2
0
        public CommentEntity Execute(AnswerModel from)
        {
            var entity = new CommentEntity(
                from.UserId,
                from.Body
                );

            entity.DefineId(from.Id);
            return(entity);
        }
Esempio n. 3
0
        public async Task <bool> Handle(RegisterQuestionCommentCommand request, CancellationToken cancellationToken)
        {
            var question = await _questionRepository.GetByIdAsync(request.QuestionId);

            if (question == null)
            {
                return(false);
            }

            var comment = new CommentEntity(
                request.UserId,
                request.Body
                );

            comment.DefineId(request.Id);
            comment.SetParent(question);

            await _questionRepository.RegisterCommentAsync(comment);

            return(true);
        }