Creating a custom attribute for IUser

Vote:
 

I'd like to extend the IUser with a list of companies and the user's function in the company. What's the easiest way to create such attribute?
I've already seen the blogs about creating a custom module (http://world.episerver.com/Articles/Items/Creating-a-Custom-EPiServer-Community-Module---Part-One/), but that seems like overkill for this case. I tried to create a custom attribute using this blog, but I get an error saying that the input string was not in a correct format when I try to save the details in 'EPiServer.Common.Data.AttributeFactory.UpdateEntityAttributes'.

The idea is to be able to enter a company name and, per company, select a function from a dropdownlist.

#51327
Jun 01, 2011 18:25
Vote:
 

Sounds like you could do with just storing strings? You can store a string attribute as a single value (SetAttributeValue/GetAttributeValue) or multiple values (SetAttributeValues/GetAttributeValues) that are stored with the same key. Just store your company-funcion pair as for example a comma separated string and store multiple such pair using SetAttributeValues. Or you could store an xml document as a single string if you need more flexibility (but querying would get more complicated an expensive).

#51328
Jun 01, 2011 23:48
Vote:
 

Sounds good, but do you have an example of how to implement this? Do I need to inherit a specific class?

When I change the attribute type to inherit 'StringAttributeType', I have no option to specify the edit-control. The admin-pages only shows a single textbox instead of a textbox and a dropdownlist.

#51372
Edited, Jun 06, 2011 10:09
Vote:
 

Ah, I didn't realize you also wanted to edit the attribute from admin mode. I thought you only wanted to set it from code (and in that case you don't need a class, just set the string value). I don't know if there is any built in support to extend the admin interface. But perhaps you can figure out which control is displaying the attribute editing, create your own modified clone and use the Virtual path mapping provider to replace the control with your own.

#51383
Jun 07, 2011 9:59
Vote:
 

Editting in the admin isn't necessary, but using it in a query is. I've just tested setting the attribute in code, which works fine. But using the value (part of it since it's a comma-separated value) in a query isn't that easy.

 

I tried again using the example mentioned before. My code is exactly the same as the one from the example, but for some reason the method AddEntityInstance is never called. Can anyone explain this? Should this method be called as soon as I create another attribute (in the admin or in code) ?

#51393
Edited, Jun 07, 2011 11:49
Vote:
 

Ok, finally I managed to get the attribute working. I had to much code from the example, where the attribute was also an entity. In my case, that wasn't necessary.

But how can I use this attribute in a query? My custom class consists of two strings, but a stringcriterion isn't working. Should I create a custom criterion-class? I can't find any examples on this.

#51415
Jun 07, 2011 17:52
Vote:
 

I've just done like this: http://mariusslette.wordpress.com/2010/06/25/extending-the-community-user-object-for-strongly-typed-attributes/

Works fine using attributes on IUser

#51509
Jun 10, 2011 15:27
Vote:
 

Creating properties for the attributes wasn't my problem, but using the attributes in a query is. I think it shouldn't be that difficult, but it doesn't seem to work.

#51553
Jun 14, 2011 16:44
This thread is locked and should be used for reference only. Please use the Legacy add-ons forum to open new discussions.