public void Handle(AddProductCommand command)
        {
            //Chama a implementação do Caso de Uso que está
            //no Building Block de serviço
            _productService.AddProduct(command.Product);

            _bus.Enqueue <ProductAddedEvent>(new ProductAddedEvent {
                Product = command.Product
            }, ProductAddedEvent.EventQueueName);
        }
Ejemplo n.º 2
0
        public ICommandResult Handle(CreateBooksCommand command)
        {
            //FAIL FAST VALIDATION
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult(false, "An error occurred while saving the requested record", command.Notifications));
            }

            var book = _mapper.Map <CreateBooksCommand, Books>(command);

            //Save the base
            _bookRepository.Create(book);

            //Send message to queue
            _bus.Enqueue(command, CreateBooksCommand.QueueName);

            return(new GenericCommandResult(true, $"The Book {book.Title} was save with success", book));
        }
Ejemplo n.º 3
0
        public ICommandResult Handle(CreateAuthorCommand command)
        {
            //FAIL FAST VALIDATION
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult(false, "An error occurred while saving the requested record", command.Notifications));
            }

            var author = _mapper.Map <CreateAuthorCommand, Author>(command);

            //Save the Database
            _authorRepository.Create(author);

            //Send message to queue
            _bus.Enqueue(command, CreateAuthorCommand.QueueName);

            //Cache
            var key = key_author.Replace("{id}", author.Id.ToString());

            _cache.Save(command, key);

            return(new GenericCommandResult(true, $"The Author {author.Name} was save with success", author));
        }
 //############## COMMANDS ################
 public void AddProduct(Product product)
 {
     _bus.Enqueue <AddProductCommand>(new AddProductCommand {
         Product = product
     }, AddProductCommand.CommandQueueName);
 }