public async Task <ObterClienteResult> Handle(ObterClienteQuery request, CancellationToken cancellationToken) { ClienteEntity result = null; if (request.Id.HasValue) { result = await _repository.ObterPorId(request.Id.Value); } else { result = await _repository.ObterPorCPF(request.CPF.Value); } if (result == null) { return(null); } return(_mapper.Map <ObterClienteResult>(result)); }
public async Task <ClienteDto> Handle(ObterClienteQuery request, CancellationToken cancellationToken) { if (request.Id == null || request.Id == Guid.Empty) { request.AddNotification("ObterClienteQuery.Id", "Id é obrigatório."); } if (request.Invalid) { await _mediator.Publish(new DomainNotification { Erros = request.Notifications }, cancellationToken); ClienteDto clienteNull = null; return(await Task.FromResult(clienteNull)); } return(_clienteRepository.GetById(request.Id)); }
public async Task <ClienteDto> Obter(Guid id) { var command = new ObterClienteQuery(id); return(await _mediator.Send(command)); }