Ejemplo n.º 1
0
        public Task <bool> Handle(UpdateClienteCommand message, CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                NotifyValidationErrors(message);
                return(Task.FromResult(false));
            }

            var cliente       = new Cliente(message.Id, message.Nome, message.Email, message.DataNascimento);
            var clienteExiste = _clienteRepository.GetByEmail(cliente.Email);

            if (clienteExiste != null && clienteExiste.Id != cliente.Id)
            {
                if (!clienteExiste.Equals(cliente))
                {
                    Bus.RaiseEvent(new DomainNotification(message.MessageType, "O email do cliente já foi recebido."));
                    return(Task.FromResult(false));
                }
            }

            _clienteRepository.Update(cliente);

            if (Commit())
            {
                Bus.RaiseEvent(new ClienteUpdatedEvent(cliente.Id, cliente.Nome, cliente.Email, cliente.DataNascimento));
            }

            return(Task.FromResult(true));
        }
Ejemplo n.º 2
0
        public Task Handle(UpdateClienteCommand message, CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                NotifyValidationErrors(message);
                return(Task.CompletedTask);
            }

            var cliente         = new Cliente(message.Id, message.Nome, message.Email, message.DataNascimento);
            var existingCliente = _clienteRepository.GetByEmail(cliente.Email);

            if (existingCliente != null && existingCliente.Id != cliente.Id)
            {
                if (!existingCliente.Equals(cliente))
                {
                    Bus.RaiseEvent(new DomainNotification(message.MessageType, "O e-mail do cliente ja foi obtido."));
                    return(Task.CompletedTask);
                }
            }

            _clienteRepository.Update(cliente);

            if (Commit())
            {
                Bus.RaiseEvent(new ClienteUpdatedEvent(cliente.Id, cliente.Nome, cliente.Email, cliente.DataNascimento));
            }

            return(Task.CompletedTask);
        }
 public ClienteNewControlViewModel(FacadeProvider facadeProvider, ClienteModel cliente, Action closAction) : base(facadeProvider)
 {
     SaveClienteComand   = new SaveClienteCommand(this);
     UpdateClienteComand = new UpdateClienteCommand(this);
     Cliente             = cliente;
     CloseAction         = closAction;
 }
Ejemplo n.º 4
0
        public async Task <IActionResult> Put(Guid id, [FromBody] UpdateClienteCommand command)
        {
            command.Id = id;
            await _clienteServiceApp.Update(command);

            return(Response());
        }
        private async Task <GenericCommandResult> CreateRequest(Guid id, string nome, int idade)
        {
            var handler = new UpdateClienteHandler(_repository);
            var request = new UpdateClienteCommand(id, nome, idade);
            var result  = await handler.Handle(request, CancellationToken.None);

            return(result);
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Update([FromBody] UpdateClienteCommand command)
        {
            var result = await _mediator.Send(new UpdateClienteCommand(command.Id, command.Nome, command.Idade));

            if (result.Ok)
            {
                return(Ok(result.Data));
            }
            return(BadRequest(result.Errors));
        }
        private bool CommandEstaInvalido(UpdateClienteCommand command)
        {
            if (!command.EValido())
            {
                return(true);
            }

            AddNotifications(command);
            return(false);
        }
Ejemplo n.º 8
0
        public override Task <CommandResult> Update(ClienteViewModel viewModel)
        {
            var command = new UpdateClienteCommand(viewModel.Id, 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 ICommandResult Handler(UpdateClienteCommand command)
        {
            if (CommandEstaInvalido(command))
            {
                return(new CommandResult(false, "Não foi possivel atualizar o cliente"));
            }

            var cliente = _clienteRepository.Buscar(x => x.Id == command.Id).FirstOrDefault();

            cliente.Update(command);
            AddNotifications(cliente.Notifications);

            _clienteRepository.Atualizar(cliente);

            return(new CommandResult(true, "Cliente atualizado com sucesso"));
        }
        public async Task <bool> Handle(UpdateClienteCommand request, CancellationToken cancellationToken)
        {
            if (request == null)
            {
                return(false);
            }

            var cliente = new Cliente(request.id, request.nome, request.sobrenome, request.email);
            await _repository.Update(cliente);

            await _repository.Save();

            await _mediator.Publish(new ClienteUpdateEvent(cliente.id, cliente.nome, cliente.sobrenome, cliente.email), cancellationToken);

            return(await Task.FromResult(true));
        }
Ejemplo n.º 11
0
        public Task <bool> Handle(UpdateClienteCommand message, CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                NotifyValidationErrors(message);
                return(Task.FromResult(false));
            }

            var adv = new Cliente(message.ID, message.Nome, message.Idade);

            _advRepository.Update(adv);

            if (Commit())
            {
                Bus.RaiseEvent(new ClienteUpdatedEvent(message.ID, message.Nome, message.Idade));
            }

            return(Task.FromResult(true));
        }
Ejemplo n.º 12
0
        public Task <CommandResult> Handle(UpdateClienteCommand 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.Id, command.Nome, command.Tipo, command.Pontuacao, documento, contato, endereco, command.Descricao);

            _clienteRepository.Update(cliente);

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

            return(Response());
        }
Ejemplo n.º 13
0
        public async Task <bool> Update(UpdateClienteCommand command)
        {
            await _mediator.SendCommand(command);

            return(!_mediator.HasNotification());
        }
Ejemplo n.º 14
0
        public async Task <JsonResult> OnPostUpdate(UpdateClienteCommand cliente)
        {
            var response = await Mediator.Send(cliente);

            return(new JsonResult(new { response }));
        }
Ejemplo n.º 15
0
        public async Task <IActionResult> Put(UpdateClienteCommand obj)
        {
            var clienteResponse = await _mediator.Send(obj);

            return(Ok(clienteResponse));
        }
Ejemplo n.º 16
0
        public async Task <IActionResult> Update(UpdateClienteCommand obj)
        {
            var x = await _mediator.Send(obj);

            return(Ok(x));
        }
Ejemplo n.º 17
0
        public async Task <ActionResult> AtualizarCliente([FromBody] UpdateClienteCommand command)
        {
            await _bus.Send(command);

            return(NoContent());
        }
Ejemplo n.º 18
0
 public void Update(UpdateClienteCommand command)
 {
     this.Nome      = new Nome(command.PrimeiroNome, command.UltimoNome);
     this.Email     = new Email(command.Email);
     this.Documento = new Documento(command.Cpf);
 }