示例#1
0
        // Validates total cart discount percent and then calls CalcCartDiscountAmount to update the view
        public void ApplyCartDiscount(string value, AdjustTypeEnum adjustType, IEnumerable <Cart> cartItems,
                                      Customer customer)
        {
            // Checking for any alpha characters
            bool containsLetters = value.Any(x => !char.IsLetter(x));

            // If none convert to double and pass to calc whole cart discount
            if (containsLetters)
            {
                var convertValue = Convert.ToDouble(value);

                if (adjustType == AdjustTypeEnum.Percent)
                {
                    foreach (var cartItem in cartItems)
                    {
                        cartItem.Discounted      = true;
                        cartItem.DiscountPercent = convertValue;
                        CalcCartItemDiscount(cartItem);
                    }
                }
                else if (adjustType == AdjustTypeEnum.Amount)
                {
                }

                CalcTotal(customer);
            }
            else
            {
                //TODO :: Inform that no alphabetical characters are allowed
                Console.WriteLine("Not allowed character in the discount field");
            }
        }
示例#2
0
        // Validates indv cart item percent and calls CalcCartItemDiscount to update view
        public void ApplyIndvItemDiscount(Cart value, object percent, AdjustTypeEnum adjustType)
        {
            // Checking for any alpha characters
            bool containsLetters = percent.ToString().Any(x => !char.IsLetter(x));

            // If no alpha calc indv item discounted value
            if (containsLetters)
            {
                var discountValue = Convert.ToDouble(percent);

                if (adjustType == AdjustTypeEnum.Percent)
                {
                    if (value.DiscountPercent >= 0)
                    {
                        value.DiscountPercent       = discountValue;
                        value.PercentDiscountedBool = true;
                        value.Discounted            = true;
                        CalcCartItemDiscount(value);
                    }
                }
                else if (adjustType == AdjustTypeEnum.Amount)
                {
                    if (value.DiscountAmount >= 0)
                    {
                        value.DiscountAmount       = discountValue;
                        value.AmountDiscountedBool = true;
                        value.Discounted           = true;
                        CalcCartItemDiscount(value);
                    }
                }
            }
            else
            {
                Console.WriteLine("Not allowed character in the discount field");
            }
        }