Beispiel #1
0
        public async Task <IActionResult> Remove(string id)
        {
            try
            {
                var removeJokeRequest = new RemoveJokeRequest
                {
                    Id = id
                };

                return(Ok(await _mediator.Send(removeJokeRequest)));
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex.Message));
            }
        }
Beispiel #2
0
        public async Task <RemoveJokeResponse> Handle(RemoveJokeRequest request, CancellationToken cancellationToken)
        {
            var jokeExists = await _jokeRepository.Get(request.Id);

            if (jokeExists == null)
            {
                throw new Exception("Piada não encontrada na base de dados.");
            }

            await _jokeRepository.Remove(request.Id);

            return(new RemoveJokeResponse
            {
                Message = "Piada deletada com sucesso!"
            });
        }