Ejemplo n.º 1
0
 public decimal HowMuch(Burger burger)
 {
     if ((ValueBurger(burger) + _discountCalculator.Calculate()) == ValueBurger(burger) / 2)
     {
         ;
     }
     {
         if (_discountCalculator.ChanceForWin() == 1)
         {
             return((ValueBurger(burger) + _discountCalculator.Calculate()) / 2);
         }
     }
     return(ValueBurger(burger) + _discountCalculator.Calculate());
 }
Ejemplo n.º 2
0
        public Domain.Offer.Offer CalculateOffer(IDiscountCalculator discountCalculator, IProductRepository productRepository)
        {
            if (_status != OrderStatus.New)
            {
                throw new NotFoundException();
            }

            List <OfferItem> availabeItems    = new List <OfferItem>();
            List <OfferItem> unavailableItems = new List <OfferItem>();

            decimal totalCost = 0;

            foreach (var orderItem in _products)
            {
                Product.Product product = productRepository.Get(orderItem.ProductId);
                if (product.Aviable)
                {
                    OfferItem offerItem = new OfferItem(product.Id, product.Name, product.Price, product.ProductType);

                    availabeItems.Add(offerItem);
                    totalCost += offerItem.Price;
                }
                else
                {
                    OfferItem offerItem = new OfferItem(product.Id, product.Name, product.Price, product.ProductType);

                    unavailableItems.Add(offerItem);
                }
            }

            decimal discount = discountCalculator.Calculate(availabeItems);

            return(new Domain.Offer.Offer(_clientId, totalCost - discount, discount, availabeItems, unavailableItems));
        }
        /// <summary>
        /// Calculate the Basket totals.
        /// </summary>
        /// <param name="basketItems">The collection of <see cref="BasketItem"/>.</param>
        /// <returns></returns>
        public BasketResult Calculate(IEnumerable <BasketItem> basketItems)
        {
            var result = new BasketResult();

            foreach (var bItem in basketItems)
            {
                var discountResult = _discountCalculator.Calculate(basketItems, bItem.ProductId);
                var baseAmount     = bItem.UnitPrice * bItem.Quantity;
                var itemResult     = new BasketItemResult
                {
                    ProductId      = bItem.ProductId,
                    BaseAmount     = baseAmount,
                    Quantity       = bItem.Quantity,
                    UnitPrice      = bItem.UnitPrice,
                    TotalAmount    = baseAmount - discountResult.TotalDiscount,
                    DiscountResult = discountResult
                };

                result.BasketItemResults.Add(itemResult);
            }

            return(result);
        }
Ejemplo n.º 4
0
 public decimal Calculate(IDiscount discounts, int categoryQuantity, decimal unitPrice)
 {
     return(_discountCalculator.Calculate(discounts, categoryQuantity, unitPrice));
 }
Ejemplo n.º 5
0
 public void ProcessOrder()
 {
     _shippingMethod.Calculate(_orders);
     _discountCalculator.Calculate(_orders);
     this.TotalCost = TotalShippingCost(_orders.ToList());
 }