Example #1
0
        private void ApplyPromotion(int lastAlteredproductId, ProductType productType)
        {
            var cartProducts = GetCartProducts(lastAlteredproductId);
            ProductPromotion productPromotion;

            if (productType == ProductType.Product)
            {
                productPromotion = ProductPromotionRepository.GetProductPromotionByProductId(lastAlteredproductId);
            }
            else if (productType == ProductType.PromoProduct)
            {
                productPromotion = ProductPromotionRepository.GetProductPromotionByPromoProductId(lastAlteredproductId);
            }
            else
            {
                throw new Exception("greska");
            }

            var promotion = PromotionRepository.GetPromotion(productPromotion.PromotionId);

            if (IsProductInCart(productPromotion.PromotionalProductId, false))
            {
                RemoveCartProduct(productPromotion.PromotionalProductId);
                AddCartProduct(productPromotion.PromotionalProductId, productPromotion.PromotionId);
            }
        }
Example #2
0
        private List <ProductType> IsPromotionAvailable(int lastAlteredproductId)
        {
            List <ProductType> types        = new List <ProductType>();
            var productPromotionByProductId = ProductPromotionRepository.GetProductPromotionByProductId(lastAlteredproductId);

            if (productPromotionByProductId != null &&
                ArePromotionRequirementsMet(productPromotionByProductId.ProductId, productPromotionByProductId.PromotionId))
            {
                types.Add(ProductType.Product);
            }
            var productPromotionByPromoProductId = ProductPromotionRepository.GetProductPromotionByPromoProductId(lastAlteredproductId);

            if (productPromotionByPromoProductId != null && ArePromotionRequirementsMet(productPromotionByPromoProductId.ProductId, productPromotionByPromoProductId.PromotionId))
            {
                types.Add(ProductType.PromoProduct);
            }

            return(types);
        }
Example #3
0
        private void LogCartDetails()
        {
            Console.WriteLine("Current state of cart");
            var temp = CartProducts.GroupBy(product => product.Id);

            foreach (var cartProduct in temp)
            {
                var totalQuantity = cartProduct.Sum(p => p.Quantity);
                Console.Write($"{cartProduct.First().ToString()}\n" +
                              $"product Quantity: {cartProduct.Sum(p => p.Quantity)}\n" +
                              $"cost of products: {cartProduct.Sum(p => p.Price * p.Quantity)}\n");
                if (cartProduct.Any(p => p.IsPromotion) && ProductPromotionRepository.GetProductPromotionByProductId(cartProduct.First().Id) != null)
                {
                    Console.Write($"Applied promotion id {ProductPromotionRepository.GetProductPromotionByProductId(cartProduct.First().Id).PromotionId}\n");
                }
                else if (cartProduct.Any(p => p.IsPromotion) && ProductPromotionRepository.GetProductPromotionByPromoProductId(cartProduct.First().Id) != null)
                {
                    Console.Write($"Applied promotion id {ProductPromotionRepository.GetProductPromotionByPromoProductId(cartProduct.First().Id).PromotionId}\n");
                }
            }
        }
Example #4
0
 public void RemoveCartProduct(int productId)
 {
     if (!ProductPromotionRepository.GetProductPromotions().Any(p => p.ProductId == productId))
     {
         RemoveCartProduct(productId, false);
     }
     else
     {
         var productPromotion = ProductPromotionRepository.GetProductPromotionByProductId(productId);
         var promotion        = PromotionRepository.GetPromotion(productPromotion.PromotionId);
         if (IsProductInCart(productPromotion.PromotionalProductId) &&
             (!ArePromotionRequirementsMet(productPromotion.ProductId, productPromotion.PromotionId) &&
              IsProductInCart(productPromotion.PromotionalProductId, true)))
         {
             RemoveCartProduct(productId, false);
             RemoveCartProduct(productPromotion.PromotionalProductId, true);
             AddCartProduct(productPromotion.PromotionalProductId);
         }
         else
         {
             RemoveCartProduct(productId, false);
         }
     }
 }