public async Task <bool> Handle(AtualizarItemPedidoCommand request, CancellationToken cancellationToken) { if (!ValidarComando(request)) { return(false); } var pedido = await _pedidoRepository.ObterPedidoRascunhoPorClienteId(request.ClienteId); if (pedido == null) { await _mediatorHandler.PublicarNotificacao(new DomainNotification("pedido", "Pedido não encontrado!")); return(false); } var pedidoItem = await _pedidoRepository.ObterItemPorPedido(pedido.Id, request.ProdutoId); if (!pedido.PedidoItemExistente(pedidoItem)) { await _mediatorHandler.PublicarNotificacao(new DomainNotification("pedido", "Item do pedido não encontrado!")); return(false); } pedido.AtualizarUnidades(pedidoItem, request.Quantidade); pedido.AdicionarEvento(new PedidoProdutoAtualizadoEvent(request.ClienteId, pedido.Id, request.ProdutoId, request.Quantidade)); _pedidoRepository.AtualizarItem(pedidoItem); _pedidoRepository.Atualizar(pedido); return(await _pedidoRepository.UnitOfWork.Commit()); }
public async Task <IActionResult> Put(Guid id, [FromBody] ItemViewModel item) { var produto = await _produtoAppService.ObterPorId(id); if (produto == null) { return(BadRequest()); } var command = new AtualizarItemPedidoCommand(ClienteId, produto.Id, item.Quantidade); await _mediatorHandler.Send(command); return(Response()); }
public async Task <bool> Handle(AtualizarItemPedidoCommand message, CancellationToken cancellationToken) { if (!ValidarComando(message)) { return(false); } var pedido = await _pedidoRepository.ObterPorId(message.PedidoId); pedido.AtualizarItemPedido(new PedidoItem(message.Id, message.ProdutoId, message.Quantidade, message.PedidoId)); var pedidoItem = await _pedidoRepository.ObterItemPorPedido(pedido.Id, message.ProdutoId); _pedidoRepository.AtualizarItem(pedidoItem); return(true); }
public async Task <IActionResult> AtualizarItem(Guid id, int quantidade) { var produto = await _produtoAppService.ObterPorId(id); if (produto == null) { return(BadRequest()); } var command = new AtualizarItemPedidoCommand(ClienteId, id, quantidade); await _mediatorHandler.EnviarComando(command); if (OperacaoValida()) { return(RedirectToAction("Index")); } return(View("Index", await _pedidoQueries.ObterCarrinhoCliente(ClienteId))); }
public async Task <string> Put(int id, [FromBody] PedidoModel model) { try { AtualizarPedidoCommand atualizarPedidoCommand = new AtualizarPedidoCommand(model.Id, model.Cliente.Id); await _mediatorHandler.EnviarComando(atualizarPedidoCommand); foreach (var item in model.Itens) { AtualizarItemPedidoCommand adicionarItemPedidoCommand = new AtualizarItemPedidoCommand(item.Produto.Id, item.Quantidade); await _mediatorHandler.EnviarComando(adicionarItemPedidoCommand); } } catch (DominioException ex) { return(ex.Message); } catch (Exception ex) { return(ex.Message); } return(null); }