Create a VisitorGroup from code

Vote:
 

I'm trying to create a visitor group from code. So far this is the code I have come up with. (These seems to be no documentation on this?)
The code creates a Visitor Group, but the criteria it creates is empty and without any boxes to check on/off. If I drag&drop the criteria it will work as normal. Are there any steps I'm missing when it comes to creating a visitor group from code?

 

var store = new VisitorGroupStore();

var visitorGroup = new VisitorGroup
{
    Name = "Test group", 
    CriteriaOperator = CriteriaOperator.All
};

var model = new RoleModel
{
   Condition = RoleCompareCondition.Equal,
   RoleName = "my-role",
   Id = Identity.NewIdentity()
};

var criterion = new VisitorGroupCriterion
{
    Id = Guid.NewGuid(),
    TypeName = VisitorGroupCriterionRepository.GetTypeName(typeof (RoleModel)),
    Definition = new VisitorGroupCriterionAttribute
    {
       Category = "User Criteria",
       DisplayName = "RoleModel",
       Description = "Criterion that matches the user's roles",
       LanguagePath = "/shell/cms/visitorgroups/criteria/role"
    },
    Model = model,
};

visitorGroup.Criteria.Add(criterion);

store.Save(visitorGroup);

    

#73246
Jul 11, 2013 14:00
Vote:
 

This is what the generated criteria looks like. The one on top is created with drag&drop..

http://i.imgur.com/VumZjEe.png

#73247
Jul 11, 2013 14:04
Vote:
 
#73595
Jul 31, 2013 11:05
Vote:
 

By setting the Settings property to model, I got it to work (wtf?). This is what the json sent on saving in the episerver admin does.

 

var criterion = new VisitorGroupCriterion
{
    Id = Guid.NewGuid(),
    TypeName = VisitorGroupCriterionRepository.GetTypeName(typeof (RoleModel)),
    Definition = new VisitorGroupCriterionAttribute
    {
       Category = "User Criteria",
       DisplayName = "RoleModel",
       Description = "Criterion that matches the user's roles",
       LanguagePath = "/shell/cms/visitorgroups/criteria/role"
    },
    Model = model,
    Settings = model
};

    

#73625
Aug 01, 2013 16:45
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.