Exemple #1
0
 public HomeController(ILogger <HomeController> logger,
                       IItemAction itemAction,
                       IPromotionAction promotionAction)
 {
     _logger          = logger;
     _itemAction      = itemAction;
     _promotionAction = promotionAction;
 }
        private void LoadCorrectEditor()
        {
            Promotion        p = GetCurrentPromotion();
            IPromotionAction a = GetCurrentAction(p);

            if (a == null)
            {
                return;
            }

            switch (a.TypeId.ToString().ToUpper())
            {
            case PromotionActionBase.TypeIdProductPriceAdjustment:
                this.MultiView1.SetActiveView(this.viewAdjustProductPrice);
                this.AmountField.Text = ((ProductPriceAdjustment)a).Amount.ToString();
                if (((ProductPriceAdjustment)a).AdjustmentType == AmountTypes.Percent)
                {
                    this.lstAdjustmentType.ClearSelection();
                    this.lstAdjustmentType.Items.FindByValue("1").Selected = true;
                }
                else
                {
                    this.lstAdjustmentType.ClearSelection();
                    this.lstAdjustmentType.Items.FindByValue("0").Selected = true;
                }
                break;

            case PromotionActionBase.TypeIdOrderTotalAdjustment:
                this.MultiView1.SetActiveView(this.viewAdjustOrderTotal);
                this.OrderTotalAmountField.Text = ((OrderTotalAdjustment)a).Amount.ToString();
                if (((OrderTotalAdjustment)a).AdjustmentType == AmountTypes.Percent)
                {
                    this.lstOrderTotalAdjustmentType.ClearSelection();
                    this.lstOrderTotalAdjustmentType.Items.FindByValue("1").Selected = true;
                }
                else
                {
                    this.lstOrderTotalAdjustmentType.ClearSelection();
                    this.lstOrderTotalAdjustmentType.Items.FindByValue("0").Selected = true;
                }
                break;

            case PromotionActionBase.TypeIdOrderShippingAdjustment:
                this.MultiView1.SetActiveView(this.viewOrderShippingAdjustment);
                this.OrderShippingAdjustmentAmount.Text = ((OrderShippingAdjustment)a).Amount.ToString();
                if (((OrderShippingAdjustment)a).AdjustmentType == AmountTypes.Percent)
                {
                    this.lstOrderShippingAdjustmentType.ClearSelection();
                    this.lstOrderShippingAdjustmentType.Items.FindByValue("1").Selected = true;
                }
                else
                {
                    this.lstOrderShippingAdjustmentType.ClearSelection();
                    this.lstOrderShippingAdjustmentType.Items.FindByValue("0").Selected = true;
                }
                break;
            }
        }
        private IPromotionAction GetCurrentAction(Promotion p)
        {
            if (p == null)
            {
                return(null);
            }
            string itemId = this.itemid.Value;
            long   temp   = 0;

            long.TryParse(itemId, out temp);
            IPromotionAction a = p.GetAction(temp);

            return(a);
        }
Exemple #4
0
            private void ExtractOfferByAction(IPromotionAction a, Promotion p, List <Promotion> tempOffers)
            {
                var m = PromotionType.Offer;

                if (a.TypeId.ToString().ToLower() == LineItemAdjustment.TypeIdString ||
                    a.TypeId.ToString().ToLower() == LineItemFreeShipping.TypeIdString)
                {
                    m = PromotionType.OfferForLineItems;
                }
                else if (a.TypeId.ToString().ToLower() == OrderShippingAdjustment.TypeIdString)
                {
                    m = PromotionType.OfferForShipping;
                }
                else if (a.TypeId.ToString().ToLower() == OrderTotalAdjustment.TypeIdString)
                {
                    m = PromotionType.OfferForOrder;
                }

                if (m == PromotionType.Offer)
                {
                    throw new ApplicationException("Offer contains invalid action types: sale or affiliate");
                }

                var tOffer = tempOffers.FirstOrDefault(t => t.Mode == m);

                if (tOffer == null)
                {
                    tOffer = new Promotion
                    {
                        Mode = m,
                        Name = p.Name,
                        CustomerDescription = p.CustomerDescription,
                        StartDateUtc        = p.StartDateUtc,
                        EndDateUtc          = p.EndDateUtc,
                        IsEnabled           = p.IsEnabled,
                        DoNotCombine        = p.DoNotCombine,
                        SortOrder           = (int)p.Id
                    };

                    var xml = p.QualificationsToXml();
                    tOffer.QualificationsFromXml(xml);
                    tempOffers.Add(tOffer);
                }

                tOffer.AddAction(a);
            }
        public bool SaveAction()
        {
            Promotion p = GetCurrentPromotion();

            if (p == null)
            {
                return(false);
            }
            IPromotionAction a = GetCurrentAction(p);

            if (a == null)
            {
                return(false);
            }

            return(SaveEditor(p, a));
        }
Exemple #6
0
        public bool AddAction(IPromotionAction a)
        {
            long maxid = 0;

            if (_actions.Count > 0)
            {
                maxid = _actions.Max(y => y.Id);
            }
            if (maxid < 0)
            {
                maxid = 0;
            }

            a.Id = maxid + 1;
            _actions.Add(a);

            return(true);
        }
Exemple #7
0
        private IPromotionAction ActionFactory(IEnumerable <XElement> nodes)
        {
            if (nodes == null)
            {
                return(null);
            }

            XElement nodeTypeId = nodes.Where(y => y.Name == "TypeId").FirstOrDefault();

            if (nodeTypeId == null)
            {
                return(null);
            }
            Guid typeId = new Guid(nodeTypeId.Value);

            IPromotionAction result = PromotionActionBase.Factory(typeId.ToString().ToUpperInvariant());

            if (result == null)
            {
                return(null);
            }

            XElement nodeId = nodes.Where(y => y.Name == "Id").FirstOrDefault();

            if (nodeId != null)
            {
                long temp = 0;
                long.TryParse(nodeId.Value, out temp);
                result.Id = temp;
            }
            XElement nodeSettings = nodes.Where(y => y.Name == "Settings").FirstOrDefault();

            if (nodeSettings != null)
            {
                foreach (XElement setting in nodeSettings.Descendants("Setting"))
                {
                    string key   = setting.Element("Key").Value;
                    string value = setting.Element("Value").Value;
                    result.Settings[key] = value;
                }
            }

            return(result);
        }
        public void LoadAction(Promotion prom, IPromotionAction action)
        {
            PromotionId = prom.Id;
            ActionId    = action.Id;

            switch (action.TypeId.ToString())
            {
            case ProductPriceAdjustment.TypeIdString:
                mvActions.SetActiveView(viewAdjustProductPrice);
                break;

            case OrderTotalAdjustment.TypeIdString:
                mvActions.SetActiveView(viewAdjustOrderTotal);
                break;

            case LineItemAdjustment.TypeIdString:
                mvActions.SetActiveView(viewAdjustLineItem);
                break;

            case OrderShippingAdjustment.TypeIdString:
                mvActions.SetActiveView(viewOrderShippingAdjustment);
                break;

            case LineItemFreeShipping.TypeIdString:
                mvActions.SetActiveView(viewLineItemFreeShipping);
                break;

            case RewardPointsAjustment.TypeIdString:
                mvActions.SetActiveView(viewAdjustRewardPoints);
                break;

            case ReceiveFreeProductAdjustment.TypeIdString:
                mvActions.SetActiveView(viewReceiveFreeProduct);
                break;

            case CategoryDiscountAdjustment.TypeIdString:
                mvActions.SetActiveView(viewCategoryDiscount);
                break;
            }

            LoadActionEditor(true);
        }
Exemple #9
0
        public bool AddAction(IPromotionAction a)
        {

            long maxid = 0;
            if (this._Actions.Count > 0)
            {
                maxid = this._Actions.Max(y => y.Id);
            }
            if (maxid < 0) maxid = 0;
            
            a.Id = maxid + 1;
            _Actions.Add(a);

            return true;
        }
        private bool SaveEditor(Promotion p, IPromotionAction a)
        {
            switch (a.TypeId.ToString().ToUpper())
            {
                case PromotionActionBase.TypeIdProductPriceAdjustment:
                    decimal adjustmentTemp = ((ProductPriceAdjustment)a).Amount;
                    decimal parsedAdjustment = 0;
                    if (decimal.TryParse(this.AmountField.Text, out parsedAdjustment))
                    {
                        adjustmentTemp = parsedAdjustment;
                    }
                    ((ProductPriceAdjustment)a).Amount = adjustmentTemp;
                    if (this.lstAdjustmentType.SelectedValue == "1")
                    {
                        ((ProductPriceAdjustment)a).AdjustmentType = AmountTypes.Percent;
                    }
                    else
                    {
                        ((ProductPriceAdjustment)a).AdjustmentType = AmountTypes.MonetaryAmount;
                    }
                    return MyPage.MTApp.MarketingServices.Promotions.Update(p);
                case PromotionActionBase.TypeIdOrderTotalAdjustment:
                    decimal adjustmentTemp2 = ((OrderTotalAdjustment)a).Amount;
                    decimal parsedAdjustment2 = 0;
                    if (decimal.TryParse(this.OrderTotalAmountField.Text, out parsedAdjustment2))
                    {
                        adjustmentTemp2 = parsedAdjustment2;
                    }
                    ((OrderTotalAdjustment)a).Amount = adjustmentTemp2;
                    if (this.lstOrderTotalAdjustmentType.SelectedValue == "1")
                    {
                        ((OrderTotalAdjustment)a).AdjustmentType = AmountTypes.Percent;
                    }
                    else
                    {
                        ((OrderTotalAdjustment)a).AdjustmentType = AmountTypes.MonetaryAmount;
                    }
                    return MyPage.MTApp.MarketingServices.Promotions.Update(p);
                case PromotionActionBase.TypeIdOrderShippingAdjustment:
                    decimal adjustmentOrderShipping = ((OrderShippingAdjustment)a).Amount;
                    decimal parsedAdjustmentOrderShipping = 0;
                    if (decimal.TryParse(this.OrderShippingAdjustmentAmount.Text, out parsedAdjustmentOrderShipping))
                    {
                        adjustmentOrderShipping = parsedAdjustmentOrderShipping;
                    }
                    ((OrderShippingAdjustment)a).Amount = adjustmentOrderShipping;
                    if (this.lstOrderShippingAdjustmentType.SelectedValue == "1")
                    {
                        ((OrderShippingAdjustment)a).AdjustmentType = AmountTypes.Percent;
                    }
                    else
                    {
                        ((OrderShippingAdjustment)a).AdjustmentType = AmountTypes.MonetaryAmount;
                    }
                    return MyPage.MTApp.MarketingServices.Promotions.Update(p);       
            }

            return false;
        }
        private bool SaveEditor(Promotion p, IPromotionAction a)
        {
            switch (a.TypeId.ToString().ToUpper())
            {
            case PromotionActionBase.TypeIdProductPriceAdjustment:
                decimal adjustmentTemp   = ((ProductPriceAdjustment)a).Amount;
                decimal parsedAdjustment = 0;
                if (decimal.TryParse(this.AmountField.Text, out parsedAdjustment))
                {
                    adjustmentTemp = parsedAdjustment;
                }
                ((ProductPriceAdjustment)a).Amount = adjustmentTemp;
                if (this.lstAdjustmentType.SelectedValue == "1")
                {
                    ((ProductPriceAdjustment)a).AdjustmentType = AmountTypes.Percent;
                }
                else
                {
                    ((ProductPriceAdjustment)a).AdjustmentType = AmountTypes.MonetaryAmount;
                }
                return(MyPage.MTApp.MarketingServices.Promotions.Update(p));

            case PromotionActionBase.TypeIdOrderTotalAdjustment:
                decimal adjustmentTemp2   = ((OrderTotalAdjustment)a).Amount;
                decimal parsedAdjustment2 = 0;
                if (decimal.TryParse(this.OrderTotalAmountField.Text, out parsedAdjustment2))
                {
                    adjustmentTemp2 = parsedAdjustment2;
                }
                ((OrderTotalAdjustment)a).Amount = adjustmentTemp2;
                if (this.lstOrderTotalAdjustmentType.SelectedValue == "1")
                {
                    ((OrderTotalAdjustment)a).AdjustmentType = AmountTypes.Percent;
                }
                else
                {
                    ((OrderTotalAdjustment)a).AdjustmentType = AmountTypes.MonetaryAmount;
                }
                return(MyPage.MTApp.MarketingServices.Promotions.Update(p));

            case PromotionActionBase.TypeIdOrderShippingAdjustment:
                decimal adjustmentOrderShipping       = ((OrderShippingAdjustment)a).Amount;
                decimal parsedAdjustmentOrderShipping = 0;
                if (decimal.TryParse(this.OrderShippingAdjustmentAmount.Text, out parsedAdjustmentOrderShipping))
                {
                    adjustmentOrderShipping = parsedAdjustmentOrderShipping;
                }
                ((OrderShippingAdjustment)a).Amount = adjustmentOrderShipping;
                if (this.lstOrderShippingAdjustmentType.SelectedValue == "1")
                {
                    ((OrderShippingAdjustment)a).AdjustmentType = AmountTypes.Percent;
                }
                else
                {
                    ((OrderShippingAdjustment)a).AdjustmentType = AmountTypes.MonetaryAmount;
                }
                return(MyPage.MTApp.MarketingServices.Promotions.Update(p));
            }

            return(false);
        }