public async Task <bool> Handle(RemoverItemPedidoCommand message, CancellationToken cancellationToken) { if (!ValidarComando(message)) { return(false); } var pedido = await _pedidoRepository.ObterPedidoRascunhoPorClienteId(message.ClienteId); if (pedido == null) { await _mediatorHandler.PublicarNotificacao(new DomainNotification("pedido", "Pedido não encontrado!")); return(false); } var pedidoItem = await _pedidoRepository.ObterItemPorPedido(pedido.Id, message.ProdutoId); if (pedidoItem != null && !pedido.PedidoItemExistente(pedidoItem)) { await _mediatorHandler.PublicarNotificacao(new DomainNotification("pedido", "Item do pedido não encontrado!")); return(false); } pedido.RemoverItem(pedidoItem); pedido.AdicionarEvento(new PedidoProdutoRemovidoEvent(message.ClienteId, pedido.Id, message.ProdutoId)); _pedidoRepository.RemoverItem(pedidoItem); _pedidoRepository.Atualizar(pedido); return(await _pedidoRepository.UnitOfWork.Commit()); }
public async Task <IActionResult> Delete(Guid id) { var produto = await _produtoAppService.ObterPorId(id); if (produto == null) { return(BadRequest()); } var command = new RemoverItemPedidoCommand(ClienteId, id); await _mediatorHandler.Send(command); return(Response()); }
public async Task <IActionResult> RemoverItem(Guid id) { var produto = await _produtoAppService.ObterPorId(id); if (produto == null) { return(BadRequest()); } var command = new RemoverItemPedidoCommand(ClienteId, id); await _mediatorHandler.EnviarComando(command); if (OperacaoValida()) { return(RedirectToAction("Index")); } return(View("Index", await _pedidoQueries.ObterCarrinhoCliente(ClienteId))); }