Beispiel #1
0
        /// <summary>
        /// Validates the constraint against the <see cref="ILineItemContainer"/>
        /// </summary>
        /// <param name="value">
        /// The value to object to which the constraint is to be applied.
        /// </param>
        /// <param name="customer">
        /// The <see cref="ICustomerBase"/>.
        /// </param>
        /// <returns>
        /// The <see cref="Attempt{ILineItemContainer}"/> indicating whether or not the constraint can be enforced.
        /// </returns>
        public override Attempt <ILineItemContainer> TryApply(ILineItemContainer value, ICustomerBase customer)
        {
            if (Quantity <= 0)
            {
                return(Attempt <ILineItemContainer> .Succeed(value));
            }

            var total = value.Items.Sum(x => x.Quantity);

            return(StringOperatorHelper.Evaluate(total, Quantity, Operator) ?
                   this.Success(value) :
                   this.Fail(value, "The total quantity of items failed to pass the configured condition."));
        }
Beispiel #2
0
 /// <summary>
 /// Visits the line items to apply expression.
 /// </summary>
 /// <param name="lineItem">
 /// The line item.
 /// </param>
 public void Visit(ILineItem lineItem)
 {
     if (lineItem.LineItemType == LineItemType.Product)
     {
         if (StringOperatorHelper.Evaluate(
                 _property == "price" ? lineItem.TotalPrice : lineItem.Quantity,
                 _target,
                 this._operator))
         {
             FilteredLineItems.Add(lineItem);
         }
     }
     else
     {
         FilteredLineItems.Add(lineItem);
     }
 }