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)); }
public static AggregateProduct CreateAggregateProduct(global::System.Guid ID) { AggregateProduct aggregateProduct = new AggregateProduct(); aggregateProduct.Id = ID; return aggregateProduct; }
public void AddToProducts(AggregateProduct aggregateProduct) { base.AddObject("Products", aggregateProduct); }