Ejemplo n.º 1
0
        private void RuleRibbonToggleButton_PressedButtonChanged(object sender, EventArgs e)
        {
            if (!(sender is RibbonToggleButton pressedRule))
            {
                return;
            }

            string ruleName = pressedRule.Text;
            bool   pressed  = pressedRule.Pressed;

            IRule newRule = _rules.Where(x => x.Name == ruleName).FirstOrDefault();

            newRule.AppliesTo.Add(new FieldRange(new string[] { "Product", "Country", "Color", "Discount" }));

            RuleCollection appliedRules = _rulesManager.Rules;
            IRule          existingRule = appliedRules.Where(x => x.Name == ruleName).FirstOrDefault();

            if (!pressed && appliedRules.Contains(existingRule))
            {
                appliedRules.Remove(existingRule);
            }
            if (pressed && existingRule is null)
            {
                appliedRules.Add(newRule);
            }
        }
Ejemplo n.º 2
0
        public override void Apply(Cart cart)
        {
            cart.Total = 0;
            var distinctProducts = cart.Items.Select(x => x.ItemCode).Distinct().ToList();

            foreach (var productCode in distinctProducts)
            {
                var productRule  = RuleCollection.Where(x => x.ProductCode == productCode).FirstOrDefault();
                var productPrice = cart.Items.Where(x => x.ItemCode == productCode)
                                   .Select(x => x.Price).First();
                var productListCount = cart.Items.Where(x => x.ItemCode == productCode).Count();

                if (productRule != null)
                {
                    var groupOfferCount = productListCount / productRule.Quantity;
                    var remainingCount  = productListCount % productRule.Quantity;

                    cart.Total += groupOfferCount * productRule.Amount;
                    cart.Total += remainingCount * productPrice;
                }
                else
                {
                    cart.Total += productPrice * productListCount;
                }
            }
        }
Ejemplo n.º 3
0
        public async void OnRunPsScriptCommand()
        {
            IsEditEnabled = false;


            var check    = RuleCollection.Where(x => x.DisplayName == SelectedRule.DisplayName);
            var intCheck = check.Count();

            if (intCheck == 0)
            {
                var result = await SelectedRule.Commit(true);

                PowerShellScript = "Script Completed - " + result.Item1.ToString();
                GetRules();
            }
            else
            {
                PowerShellScript = "Script Halted - Rule '" + SelectedRule.DisplayName + "' already exists";
            }

            IsEditEnabled = true;
        }