Example #1
0
        public async Task <DeleteCotacaoCommandResponse> Handle(DeleteCotacaoCommand request, CancellationToken cancellationToken)
        {
            var response = new DeleteCotacaoCommandResponse();

            if (!request.IsValid())
            {
                var notifications = new List <Notification>();

                foreach (var item in request.ValidationResult.Errors)
                {
                    var notification = new Notification
                    {
                        Exception = "Notificação.",
                        Message   = item.ErrorMessage
                    };
                    notifications.Add(notification);
                }

                response = new DeleteCotacaoCommandResponse
                {
                    Data = new Data
                    {
                        Message = "Cotação com dados inválidos.",
                        Status  = Status.Error
                    },
                    Notification = notifications
                };
            }
            else
            {
                _cotacaoRepository.Delete(request.Id);

                response = new DeleteCotacaoCommandResponse
                {
                    Data = new Data
                    {
                        Message = "Cotação removida com sucesso.",
                        Status  = Status.Sucessed
                    }
                };
            }
            return(await Task.FromResult(response));
        }
        public async Task <IActionResult> Delete(int id)
        {
            try
            {
                if (id == 0)
                {
                    return(BadRequest());
                }

                if (await _cotacaoRepository.Delete(id))
                {
                    return(Ok());
                }
                else
                {
                    return(StatusCode(404));
                }
            }
            catch (Exception ex)
            {
                return(StatusCode(500, ex));
            }
        }