Example #1
0
        public void AddPromotionHandler_price_invalid()
        {
            var repository = new FakeProductRepository();
            var handler    = new ProductHandler(repository);

            var command = new ProductPromotionCommand();

            command.Id    = repository.GetAll().FirstOrDefault().Id;
            command.Price = 11.5m;

            var result = handler.Handle(command);

            Assert.False(result.Success, result.Message);
        }
        public CommandResult AddPromotion(ProductPromotionCommand command)
        {
            var product = _repository.GetById(command.Id);

            if (product == null)
            {
                return(new CommandResult(false, "Produto não encontrado na base de dados. ", null));
            }

            product.AddPromotion(command.Price);

            AddNotifications(product);
            if (Invalid)
            {
                return(new CommandResult(false, GroupNotifications.Group(Notifications), null));
            }

            _repository.Update(product);

            return(new CommandResult(true, "Preço do Produto atualizado com sucesso! ", product));
        }
        public CommandResult AddPromotion(string id, ProductPromotionCommand command)
        {
            var result = _handler.Handle(command);

            return(result);
        }