public async Task <IActionResult> Delete(int id) { var dto = new PessoaDeleteCommand { Id = id }; var result = await _mediator.Send(dto); return(Ok(result)); }
public async Task <OperationResult <PessoaEntity> > Handle(PessoaDeleteCommand request, CancellationToken cancellationToken) { var pessoa = await _appDbContext.Pessoas.FindAsync(request.Id); if (pessoa is null) { return(OperationResult <PessoaEntity> .CreateFailure("Pessoa não encontrada")); } _appDbContext.Pessoas.Remove(pessoa); await _appDbContext.SaveChangesAsync(); return(OperationResult <PessoaEntity> .CreateSuccessResult(pessoa)); }
public Task <string> Handle(PessoaDeleteCommand request, CancellationToken cancellationToken) { var pessoa = domainService.GetId(Guid.Parse(request.Id)); domainService.Delete(pessoa); mediator.Publish(new PessoaNotification { Pessoa = pessoa, Action = ActionNotification.Excluido, DataHora = DateTime.Now }); return(Task.FromResult($"{pessoa.Nome} {pessoa.Sobrenome} foi excluido do sistama com sucesso.")); }
public async Task <IActionResult> Delete(string id) { try { var command = new PessoaDeleteCommand { Id = id }; var result = await pessoaApplicationService.Delete(command); return(Ok(result)); } catch (Exception e) { return(StatusCode(500, e.Message)); } }
public async Task <string> Handle(PessoaDeleteCommand request, CancellationToken cancellationToken) { var client = await _PessoaRepository.GetById(request.Id); await _PessoaRepository.Delete(request.Id); await _mediator.Publish(new PessoaActionNotification { Nome = client.Nome, Telefone = client.Telefone, Idade = client.Idade, CPF = client.CPF, Action = ActionNotification.Excluido }, cancellationToken); return(await Task.FromResult("Cliente excluido com sucesso")); }
public Task <string> Delete(PessoaDeleteCommand command) { return(mediator.Send(command)); }