Esempio n. 1
0
        public async Task <ActionResult> AnswerLike(
            [FromRoute] Guid id)
        {
            var command = new LikeAnswerCommand {
                AnswerId = id
            };
            var result = await _bus.SendCommand(command);

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

            return(Ok(result));
        }
Esempio n. 2
0
        public async Task <CommandResult> Handle(LikeAnswerCommand 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 resposta existe
            var answer = await _answerRepository.GetById(command.AnswerId);

            if (answer == null)
            {
                return(new CommandResult(Message.AnswerNotFound));
            }

            // Curtiu a resposta
            answer.Like();
            await _answerRepository.Update(answer);

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