public int DaysToKeep(ProduceItem produceItem)
 {
     // could be replaced with binary search for better performance
     return(Values
            .Where(product => product.Has(produceItem.ProductCode))
            .Select(product => product.DaysToKeep).FirstOrDefault());
 }
        public double SellingPriceOf(ProduceItem produceItem)
        {
            if (produceItem.UnitPrice == 0.0)
            {
                return(0);
            }

            var markup = MarkupOf(produceItem);

            if (isPremiumSupplier(produceItem))
            {
                markup += _premiumSupplierMarkup;
            }

            var price = Math.Round(produceItem.UnitPrice * markup, 2);

            if (isTroubleSupplier(produceItem))
            {
                price -= _troubleSupplierDiscountInRands;
            }
            if (isPremiumSupplier(produceItem))
            {
                price = Math.Ceiling(price);
            }

            return(price);
        }
 public double MarkupOf(ProduceItem produceItem)
 {
     // could be replaced with binary search for better performance
     return(1 + Values
            .Where(product => product.Has(produceItem.ProductCode))
            .Select(product => product.Markup).FirstOrDefault());
 }
        public DateTime SellByDateOf(ProduceItem produceItem)
        {
            var sellBy = produceItem.DeliveryDate.AddDays(DaysToKeep(produceItem));

            if (isTroubleSupplier(produceItem))
            {
                sellBy = sellBy.AddDays(-3);
            }

            return(sellBy);
        }
 private bool isTroubleSupplier(ProduceItem produceItem)
 {
     return(_troubleSuppliers.Contains(produceItem.SupplierId));
 }
 private bool isPremiumSupplier(ProduceItem produceItem)
 {
     return(_premiumSuppliers.Contains(produceItem.SupplierId));
 }