|
| Updating additional user profile information tip |
 |
Fri, 29 Sep 2006 19:10:20 +000 |
I am trying to attach the blog SectionID to the users attribute:
editableUser.SetExtendedAttribute("BlogSectionID", 17);
Following the debug I can see that my update is successful, but I can also see
that after its updated, the user is update one more time overwritting my
extendedattribute. The cs.config csmodules ref is placed at the bottom.
Solution from Ken Robertson
I had encountered this problem before, but had come up with a little
workaround.
The problem is that CS creates the user, then assigns some additional profile
data to the user and does an update. In the future, I'd like to get it fixed so
that creating the user, contains the full user object from the DB, and then the
update is done against that data, so that nothing is overwritten/lost.
As a work around though, take a look at this class: public class
NewUserExtendedDataModule : ICSModule
{
private Hashtable namesToUpdate = new Hashtable();
public void Init(CSApplication csa, XmlNode node)
{
csa.PostUserUpdate += new CSUserEventHandler(csa_PostUserUpdate);
csa.PreUserUpdate += new CSUserEventHandler(csa_PreUserUpdate);
}
private void csa_PostUserUpdate(User user, CSEventArgs e)
{
if(HttpContext.Current == null)
return;
if(e.State == ObjectState.Create)
if(!namesToUpdate.Contains(user.UserID))
namesToUpdate.Add(user.UserID, true);
}
private void csa_PreUserUpdate(User user, CSEventArgs e)
{
if(HttpContext.Current == null)
return;
if(e.State == ObjectState.Update)
{
if(namesToUpdate.Contains(user.UserID))
{
user.SetExtendedAttribute("SectionID",
"1000"); // Add your stuff here
namesToUpdate.Remove(user.UserID);
}
}
}
}
It basically listens to when AFTER a user is created, remembers their user ID,
and then does the work before the update event, knowing that the update will be
next.
|
| Post Reply
|
|
|
|
|
|
|
|
|
|