コード例 #1
0
        public async Task <ValidationResult> Handle(RegisterClientCommand message, CancellationToken cancellationToken)
        {
            if (!message.IsValid())
            {
                return(message.ValidationResult);
            }

            var client = new Core.Domain.Entities.Client(message.Id, message.Name, message.Email, message.CPF);

            var clientExists = await _repository.GetByCPF(client.CPF.Numero);

            if (clientExists != null)
            {
                AdicionarErro("Este CPF já está em uso.");
                return(ValidationResult);
            }

            _repository.Adicionar(client);

            client.AddEvent(new RegisteredClientEvent(message.Id, message.Name, message.Email, message.CPF));

            return(await PersistData(_repository.UnitOfWork));
        }
コード例 #2
0
 public void Adicionar(Core.Domain.Entities.Client client)
 {
     _context.Clients.Add(client);
 }