Exemple #1
0
        public decimal GetSum(IDiscountProduct discount, List <IProduct> products)
        {
            var             allowProductTypes = discount.GetAllowProductTypes();
            var             denyProductTypes  = discount.GetDenyProductTypes();
            List <IProduct> discountProducts  = new List <IProduct>();

            _allowProductTypes = new List <ProductType>(allowProductTypes);
            decimal sum = 0;

            foreach (var product in products)
            {
                if (_allowProductTypes.Contains(product.Type) && !denyProductTypes.Contains(product.Type) && !product.IsCalculate)
                {
                    _allowProductTypes.Remove(product.Type);
                    sum += product.Price;
                    discountProducts.Add(product);
                    if (_allowProductTypes.Count == 0)
                    {
                        break;
                    }
                }
            }
            if (_allowProductTypes.Count == 0)
            {
                foreach (var product in discountProducts)
                {
                    product.IsCalculate = true;
                }

                return(sum * (1 - discount.GetDiscount() / 100));
            }
            return(0);
        }
        public decimal GetSum(IDiscountProduct discount, List <IProduct> products)
        {
            var             denyProductTypes = discount.GetDenyProductTypes();
            decimal         sum = 0;
            List <IProduct> discountProducts = new List <IProduct>();

            foreach (var product in products)
            {
                if (!denyProductTypes.Contains(product.Type) && !product.IsCalculate)
                {
                    sum += product.Price;
                    discountProducts.Add(product);
                }
            }
            if (discountProducts.Count == COUNT)
            {
                foreach (var product in discountProducts)
                {
                    product.IsCalculate = true;
                }

                return(sum * (1 - discount.GetDiscount() / 100));
            }
            return(0);
        }
        public decimal GetSum(IDiscountProduct discount, List <IProduct> products)
        {
            var             denyProductTypes = discount.GetDenyProductTypes();
            List <IProduct> discountProducts = new List <IProduct>();
            decimal         sum     = 0;
            var             thisDay = DateTime.Today;

            foreach (var product in products)
            {
                if (discount.GetBirthdayOfBuyer() == thisDay && (!denyProductTypes.Contains(product.Type) && !product.IsCalculate))
                {
                    sum += product.Price;
                    discountProducts.Add(product);
                }
            }

            foreach (var product in discountProducts)
            {
                product.IsCalculate = true;
            }

            return(sum * (1 - discount.GetDiscount() / 100));
        }