VisitorGroups Criterion values not persisted?

Vote:
 

Hi, I am creating a custom SelectionCriterion (just for fun) for use with VisitorGroups, on EPiServer CMS (Product Version: 8.11.0, File Version 8.11.0.0 on EPiServer.dll).

It displays seemingly correctly in the EPiServer GUI, and no errors when cliking the Save button when creating a new visitor group.

However, if I go away from the page and then return to the settings for the visitor group, the values which I selected are (seemingly) no longer set.

So did the settings get saved or not? How can I know?

If it's just a display problem, then that's not so bad, except it would be nice to be able to go in and see what the settings are.

Please help!

This is the model:

    public class BeenMissingYouCriterionSettings : CriterionModelBase
    {
        [Required]
        [Range(1, 999)]
        public int Number { get; set; }

        /// 
        /// Text for enum members are set in lang file: /Resources/LanguageFiles/Enums.xml
        /// 
        [Required]
        [DojoWidget(SelectionFactoryType = typeof(EnumSelectionFactory))]
        public PropertyTimeSpanControl.TimeUnit Unit { get; set; }

        public override ICriterionModel Copy()
        {
            return ShallowCopy();
        }
    }

And here's the SelectionCriterion:

    [VisitorGroupCriterion(
       Category = "Time and Place Criteria",
       DisplayName = "I've Been Missing You",
       Description = "Returns true if more than configured timeunits since last login.")]
    public class BeenMissingYouCriterion : CriterionBase
    {
        public override bool IsMatch(IPrincipal principal, HttpContextBase httpContext)
        {
            var user = Membership.GetUser();
            switch (Model.Unit)
            {
                case EPiServer.Web.PropertyControls.PropertyTimeSpanControl.TimeUnit.Minute:
                    return user?.LastLoginDate.AddMinutes(Model.Number).CompareTo(DateTime.Now) < 1;
                case EPiServer.Web.PropertyControls.PropertyTimeSpanControl.TimeUnit.Hour:
                    return user?.LastLoginDate.AddHours(Model.Number).CompareTo(DateTime.Now) < 1;
                case EPiServer.Web.PropertyControls.PropertyTimeSpanControl.TimeUnit.Day:
                    return user?.LastLoginDate.AddDays(Model.Number).CompareTo(DateTime.Now) < 1;
                case EPiServer.Web.PropertyControls.PropertyTimeSpanControl.TimeUnit.Week:
                    return user?.LastLoginDate.AddDays(Model.Number * 7).CompareTo(DateTime.Now) < 1;
                case EPiServer.Web.PropertyControls.PropertyTimeSpanControl.TimeUnit.Month:
                    return user?.LastLoginDate.AddMonths(Model.Number).CompareTo(DateTime.Now) < 1;
                case EPiServer.Web.PropertyControls.PropertyTimeSpanControl.TimeUnit.Undefined:
                    return false;
                default:
                    return false;
            }
        }
    }
#138688
Sep 23, 2015 11:18
Vote:
 

Hello Svein

At first glance your code looks OK. I can only think that perhaps something has gone wrong with the TimeUnit property on the model. Have you tried creating a more simple version just using strings? 

You should also check out the console to look for any javascript errors that are not being displayed to end users when the criteria loads.

I recently posted a simple set of criteria for cookies so perhaps you could start with mine and refactor until you find the issue? https://github.com/davidknipe/CookieVisitorGroupCriteria

David

#138921
Sep 23, 2015 15:50
Vote:
 

try

[DojoWidget( DefaultValue = 1), Required, Range(1, 999)]
public int Number { get; set; }
Regards
/K
#138923
Edited, Sep 23, 2015 16:16
Vote:
 

Thanks for the help (long time). I appreciate it! But unfortunately I was diverted into something else, so I never got to fix this, and now I don't even have the code any more. So I guess theres only one word to say: Sorry!

#185563
Nov 24, 2017 8:54
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.