public void CadastrarClienteErroValidacao() { var clienteServiceMock = new ClienteServicoMock(); var clienteServico = clienteServiceMock.ConfigurarCadastrarSucesso().Build(); var cadastrarCommand = new CadastrarClienteCommand(clienteServico, new CadastrarClienteValidador()); Assert.ThrowsAsync <ArgumentException>(() => cadastrarCommand.Executar(new CadastrarClientesInput { Bairro = "Dornelas", Cep = "32123321", Cidade = "Belo Horizonte", Cpf = "025321256952", Endereco = "Rua Teste", Telefone = "33333333", Uf = "MG", })); Assert.ThrowsAsync <ArgumentException>(() => cadastrarCommand.Executar(new CadastrarClientesInput { Bairro = "Dornelas", Cep = "32123321", Cidade = "Belo Horizonte", Endereco = "Rua Teste", NomeCompleto = "Nadal dos Santos", Telefone = "33333333", Uf = "MG", })); }
public async Task <ActionResult <CommandResult <Cliente> > > Post([FromBody] CadastrarClienteCommand command) { var response = await _mediator.Send(command); if (response.Sucesso) { return(Ok(response)); } return(BadRequest(response)); }
public async Task <object> CadastrarCliente(string cpf, string nomeCompleto, DateTime dataNascimento, string email, string telefoneFixo, string telefoneCelular, Guid?consultorId, long?inssNumeroBeneficio, double?inssSalario, int?inssEspecie, int?outrosDiaPagamento) { var cadastrarClienteCommand = new CadastrarClienteCommand(cpf, nomeCompleto, dataNascimento, email, telefoneFixo, telefoneCelular, consultorId, inssNumeroBeneficio, inssSalario, inssEspecie, outrosDiaPagamento); var cadastrarClienteResponse = await _bus.SendCommand(cadastrarClienteCommand); return(_notifications.HasNotifications() ? cadastrarClienteResponse : _mapper.Map <ClienteViewModel>((Cliente)cadastrarClienteResponse)); }
public async Task <IActionResult> CadastrarCliente([FromBody] CadastrarClienteCommand command) { var cliente = await _clienteAppService.CadastrarCliente(command); if (cliente == null) { return(BadRequest("Erro ao cadastrar cliente.")); } return(Created(string.Empty, cliente)); }
public async Task <IActionResult> CriarClienteAsync([FromBody] CadastrarClienteCommand command) { var result = await _commandCadastrarCliente.Handle(command).ConfigureAwait(true) as CommandResult; if (result.Success) { return(Ok()); } else { return(UnprocessableEntity()); } }
public Task <CommandResult <Cliente> > Handle(CadastrarClienteCommand request, CancellationToken cancellationToken) { var response = new CommandResult <Cliente>("Salvo com sucesso", true, null); request.Validate(); if (request.Valid) { Nome nome = new Nome(request.PrimeiroNome, request.SegundoNome); Documento documentocliente = null; // validar tipo de pessoa switch (request.TipoPessoa) { case ETipoPessoa.Fisica: documentocliente = new Documento(request.Documento, ETipoDocumento.Cpf); break; case ETipoPessoa.Juridica: documentocliente = new Documento(request.Documento, ETipoDocumento.Cnpj); break; } // validar se tipo de documento foi definido if (!(documentocliente == null)) { Cliente cliente = new Cliente(nome, request.TipoPessoa, documentocliente, request.Rg); if (cliente.Valid) { var xx = _clienteRepositorio.GetList(x => x.TipoPessoa == ETipoPessoa.Fisica); if (_clienteRepositorio.ExisteCliente(cliente)) { response.Sucesso = false; response.Mensagem = "Cliente já foi cadastrado com esse documento."; return(Task.FromResult(response)); } if (_clienteRepositorio.Insert(ref cliente)) { response.ObjetoResposta = cliente; return(Task.FromResult(response)); } } response.Notificacoes.AddRange(cliente.Notifications.Select(x => x.Message).ToList()); } AddNotification("TipoPessoa", "Tipo de documento relátivo ao cliente não foi informado."); } response.Notificacoes.AddRange(request.Notifications.Select(x => x.Message).ToList()); response.Sucesso = false; response.Mensagem = "Não foi possível cadastrar cliente."; return(Task.FromResult(response)); }
public async Task <IActionResult> Post([FromBody] CadastrarClienteCommand command) { command.Validate(); if (command.Invalid) { return(BadRequest(JsonConvert.SerializeObject(command.Notifications, Formatting.Indented))); } var response = await _mediator.Send(command); if (!response.Success) { return(BadRequest(response.Message)); } return(CreatedAtAction(nameof(GetClientePorId), new { id = response.ResourceId }, Guid.Parse(response.ResourceId))); }
public async ValueTask <ICommandResult> Handle(CadastrarClienteCommand command) { if (!command.Validate()) { AddNotifications(command); return(new CommandResult(false, base.Notifications)); } var entity = new Cliente(command.Nome, command.Identidade, command.Email, command.DataNascimento, command.CPF); await _clienteRepository.Add(entity); var result = await _clienteRepository.SaveChanges().ConfigureAwait(true); if (!result) { return(new CommandResult(false)); } return(new CommandResult(true)); }
public CommandResult Handle(CadastrarClienteCommand command) { var nome = new Nome(command.PrimeiroNome, command.UltimoNome); var cpf = new Documento(command.CPF, EDocumentoTipo.CPF); var endereco = new Endereco(command.Logradouro, command.Numero, command.Bairro, command.Cidade, command.Estado, command.CEP); var email = new Email(command.Email); var nascimento = new Nascimento(command.Nascimento); AddNotifications(nome, cpf, endereco, email, nascimento); if (this.Invalid) { return(new CommandResult(this.Notifications, command)); } var cliente = new Cliente(nome, cpf, endereco, email, nascimento); clienteRepository.CadastrarCliente(cliente); return(new CommandResult(true, "", cliente)); }
public async Task <ClienteCadastroVM> CadastrarCliente(CadastrarClienteCommand cadastrarClienteCommand) { var telefone = new Telefone(cadastrarClienteCommand.DDI, cadastrarClienteCommand.DDD, cadastrarClienteCommand.NumeroTelefone, true); var endereco = new Endereco( cadastrarClienteCommand.CEP, cadastrarClienteCommand.Logradouro, cadastrarClienteCommand.NumeroEndereco, cadastrarClienteCommand.Complemento, true); var pessoa = new Pessoa(cadastrarClienteCommand.Nome, cadastrarClienteCommand.CPF, cadastrarClienteCommand.DataNascimento, telefone, endereco); var cliente = new Cliente(cadastrarClienteCommand.TipoClienteId, EStatusCliente.Ativo.Id, pessoa); await _clienteService.CadastrarCliente(cliente); _ = _clienteQueryRepository.Adicionar(new ClienteDocument(cliente)); var integrationEvent = new ClienteCriadoIntegrationEvent(cliente.Id, cliente.Pessoa.CPF, cliente.Pessoa.Nome); _ = _clienteIntegrationEventService.PublishEventsThroughEventBusAsync(integrationEvent); return(_mapper.Map <ClienteCadastroVM>(cliente)); }
public async Task <ActionResult> Post(CadastrarClienteCommand command) { return(RespostaCasoDeUso(await _mediator.Send(command))); }
public static Cliente ToCliente(CadastrarClienteCommand command) => Cliente.Factory.CriarNovoCliente(command.Id, command.NomeCompleto, command.Cpf, command.DataNascimento, command.Email, command.Telefone, command.Senha, command.DataHoraCriacao);
public static ClienteCadastradoEvent ToClienteCadastradoEvent(CadastrarClienteCommand command) => new ClienteCadastradoEvent(command.Id);
public async Task <object> Handle(CadastrarClienteCommand message, CancellationToken cancellationToken) { if (!message.IsValid()) { NotifyValidationErrors(message); return(await Task.FromResult(false)); } try { var client = _httpAppService.CreateClient(_serviceManager.UrlVileve); var token = await _httpAppService.OnPost <Token, object>(client, message.RequestId, "v1/auth/login", new { usuario = _serviceManager.UserVileve, senha = _serviceManager.PasswordVileve }); if (token == null || string.IsNullOrWhiteSpace(token.AccessToken)) { await _bus.RaiseEvent(new DomainNotification(message.MessageType, "Usuário de integração não encontrado.", message)); return(await Task.FromResult(false)); } client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken); var enviarTokenSms = await _httpAppService.OnPost <EnviarTokenSms, object>(client, message.RequestId, "v1/validacao-contato/enviar-token-sms", new { numero_telefone = message.TelefoneCelular }); if (enviarTokenSms.Sucesso.Equals(false)) { await _bus.RaiseEvent(new DomainNotification(message.MessageType, "O sistema está momentaneamente indisponível, tente novamente mais tarde.", message)); return(await Task.FromResult(false)); } } catch (Exception e) { _logger.Log(LogLevel.Error, e, JsonSerializer.Serialize(new { message.RequestId, e.Message })); await _bus.RaiseEvent(new DomainNotification(message.MessageType, "O sistema está momentaneamente indisponível, tente novamente mais tarde.", message)); return(await Task.FromResult(false)); } var cliente = new Cliente(Guid.NewGuid(), message.Cpf, message.NomeCompleto, message.DataNascimento, message.Email, message.TelefoneFixo, message.TelefoneCelular, message.ConsultorId); _clienteRepository.Add(cliente); var clienteFontePagadora = new ClienteFontePagadora(Guid.NewGuid(), message.InssNumeroBeneficio, message.InssSalario, message.InssEspecie, message.OutrosDiaPagamento, cliente.Id); _clienteFontePagadoraRepository.Add(clienteFontePagadora); if (Commit()) { } return(await Task.FromResult(cliente)); }