public int CalculateBasketPrice(AggregateProduct products)
        {
            // find offer with greater total.
            var prefredSpecial = products.Specials.FirstOrDefault(x => x.Total == products.Specials.Max(e => e.Total));

            // to remove overlap between specials and our baseket.
            foreach (var item in prefredSpecial.Products)
            {
                var current = products.Products.FirstOrDefault(x => x.Name == item.Name);

                // assume we use greater special even we can't use all of them.
                if (current.Quantity < item.Quantity)
                {
                    current.Quantity = 0;
                }

                current.Quantity -= item.Quantity;
            }

            // calculate basket price without specials.
            int basketPrice = products.Products.Sum(x => x.Quantity * x.Price);

            // sum basket price and specials as result.
            int result = basketPrice + prefredSpecial.Total;

            return(result);
        }
 public int Calculate(AggregateProduct products)
 {
     return(_basketService.CalculateBasketPrice(products));
 }
示例#3
0
 public static AggregateProduct CreateAggregateProduct(global::System.Guid ID)
 {
     AggregateProduct aggregateProduct = new AggregateProduct();
     aggregateProduct.Id = ID;
     return aggregateProduct;
 }
示例#4
0
 public void AddToProducts(AggregateProduct aggregateProduct)
 {
     base.AddObject("Products", aggregateProduct);
 }