November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
I am not sure but i believe there are a way todo it as well. Have not time to investigate at the moment but I was in a project last autum where I think we did that. The base for that project was the MedStore templates from Circuit. You can dowload and check the code from http://relateintranet.codeplex.com/ it is a bit old but they might have that when importing users from AD or something like that.
Thanks, but I managed to solve it by reflecting and guessing :) It's actually very simple once you know it. But it had saved me some time if this was already mentioned in the docs. Hint Episerver...
Here are the magic lines (for future reference):
var attribute = new EPiServer.Common.Attributes.Attribute("SomeAttribute", typeof(User), typeof(string));
AttributeHandler.Instance.AddAttribute(attribute);
To be honest, I don't think creating attributes manually through admin is a serious approach, since it cannot be reproduced in all environments without manual work. Doing it programatically (through an init module) is the only way to do this right.
You may want to use CommunityAttributeBuilder (https://github.com/Geta/Community.EntityAttributeBuilder) that is similar to PageTypeBuilder for CMS. Currently it's supporting CMS6, I'll commit v7 as soon I will finish testing. By decorating your class properties with special attribute you will find those created in target site.
For instance:
[CommunityEntity(TargetType = typeof(IUser))]
public class UserAttributes : IClubUserAttributes
{
[CommunityEntityMetadata]
public virtual int AccessType { get; set; }
[CommunityEntityMetadata]
public virtual string Code { get; set; }
[CommunityEntityMetadata]
public virtual int EmployeeKey { get; set; }
[CommunityEntityMetadata]
public virtual bool IsAdmin { get; set; }
}
Library will scan all assemblies and look for types decorated with CommunityEntity attribute, if found one then properties will be scanned and those decorated with CommunityEntityMetadata attribute will be automatically created in DB. It also supports strongly-typed interface over IUser type:
var metadata = user.AsAttributeExtendable<UserAttributes>();
metadata.AccessType = info.AccessType;
metadata.Code = info.Code;
metadata.EmployeeKey = info.EmployeeKey;
metadata.IsAdmin = info.IsAdmin;
More info about library could be found - http://world.episerver.com/Blogs/Valdis-Iljuconoks/Dates/2012/6/Community-Attribute-Builder-final/
More info about internals (if interested) could be found here - http://www.tech-fellow.lv/2012/06/when-you-need-something-stronger/
Hi,
You can try it out - http://nuget.episerver.com/en/OtherPages/Package/?packageId=Geta.Community.EntityAttributeBuilder.CMS7
Any feedback is valuable :)
I'm sure there is a way to create Community attributes programatically but it's nowhere to be found - neither on the net nor the SDK. Someone who made this happen can you please share the wizdom. Thanks in advance!