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)); }
public void Adicionar(Core.Domain.Entities.Client client) { _context.Clients.Add(client); }