public override double CalculatePrice(List <CartSKU> cartSKUs, Dictionary <SKU, double> priceList)
        {
            double calcPrice = 0;
            //Assuming only one Type of SKU and Promotion can be only 1
            CartSKU cartSKU = cartSKUs.FirstOrDefault(x => x.Id == SKU.Id && x.Quantity >= MinQuantity && x.IsPromotionApplied == false);

            if (cartSKU != null)
            {
                //Promotion Appplicable
                double unitPrice = priceList[priceList.Keys.FirstOrDefault(x => x.Id == cartSKU.Id)];
                cartSKU.IsPromotionApplied = true;
                calcPrice = ((cartSKU.Quantity / MinQuantity) * ApplicablePrice) + ((cartSKU.Quantity % MinQuantity) * unitPrice);
            }

            return(calcPrice);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            PromotionCalculator PromoCalObj  = new PromotionCalculator(new PromotionSKUObj());
            List <CartSKU>      cartItemList = new List <CartSKU>();
            int totalAmount = 0;

            Console.WriteLine("Enter number of SKUs in the cart");
            int i = Convert.ToInt32(Console.ReadLine());

            for (int j = 0; j < i; j++)
            {
                Console.WriteLine("Enter a SKU from A, B, C or D");
                CartSKU cartObj = new CartSKU();
                cartObj.SKUName = Console.ReadLine();
                Console.WriteLine("Enter the quantity of the entered SKU");
                cartObj.SKUQuantity = Convert.ToInt32(Console.ReadLine());
                cartItemList.Add(cartObj);
            }
            totalAmount = PromoCalObj.GetCartTotalAmount(cartItemList);
            Console.WriteLine("Total Amount {0}", totalAmount);
        }
        public override double CalculatePrice(List <CartSKU> cartSKUs, Dictionary <SKU, double> priceList)
        {
            double calcPrice = 0;

            CartSKU cartSKU1 = cartSKUs.FirstOrDefault(x => x.Id == SKU1.Id && x.IsPromotionApplied == false);
            CartSKU cartSKU2 = cartSKUs.FirstOrDefault(x => x.Id == SKU2.Id && x.IsPromotionApplied == false);

            if (cartSKU1 != null && cartSKU2 != null)
            {
                //Promotion Appplicable
                double unitPriceSKU1 = priceList[priceList.Keys.FirstOrDefault(x => x.Id == cartSKU1.Id)];
                double unitPriceSKU2 = priceList[priceList.Keys.FirstOrDefault(x => x.Id == cartSKU2.Id)];
                cartSKU1.IsPromotionApplied = true;
                cartSKU2.IsPromotionApplied = true;

                int min = Math.Min(cartSKU1.Quantity, cartSKU2.Quantity);

                calcPrice = min * ApplicablePrice + ((cartSKU1.Quantity - min) * unitPriceSKU1) + ((cartSKU2.Quantity - min) * unitPriceSKU2);
            }

            return(calcPrice);
        }
Exemple #4
0
        private double GetPrice(CartSKU cartSKU, Dictionary <SKU, double> priceList)
        {
            double unitPrice = priceList[priceList.Keys.FirstOrDefault(x => x.Id == cartSKU.Id)];

            return(cartSKU.Quantity * unitPrice);
        }