Beispiel #1
0
        public Telefone(CriarTelefoneCommand criarTelefoneCommand)
        {
            ValidarPropriedades(criarTelefoneCommand.DDD, criarTelefoneCommand.Numero);

            DDD    = criarTelefoneCommand.DDD;
            Numero = criarTelefoneCommand.Numero;
        }
        public void AdicionarTelefone(decimal cpfCliente, CriarTelefoneCommand criarTelefoneCommand)
        {
            ValidacaoLogica.IsTrue <ValidacaoException>(criarTelefoneCommand is null, "Comando de alteração de telefone não pode ser nulo.");

            var cliente = clientesRepository.ObterUm(x => x.Cpf == cpfCliente);

            ValidacaoLogica.IsTrue <RecursoNaoEncontradoException>(cliente is null, "Cliente não encontrado.");

            if (cliente.Telefones is null)
            {
                cliente.Telefones = new List <Telefone>();
            }

            cliente.Telefones.Add(new Telefone(criarTelefoneCommand));

            clientesRepository.Atualizar(cliente);

            unitOfWork.SaveChanges();
        }
Beispiel #3
0
        public async Task <ICommandResult> Handle(CriarTelefoneCommand command, CancellationToken cancellationToken)
        {
            if (command.Invalid)
            {
                return(new CommandResult(false, "Dados Inválidos!", command.Notifications));
            }
            if (await _clienteRepository.PossuiTelefone(command.IdCliente, command.Numero))
            {
                AddNotification("Telefone.Numero", "O Cliente já possui este telefone");
                return(new CommandResult(false, "Dados Inválidos!", Notifications));
            }
            Telefone telefone = new Telefone(command.IdCliente, command.Numero);

            if (telefone.Invalid)
            {
                return(new CommandResult(false, "Dados Inválidos!", telefone.Notifications));
            }

            await _telefoneRepository.AddAsync(telefone);

            return(new CommandResult(true, $"O telefone {command.Numero} foi criado com sucesso!"));
        }
Beispiel #4
0
 public static Telefone Create(CriarTelefoneCommand command, CriarTelefoneValidation validator)
 {
     validator.ValidateCommand(command);
     return(new Telefone(command));
 }
Beispiel #5
0
 protected Telefone(CriarTelefoneCommand command) : base(command.ID)
 {
     DDD    = command.DDD;
     Numero = command.Number;
 }
Beispiel #6
0
 public void AdicionarTelefone(decimal cpf, CriarTelefoneCommand criarTelefoneCommand)
 {
     telefonesAppService.AdicionarTelefone(cpf, criarTelefoneCommand);
 }
Beispiel #7
0
        public async Task <IActionResult> AddTelefone([FromRoute] Guid id, [FromBody] string numero)
        {
            var command = new CriarTelefoneCommand(id, numero);

            return(Ok(await _mediator.Send(command)));
        }