public bool isValidRepConstraint(List<basketItem> basketContent, tbl_discount item)
 {
     // ToDo : Discount Rep With Order
     return true;
 }
        private discountItem getDiscountSummaryByDiscountItem(tbl_discount discountItem, List<basketItem> basketContent)
        {
            discountItem helperItem = new discountItem();

            helperItem.name = discountItem.code;
            helperItem.description = discountItem.description;
            helperItem.discountId = discountItem.discountId;

            List<int> productIdList = new List<int>();
            decimal discountAmount = 0;
            decimal totalPrice = basketContent.Sum(a => a.productTotalPriceDec);

            switch (((discountType)discountItem.typeId))
            {
                case discountType.basketPercent:

                    discountAmount = totalPrice * (discountItem.amountPercent / 100);

                    break;
                case discountType.basketAmount:

                    discountAmount = discountItem.amountPercent;
                    break;

                case discountType.productPercent:

                    productIdList = getProductIdListByDiscountItem(discountItem);

                    foreach (var item in basketContent)
                    {
                        if (productIdList.Contains(item.productId))
                        {
                            discountAmount = discountAmount + (item.productTotalPriceDec * (discountItem.amountPercent / 100));
                        }
                    }

                    break;

                case discountType.productAmount:

                    productIdList = getProductIdListByDiscountItem(discountItem);

                    foreach (var item in basketContent)
                    {
                        if (productIdList.Contains(item.productId))
                        {
                            discountAmount = discountAmount + item.productTotalPriceDec;
                        }
                    }
                    break;

            }

            helperItem.discountAmount = Math.Round(discountAmount, 2, MidpointRounding.AwayFromZero);

            return helperItem;
        }
 public bool isValidMinimumSpent(List<basketItem> basketContent, tbl_discount item)
 {
     var totalSpent = basketContent.Sum(a => a.productTotalPriceDec);
     return (totalSpent > item.minBasketAmount);
 }
        public bool isValidProductConstraint(List<basketItem> basketContent, tbl_discount item)
        {
            if (string.IsNullOrWhiteSpace(item.productList) && string.IsNullOrWhiteSpace(item.exculudeProductList))
            {
                return true;
            }

            var productIdList = getProductIdListByDiscountItem(item);

            var discountTypeItem = ((discountType)item.typeId);

            if (discountTypeItem == discountType.basketAmount || discountTypeItem == discountType.basketPercent)
            {
                return basketContent.Select(a => a.productId).All(a => productIdList.Contains(a));
            }

            if (discountTypeItem == discountType.productAmount || discountTypeItem == discountType.productPercent)
            {
                return basketContent.Select(a => a.productId).Any(a => productIdList.Contains(a));
            }

            return false;
        }
 public bool isValidBasketCount(List<basketItem> basketContent, tbl_discount item)
 {
     var totalCount = basketContent.Sum(a => a.quantity);
     return (totalCount > item.minBasketCount);
 }
 public bool isUserValid(tbl_discount item, int? userId)
 {
     if (item.userId == 0)
     {
         return true;
     }
     else
     {
         if (userId.HasValue && item.userId == userId.Value)
         {
             return true;
         }
         else
         {
             return false;
         }
     }
 }
 public bool isDateValid(tbl_discount item)
 {
     if (item.startDate <= DateTime.Now && DateTime.Now <= item.endDate)
     {
         return true;
     }
     else
     {
         return false;
     }
 }
 public bool isAllreadyUse(List<basketItem> basketContent, tbl_discount item)
 {
     return basketContent.Any(a => a.discountCode != null && a.discountCode.Split(',').ToList().Contains(item.code.Trim()));
 }
        public List<int> getProductIdListByDiscountItem(tbl_discount item)
        {
            if (!string.IsNullOrWhiteSpace(item.productList))
            {
                var strProductIdList = item.productList.Split(',').ToList();
                var productIdList = strProductIdList.Select(int.Parse).ToList();

                if (!string.IsNullOrWhiteSpace(item.exculudeProductList))
                {
                    var strExcludeProductIdList = item.exculudeProductList.Split(',').ToList();
                    var excludeProductIdList = strExcludeProductIdList.Select(int.Parse).ToList();

                    List<int> filterList = new List<int>();

                    foreach (var productId in productIdList)
                    {
                        if (!excludeProductIdList.Contains(productId))
                        {
                            filterList.Add(productId);
                        }
                    }

                    return filterList;
                }
                else
                {
                    return productIdList;
                }
            }
            else
            {
                var productIdList = db.tbl_product.Select(a => a.productId).ToList();

                if (!string.IsNullOrWhiteSpace(item.exculudeProductList))
                {
                    var strExcludeProductIdList = item.exculudeProductList.Split(',').ToList();
                    var excludeProductIdList = strExcludeProductIdList.Select(int.Parse).ToList();

                    List<int> filterList = new List<int>();

                    foreach (var productId in productIdList)
                    {
                        if (!excludeProductIdList.Contains(productId))
                        {
                            filterList.Add(productId);
                        }
                    }

                    return filterList;
                }
                else
                {
                    return productIdList;
                }
            }
        }