public async Task <bool> Handle(AskQuestionCommand request, CancellationToken cancellationToken) { var question = new QuestionEntity( request.Title, request.UserId, request.Tags ); question.DefineId(request.Id); var questionBody = new AnswerEntity( request.Body, request.UserId, AnswerKind.QuestionBody, votes: 0 ); questionBody.DefineId(Guid.NewGuid()); question.SetQuestionBody(questionBody); await _repository.RegisterAsync(question); return(true); }
public AnswerEntity Execute(AnswerModel from) { var entity = new AnswerEntity( from.Body, from.UserId, (AnswerKind)from.KindOf, from.Votes ); entity.DefineId(from.Id); from.Comments.ToList().ForEach(comment => { var newComment = _commentFactory.Execute(comment); newComment.SetParent(entity); entity.AddComment(newComment); }); return(entity); }
public async Task <bool> Handle(AnswerCommand request, CancellationToken cancellationToken) { var question = _questionRepository.GetById(request.QuestionId); if (question == null) { //todo: Send error message return(false); } var answer = new AnswerEntity( request.Body, request.UserId, AnswerKind.Answer, votes: 0); answer.DefineId(request.Id); answer.SetParent(question); await _answerRepository.RegisterAsync(answer); return(true); }