Beispiel #1
0
        public bool BuyProduct(int productId)
        {
            double productPrice = productRepository.GetProductPriceByKey(productId);

            if (payment.IsValid() && payment.IsEnough(productPrice))
            {
                productRepository.DecreaseProductQuantity(productId);
                payment.Pay(productPrice);
                dataStorage.PersistData(GetProducts());
                transactionService.AddTransition("BUY", productId);
                return(true);
            }
            return(false);
        }