Ejemplo n.º 1
0
        public async Task <ActionResult> QuestionLike(
            [FromRoute] Guid id)
        {
            var command = new LikeQuestionCommand {
                QuestionId = id
            };
            var result = await _bus.SendCommand(command);

            if (!result.Sucess)
            {
                return(BadRequest(result));
            }

            return(Ok(result));
        }
Ejemplo n.º 2
0
        public async Task <CommandResult> Handle(LikeQuestionCommand command, CancellationToken ct = default(CancellationToken))
        {
            // Validar comando (Fail Fast Validation)
            command.Validate();
            if (command.Invalid)
            {
                return(new CommandResult(Message.LikeInvalidCommand, command.Notifications));
            }

            // Verifica se a pergunta existe
            var question = await _questionRepository.GetById(command.QuestionId);

            if (question == null)
            {
                return(new CommandResult(Message.QuestionNotFound));
            }

            // Curtiu a pergunta
            question.Like();
            await _questionRepository.Update(question);

            // Retornar o resultado
            return(new CommandResult(Message.LikedSucess, question));
        }