//--------------------------------------------------------
        public decimal ComputeBuyQuantityDiscount( PricingRule pr, ShoppingCartItem scItem)
        {
            int discountCount = 0;
            decimal discount = 0;
            int discountMuliplier = 1;
            if ((pr != null) && scItem != null && (scItem.Quantity > 0) &&
                (   (pr.DiscountRuleEnumType == DiscountRuleEnum.BuyOneGetFree) ||
                    (pr.DiscountRuleEnumType == DiscountRuleEnum.BuyQuantityGetFree) ||
                    (pr.DiscountRuleEnumType == DiscountRuleEnum.BuyOneGetDiscount) ||
                    (pr.DiscountRuleEnumType == DiscountRuleEnum.BuyQuantityGetDiscount)
                )
               )
            {
                int tempMultiplier = (int)scItem.Quantity / (int)(pr.BuyQuantity + pr.DiscountQuantity);
                discountMuliplier = (tempMultiplier == 0) ? 1 : tempMultiplier;

                int tempCount = (int)(scItem.Quantity - pr.BuyQuantity);
                if(pr.DiscountQuantity > 0)
                    discountCount = tempCount > (int)pr.DiscountQuantity ? (int)pr.DiscountQuantity : tempCount;

                if (discountCount > 0)
                    discount = (decimal)(scItem.Product.Price * (pr.DiscountPercent) * discountCount * discountMuliplier)/100;
            }
            else if ((pr != null) && (pr.DiscountRuleEnumType == DiscountRuleEnum.DiscountPercent))
                discount = discount + (decimal)(scItem.Product.Price * pr.DiscountPercent/100);
            //else if ((pr != null) && (pr.DiscountRuleEnumType == DiscountRuleEnum.DiscountedAmount))
                //discount = discount + (decimal)pr.DiscountedAmount;

            return discount;
        }
        public ShoppingCartVM()
        {
            Invoice = new Invoice() { };
            PricingRule = new PricingRule();
            ShoppingCartItem = new ShoppingCartItem();

            ProductList = new List<Product>() { };
            ShoppingCartPricingRuleList = new List<PricingRule>() { };
            CartItemList = new List<ShoppingCartItem>() { };
        }
 //
 // GET: /PricingRule/Create
 public ActionResult Create()
 {
     PricingRule pr = new PricingRule();
     IEnumerable<DiscountRuleEnum> enumTypeList = Enum.GetValues(typeof(DiscountRuleEnum)).Cast<DiscountRuleEnum>();
     pr.DiscountRuleEnumTypeSelectList = from s in enumTypeList
                                             select new SelectListItem
                                             {
                                                 Text = s.ToString(),
                                                 Value = ((int)s).ToString()
                                             };
     return View(pr);
 }
 public ActionResult Create(PricingRule pr)
 {
     try
     {
         if (ModelState.IsValid)
         {
             pr.Name = pr.DiscountRuleEnumType.ToString();
             db.PricingRules.Add(pr);
             db.SaveChanges();
         }
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
Beispiel #5
0
        public ShoppingCartVM()
        {
            Invoice = new Invoice()
            {
            };
            PricingRule      = new PricingRule();
            ShoppingCartItem = new ShoppingCartItem();

            ProductList = new List <Product>()
            {
            };
            ShoppingCartPricingRuleList = new List <PricingRule>()
            {
            };
            CartItemList = new List <ShoppingCartItem>()
            {
            };
        }
 //--------------------------------------------------------
 public bool IsValidPricingRule(PricingRule pricingRule)
 {
     DateTime now = DateTime.Now;
     if (pricingRule != null)
         return now > pricingRule.ExpDate ? true : false;
     return false;
 }