Exemplo n.º 1
0
        public static void ReapplyOnDateChanged <T> (Operation <T> operation, Action <string, Action> reapplyConfirmation, IListModel <PriceRule> allRules = null) where T : OperationDetail, new ()
        {
            if (operation.Details.Count == 0)
            {
                return;
            }

            if (allRules == null)
            {
                allRules = GetAll();
            }

            if (allRules.Where(p => p.Enabled).SelectMany(r => r.Conditions).All(c => c.Type != ConditionType.Date))
            {
                return;
            }

            reapplyConfirmation(Translator.GetString("You have changed the date. Would you like to reapply your price rules?"), () =>
            {
                for (int i = operation.Details.Count - 1; i >= 0; i--)
                {
                    if ((operation.Details [i].AppliedPriceRules & AppliedActions.PromotionalItem) == AppliedActions.PromotionalItem)
                    {
                        operation.RemoveDetail(i, false);
                    }
                    else
                    {
                        operation.Details [i].AppliedPriceRules = AppliedActions.None;
                    }
                }

                ApplyBeforeOperationSaved(operation, null, false, allRules);
            });
        }
Exemplo n.º 2
0
        public static void ReapplyOnUserChanged <T> (Operation <T> operation, Action <string, Action> reapplyConfirmation, IListModel <PriceRule> allRules = null) where T : OperationDetail, new ()
        {
            if (operation.Details.Count == 0)
            {
                return;
            }

            if (allRules == null)
            {
                allRules = GetAll();
            }

            if (!allRules.Where(p => p.Enabled).SelectMany(r => r.Conditions).Any(c =>
            {
                if (c.Error || c.Values == null || c.Values.Length <= 0 || c.Values [0] == null)
                {
                    return(false);
                }

                switch (c.Type)
                {
                case ConditionType.User:
                    return((long)c.Values [0] == operation.PartnerId);

                case ConditionType.UserGroup:
                    string stringValue = (string)c.Values [0];

                    long longValue;
                    UsersGroup usersGroup = long.TryParse(stringValue, NumberStyles.Any, CultureInfo.InvariantCulture, out longValue) ?
                                            UsersGroup.Cache.GetById(longValue) :
                                            UsersGroup.Cache.GetByCode(stringValue);

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

                    User user = User.Cache.GetById(operation.UserId);
                    if (user == null)
                    {
                        return(false);
                    }

                    return(usersGroup.Id == user.GroupId);
                }

                return(false);
            }))
            {
                return;
            }

            reapplyConfirmation(Translator.GetString("You have changed the operator. Would you like to reapply your price rules?"), () =>
            {
                for (int i = operation.Details.Count - 1; i >= 0; i--)
                {
                    if ((operation.Details [i].AppliedPriceRules & AppliedActions.PromotionalItem) == AppliedActions.PromotionalItem)
                    {
                        operation.RemoveDetail(i, false);
                    }
                    else
                    {
                        operation.Details [i].AppliedPriceRules = AppliedActions.None;
                    }
                }

                ApplyBeforeOperationSaved(operation, null, false, allRules);
            });
        }