public void Remove(DeleteClienteCommand command) { var cliente = clienteRepository.GetById(command.Id); if (cliente == null) { throw new Exception("Cliente não encontrado."); } clienteRepository.Remove(cliente); }
public async Task <ActionResult> ExcluirCliente(Guid id) { var command = new DeleteClienteCommand { Id = id }; await _bus.Send(command); if (!_notificationContext.HasErrorNotifications) { return(NoContent()); } var notifications = _notificationContext.GetErrorNotifications(); return(BadRequest(notifications)); }
public async Task <bool> Handle(DeleteClienteCommand request, CancellationToken cancellationToken) { if (request == null) { return(false); } var cliente = new Cliente(request.id); await _repository.Delete(cliente.id); await _repository.Save(); await _mediator.Publish(new ClienteDeleteEvent(cliente.id), cancellationToken); return(await Task.FromResult(true)); }
public IActionResult Delete(int id) { try { var command = new DeleteClienteCommand { Id = id }; clienteApplicationService.Remove(command); return(Ok(new { Message = "Cliente excluido com sucesso." })); } catch (Exception e) { return(StatusCode(500, e.Message)); } }
public async Task <IActionResult> Delete(DeleteClienteCommand obj) { var x = await _mediator.Send(obj); return(Ok(x)); }