Exemple #1
0
        /// <summary>
        /// Qualifies an order based on rules you set
        /// these are simple rules - override as needed
        /// </summary>
        public virtual void ValidateUse(Order order)
        {
            if (ExpiresOn < DateTime.Now)
            {
                throw new InvalidOperationException("This coupon is Expired");
            }

            if (order.SubTotal < MininumPurchase)
            {
                throw new InvalidOperationException("There is a minimum of " + MininumPurchase.ToString("C") + " required");
            }

            if (order.Items.Count < MinimumItems)
            {
                throw new InvalidOperationException("There is a minimum of " + MinimumItems.ToString() + " items required");
            }


            if (MustHaveProducts.Length > 0)
            {
                bool haveProduct = false;

                foreach (string productCode in MustHaveProducts)
                {
                    var item = order.Items.Where(x => x.Product.ProductCode == productCode).SingleOrDefault();
                    if (item != null)
                    {
                        haveProduct = true;
                        break;
                    }
                }

                if (!haveProduct)
                {
                    throw new InvalidOperationException("This coupon is not valid for the items you've selected");
                }
            }
        }
 public bool Equals(ItemCountDescriptor other)
 => other != null && MinimumItems.Equals(other.MinimumItems) && MaximumItems.Equals(other.MaximumItems);