示例#1
0
 public ShoppingCartService(IProductService productService, IDeliveryCostCalculatorService deliveryCostCalculatorService, ICampaignService campaignService)
 {
     ProductService = productService;
     DeliveryCostCalculatorService = deliveryCostCalculatorService;
     CampaignService = campaignService;
     cart            = new Models.ShoppingCart();
 }
示例#2
0
        public double CalculateDeliveryCost(Models.ShoppingCart cart)
        {
            if (!cart.Items.Any())
            {
                return(0);
            }

            var numberOfDeliveries = cart.Items.Select(i => i.Product.CategoryTitle).Distinct().Count();
            var numberOfProducts   = cart.Items.Select(i => i.Product.Title).Distinct().Count();

            return((numberOfDeliveries * CostPerDelivery) + (numberOfProducts * CostPerProduct) + FixedCost);
        }