Пример #1
0
        public void Handle(RegistrarEditoraCommand message)
        {
            var editora = new Editora(message.Id, message.Nome, message.CNPJ, message.Email);

            if (!editora.EhValido())
            {
                NotificarValidacoesErro(editora.ValidationResult);
                return;
            }

            var editoraExistente = _editoraRepository.Buscar(o => o.CNPJ == editora.CNPJ || o.Email == editora.Email);

            if (editoraExistente.Any())
            {
                _bus.RaiseEvent(new DomainNotification(message.MessageType, "CPF ou e-mail já utilizados"));
            }

            _editoraRepository.Adicionar(editora);

            if (Commit())
            {
                _bus.RaiseEvent(new EditoraRegistradoEvent(editora.Id, editora.Nome, editora.CNPJ, editora.Email));
            }
        }