public ProductCart CalculateCartAmount(ProductCart cart) { decimal total = default; var items = cart.Items.Where(x => x.Product.SKU == PromotedProductSku).ToList(); var totalQuantityToProcess = items.Sum(x => x.Quantity); if (items != null && totalQuantityToProcess >= PromotionQuantity) { var numberOfSets = (int)Math.Floor((decimal)totalQuantityToProcess / PromotionQuantity); total = numberOfSets * PromotionAmount; int processedProductCount = (numberOfSets * PromotionQuantity); var unprocessedQuantity = totalQuantityToProcess - processedProductCount; total += unprocessedQuantity * items.FirstOrDefault().Product.Price; return(new ProductCart(cart.Items.Except(items).ToList(), cart.Total + total)); } return(cart); }
public ProductCart CalculateCartAmount(ProductCart cart) { throw new NotImplementedException(); }