/// <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)
        {
            var visitor = new NumericalValueFilterConstraintVisitor(this.Price, Operator, "price");

            value.Items.Accept(visitor);

            return(visitor.FilteredLineItems.Any(x => x.LineItemType == LineItemType.Product)
                       ? this.Success(CreateNewLineContainer(visitor.FilteredLineItems))
                       : this.Fail(value, "No items qualify. Quantity filter removes all items"));
        }
Exemple #2
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)
        {
            var visitor = new NumericalValueFilterConstraintVisitor(Quantity, Operator, "quantity");

            value.Items.Accept(visitor);

            return(visitor.FilteredLineItems.Any(x => x.LineItemType == LineItemType.Product)
                       ? this.Success(CreateNewLineContainer(visitor.FilteredLineItems))
                       : this.Fail(value, "No items qualify. Resulting collection would be empty."));
        }
        /// <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)
        {
            var visitor = new NumericalValueFilterConstraintVisitor(Quantity, Operator, "quantity");
            value.Items.Accept(visitor);

            return visitor.FilteredLineItems.Any(x => x.LineItemType == LineItemType.Product)
                       ? this.Success(CreateNewLineContainer(visitor.FilteredLineItems))
                       : this.Fail(value, "No items qualify. Resulting collection would be empty.");
        }
        /// <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)
        {
            var visitor = new NumericalValueFilterConstraintVisitor(this.Price, Operator, "price");
            value.Items.Accept(visitor);

            return visitor.FilteredLineItems.Any(x => x.LineItemType == LineItemType.Product)
                       ? this.Success(CreateNewLineContainer(visitor.FilteredLineItems))
                       : this.Fail(value, "No items qualify. Quantity filter removes all items");
        }