public static PromotionProperties Create(XElement xPromotion, ReferenceConverter referenceConverter)
        {
            var promotion = new PromotionProperties();

            // Conditions
            var conditionContentLinks = GetContentLinks(xPromotion, "Condition", "Codes", referenceConverter);
            var xCondition            = xPromotion.Element(XName.Get("Condition"));

            promotion.ConditionContentLinks = conditionContentLinks;

            var xConditionAmount          = xCondition.Element(XName.Get("Amount"));
            var conditionValue            = string.IsNullOrEmpty(xConditionAmount.Get("Value")) ? "0" : xConditionAmount.Get("Value");
            var conditionCurrency         = string.IsNullOrEmpty(xConditionAmount.Get("Currency")) ? "USD" : xConditionAmount.Get("Currency");
            var conditionAmount           = new Money(decimal.Parse(conditionValue ?? "0"), new Currency(conditionCurrency));
            var conditionRequiredQuantity = string.IsNullOrEmpty(xCondition.Get("RequiredQuanity")) ? 0 : int.Parse(xCondition.Get("RequiredQuanity") ?? "0");

            promotion.ConditionAmounts = new List <Money> {
                conditionAmount
            };
            promotion.ConditionRequiredQuantity = conditionRequiredQuantity;

            // Targets
            var targetContentLinks = GetContentLinks(xPromotion, "Target", "Codes", referenceConverter);

            promotion.TargetContentLinks = targetContentLinks;

            // Discount
            var xDiscount          = xPromotion.Element(XName.Get("Discount"));
            var xDiscountAmount    = xDiscount.Element(XName.Get("Amount"));
            var discountValue      = string.IsNullOrEmpty(xDiscountAmount.Get("Value")) ? "0" : xDiscountAmount.Get("Value");
            var discountCurrency   = string.IsNullOrEmpty(xDiscountAmount.Get("Currency")) ? "USD" : xDiscountAmount.Get("Currency");
            var discountAmount     = new Money(decimal.Parse(discountValue ?? "0"), new Currency(discountCurrency));
            var discountUseAmount  = bool.Parse(string.IsNullOrEmpty(xDiscount.Get("UseAmounts")) ? "False" : xDiscount.Get("UseAmounts"));
            var discountPercentage = decimal.Parse(string.IsNullOrEmpty(xDiscount.Get("Percentage")) ? "0" : xDiscount.Get("Percentage"));

            promotion.DiscountAmounts = new List <Money> {
                discountAmount
            };
            promotion.IsDiscountUseAmount = discountUseAmount;
            promotion.DiscountPercentage  = discountPercentage;

            // Common promotio attributes
            var bannerPath  = xPromotion.Get("Banner");
            var description = xPromotion.Get("Description");
            var isActive    = bool.Parse(string.IsNullOrEmpty(xPromotion.Get("IsActive")) ? "False" : xPromotion.Get("IsActive"));
            var type        = xPromotion.Get("Type");
            var name        = xPromotion.Get("Name");

            promotion.Name        = name;
            promotion.Description = description;
            promotion.IsActive    = isActive;
            promotion.Type        = type;
            promotion.Banner      = bannerPath;

            return(promotion);
        }
        private void CreatePromotion(ContentReference campaignLink, XElement xPromotion)
        {
            var promotionProperties = PromotionProperties.Create(xPromotion, ReferenceConverter);

            switch (promotionProperties.Type)
            {
            case "BuyQuantityGetItemDiscount":
                CreateBuyFromMenShoesGetDiscountPromotion(campaignLink, promotionProperties);
                break;

            case "SpendAmountGetOrderDiscount":
                CreateSpendAmountGetDiscountPromotion(campaignLink, promotionProperties);
                break;

            case "BuyQuantityGetShippingDiscount":
                CreateBuyFromWomenShoesGetShippingDiscountPromotion(campaignLink, promotionProperties);
                break;

            default:
                break;
            }
        }
        private void CreateBuyFromMenShoesGetDiscountPromotion(ContentReference campaignLink, PromotionProperties promotionProperties)
        {
            var promotion = ContentRepository.GetDefault <BuyQuantityGetItemDiscount>(campaignLink);

            promotion.IsActive                   = promotionProperties.IsActive;
            promotion.Name                       = promotionProperties.Name ?? "20 % off Mens Shoes";
            promotion.Condition.Items            = promotionProperties.ConditionContentLinks;
            promotion.Condition.RequiredQuantity = promotionProperties.ConditionRequiredQuantity;
            promotion.DiscountTarget.Items       = promotionProperties.TargetContentLinks;
            promotion.Discount.UseAmounts        = promotionProperties.IsDiscountUseAmount;
            promotion.Discount.Percentage        = promotionProperties.DiscountPercentage;
            promotion.Banner                     = GetAssetUrl(promotionProperties.Banner);
            ContentRepository.Save(promotion, SaveAction.Publish, AccessLevel.NoAccess);
        }
        private void CreateBuyFromWomenShoesGetShippingDiscountPromotion(ContentReference campaignLink, PromotionProperties promotionProperties)
        {
            var promotion = ContentRepository.GetDefault <BuyQuantityGetShippingDiscount>(campaignLink);

            promotion.IsActive                   = promotionProperties.IsActive;
            promotion.Name                       = promotionProperties.Name ?? "$10 off shipping from Women's Shoes";
            promotion.Condition.Items            = promotionProperties.ConditionContentLinks;
            promotion.ShippingMethods            = GetShippingMethodIds();
            promotion.Condition.RequiredQuantity = promotionProperties.ConditionRequiredQuantity;
            promotion.Discount.UseAmounts        = promotionProperties.IsDiscountUseAmount;
            promotion.Discount.Amounts           = promotionProperties.DiscountAmounts;
            promotion.Banner                     = GetAssetUrl(promotionProperties.Banner);
            ContentRepository.Save(promotion, SaveAction.Publish, AccessLevel.NoAccess);
        }
        private void CreateSpendAmountGetDiscountPromotion(ContentReference campaignLink, PromotionProperties promotionProperties)
        {
            var promotion = ContentRepository.GetDefault <SpendAmountGetOrderDiscount>(campaignLink);

            promotion.IsActive            = promotionProperties.IsActive;
            promotion.Name                = promotionProperties.Name ?? "$50 off Order over $500";
            promotion.Condition.Amounts   = promotionProperties.ConditionAmounts;
            promotion.Discount.UseAmounts = promotionProperties.IsDiscountUseAmount;
            promotion.Discount.Amounts    = promotionProperties.DiscountAmounts;
            promotion.Banner              = GetAssetUrl(promotionProperties.Banner);
            ContentRepository.Save(promotion, SaveAction.Publish, AccessLevel.NoAccess);
        }