public override Task <CommandResult> Add(ClienteViewModel viewModel)
        {
            var command = new AddClienteCommand(viewModel.Nome, viewModel.Tipo, viewModel.Pontuacao, viewModel.Descricao);

            command.AttachContato(viewModel.ContatoCelular, viewModel.ContatoEmail, viewModel.ContatoTelefoneComercial, viewModel.ContatoTelefoneResidencial, viewModel.ContatoObservacao);
            command.AttachEndereco(viewModel.EnderecoNumero, viewModel.EnderecoRua, viewModel.EnderecoBairro, viewModel.EnderecoComplemento, viewModel.EnderecoCidadeId, viewModel.EnderecoCEP);
            command.AttachDocumento(viewModel.DocumentoCadastroNacional, viewModel.DocumentoCadastroEstadual);

            return(_mediator.SendCommand(command));
        }
        public Task <CommandResult> Handle(AddClienteCommand command, CancellationToken cancellationToken)
        {
            if (!command.IsValid())
            {
                NotifyCommandErrors(command);
                return(Response());
            }

            Cidade    cidade    = _cidadeRepository.GetById(command.EnderecoCidadeId);
            Contato   contato   = new Contato(command.ContatoCelular, command.ContatoEmail, command.ContatoTelefoneComercial, command.ContatoTelefoneResidencial, command.ContatoObservacao);
            Endereco  endereco  = new Endereco(command.EnderecoRua, command.EnderecoNumero, command.EnderecoBairro, command.EnderecoComplemento, cidade, command.EnderecoCEP);
            Documento documento = new Documento(command.DocumentoCadastroNacional, command.DocumentoCadastroEstadual);
            Cliente   cliente   = new Cliente(command.Nome, command.Tipo, command.Pontuacao, documento, contato, endereco, command.Descricao);

            _clienteRepository.Add(cliente);

            if (Commit())
            {
                _mediator.PublishEvent(new AddedClienteEvent(cliente));
            }

            return(Response());
        }
Beispiel #3
0
        public async Task <IActionResult> Post([FromBody] AddClienteCommand command)
        {
            await _clienteServiceApp.Add(command);

            return(Response());
        }
Beispiel #4
0
        public async Task <bool> Add(AddClienteCommand command)
        {
            await _mediator.SendCommand(command);

            return(!_mediator.HasNotification());
        }