Esempio n. 1
0
        public override AddProductCommand Handle(AddProductCommand addProductCommand)
        {
            Product insertedProduct;

            using (var scope = _productsDao.BeginTransaction())
            {
                insertedProduct = _productsDao.Add(
                    new Product(
                        productName: addProductCommand.ProductName,
                        productDescription: addProductCommand.ProductDescription,
                        productPrice: addProductCommand.ProductPrice)
                    );

                scope.Commit();

                addProductCommand.ProductId = insertedProduct.Id;
            }

            if (insertedProduct != null)
            {
                _commandProcessor.Publish(new ProductAddedEvent(insertedProduct.Id, insertedProduct.ProductName, insertedProduct.ProductDescription, insertedProduct.ProductPrice));
            }

            return(base.Handle(addProductCommand));
        }
Esempio n. 2
0
        public override RemoveProductCommand Handle(RemoveProductCommand removeProductCommand)
        {
            ProductReference productReference;

            using (var scope = _productsDao.BeginTransaction())
            {
                productReference = _productsDao.FindById(removeProductCommand.ProductId);
                _productsDao.Delete(removeProductCommand.ProductId);

                scope.Commit();
            }

            return(base.Handle(removeProductCommand));
        }
        public override ChangeProductCommand Handle(ChangeProductCommand changeProductCommand)
        {
            ProductReference productReference;

            using (var scope = _productsDao.BeginTransaction())
            {
                productReference                    = _productsDao.FindById(changeProductCommand.ProductId);
                productReference.ProductName        = changeProductCommand.ProductName;
                productReference.ProductDescription = changeProductCommand.ProductDescription;
                productReference.ProductPrice       = changeProductCommand.Price;

                _productsDao.Update(productReference);
                scope.Commit();
            }

            return(base.Handle(changeProductCommand));
        }
Esempio n. 4
0
        public override RemoveProductCommand Handle(RemoveProductCommand removeProductCommand)
        {
            Product product;

            using (var scope = _productsDao.BeginTransaction())
            {
                product = _productsDao.FindById(removeProductCommand.ProductId);
                _productsDao.Delete(removeProductCommand.ProductId);
            }

            if (product != null)
            {
                _commandProcessor.Publish(new ProductRemovedEvent(product.Id, product.ProductName, product.ProductDescription, product.ProductPrice));
            }

            return(base.Handle(removeProductCommand));
        }
        public override AddProductCommand Handle(AddProductCommand addProductCommand)
        {
            using (var scope = _productsDao.BeginTransaction())
            {
                ProductReference insertedProductReference = _productsDao.Add(
                    new ProductReference(
                        productId: addProductCommand.ProductId,
                        productName: addProductCommand.ProductName,
                        productDescription: addProductCommand.ProductDescription,
                        productPrice: addProductCommand.ProductPrice)
                    );

                scope.Commit();

                addProductCommand.ProductId = insertedProductReference.Id;
            }

            return(base.Handle(addProductCommand));
        }
        public override ChangeProductCommand Handle(ChangeProductCommand changeProductCommand)
        {
            Product product;

            using (var scope = _productsDao.BeginTransaction())
            {
                product                    = _productsDao.FindById(changeProductCommand.ProductId);
                product.ProductName        = changeProductCommand.ProductName;
                product.ProductDescription = changeProductCommand.ProductDescription;
                product.ProductPrice       = changeProductCommand.Price;

                _productsDao.Update(product);
                scope.Commit();
            }

            if (product != null)
            {
                _commandProcessor.Publish(new ProductChangedEvent(product.Id, product.ProductName, product.ProductDescription, product.ProductPrice));
            }

            return(base.Handle(changeProductCommand));
        }